Archive

Archive for August, 2017

Car Registration #API now available on #Cocoapods #Swift

Screen Shot 2017-08-27 at 11.44.59

We’ve just packaged our Swift Module as a Cocoapod, and listed it on Cocoapods.org, you can access the GIT repo here https://github.com/infiniteloopltd/CarRegistrationPod

CarRegistrationPod

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

A wrapper for the Car Registration API in Swift. You will require a username and password from http://www.vehicleregistrationapi.com This API returns car details from a car number plate in many countries worldwide, including the UK, USA, Australia, India. A full list is shown below.

Installation

CarRegistrationPod is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "CarRegistrationPod"

Usage

import CarRegistrationPod
...
let dict = australia_lookup(registrationNumber: "YHC14Y", state: "NSW", username:"***your username***", password:"*** password ***")

label.text = dict["Description"] as? String

Other members of the car_registration package are

  • australia_lookup
  • usa_lookup
  • europe_lookup

Both australia and usa accept four parameters, registrationNumber, state, username and password, and returns a [String: Any] europe_lookup does not require the state parameter, but instead, requires a endpoint parameter, which can be one of the following strings;

  • Check (UK)
  • CheckBelgium
  • CheckCroatia
  • CheckCzechRepublic
  • CheckDenmark
  • CheckEstonia
  • CheckFinland
  • CheckFrance
  • CheckHungary
  • CheckIndia
  • CheckIreland
  • CheckItaly
  • CheckNetherlands
  • CheckNewZealand
  • CheckNigeria
  • CheckNorway
  • CheckPortugal
  • CheckRussia
  • CheckSlovakia
  • CheckSouthAfrica
  • CheckSpain
  • CheckSriLanka
  • CheckSweden
  • CheckUAE
  • CheckUSA
  • CheckAustralia

Author

Infinite loop Development ltd, http://www.infiniteloop.ie

License

CarRegistrationPod is available under the MIT license. See the LICENSE file for more info.

Categories: Uncategorized

Enable Remote access on #SQL server named instance

named-instance

You can install two instances of SQL server on the same machine, for example if you really needed to have two different versions of SQL server, or wanted to create a logically separated database where you could keep a near-identical copy of your main database.

Anyway, for whatever reason, if you do install two instances of SQL server on one server, you will quickly find that the default port number 1433 is occupied by the first SQL server, for local connections this doesn’t cause a problem, but for remote connections it does.

First, you have to pick a new port for the named instance. Open SQL server configuration manager, then select SQL Server Network Configuration, then SQLExpress (Or whatever you named your second instance), select TCP/IP, enable it, if it isn’t already. Then right click properties. Select the IP Addresses tab, and scroll to the IP (ALL) heading, remove the 0 from TCP Dynamic ports, and enter a number such as 1444 into the TCP port box. Open up services, and restart the service associated with the SQLExpress instance.

You may now need to open up TCP port 1444 on your firewall, and adjust your connection strings to <IP Address>\<Instance Name>,1444

 

 

Categories: Uncategorized

New #Swift3 Package published on #swiftModules @corydmc

swift

To help Swift developers integrate our API easily into their app, with just two lines of code, we’ve just published a wrapper for our Car Registration API on SwiftModules here

https://swiftmodules.com/infiniteloopltd/swiftcarregistrationapi

SwiftCarRegistrationAPI

A wrapper for the Car Registration API in Swift. You will require a username and password from http://www.vehicleregistrationapi.com This API returns car details from a car number plate in many countries worldwide, including the UK, USA, Australia, India. A full list is shown below.

Usage

Package.swift

import PackageDescription

let package = Package(
    name: "MyApp",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/infiniteloopltd/SwiftCarRegistrationAPI.git",
                  "1.0.1")
    ]
)

main.swift

import car_registration

let dict = australia_lookup(registrationNumber: "YHC14Y", state: "NSW", username:"***your username***", password:"*** password ***")

print(dict["Description"] ?? "error");

Other members of the car_registration package are

  • australia_lookup
  • usa_lookup
  • europe_lookup

Both australia and usa accept four parameters, registrationNumber, state, username and password, and returns a [String: Any] europe_lookup does not require the state parameter, but instead, requires a endpoint parameter, which can be one of the following strings;

  • Check (UK)
  • CheckBelgium
  • CheckCroatia
  • CheckCzechRepublic
  • CheckDenmark
  • CheckEstonia
  • CheckFinland
  • CheckFrance
  • CheckHungary
  • CheckIndia
  • CheckIreland
  • CheckItaly
  • CheckNetherlands
  • CheckNewZealand
  • CheckNigeria
  • CheckNorway
  • CheckPortugal
  • CheckRussia
  • CheckSlovakia
  • CheckSouthAfrica
  • CheckSpain
  • CheckSriLanka
  • CheckSweden
  • CheckUAE
  • CheckUSA
  • CheckAustralia

 

Categories: Uncategorized

Using basic #HTTP authentication with a #REST #API in Perl

perl-camel-source-code-1024-postbit-98365.jpg

Another language in the series, is Perl, where I’ve written some code to call the CarRegistrationAPI.com API – which is a JSON based REST API. Using Perl.

So, here is the perl module

package InfiniteLoop::CarRegistration;

use LWP::UserAgent;
use MIME::Base64;
use JSON;

use Exporter qw(import);

our @EXPORT_OK = qw(usa_lookup australia_lookup europe_lookup);

sub usa_lookup
{
my (%params) = @_;
my $server_endpoint = “https://www.regcheck.org.uk/api/json.aspx/CheckUSA/&#8221; . %params{‘registration_number’} . “/” . %params{‘state’};
%arguments = ( ‘url’ => $server_endpoint,
‘username’ => “” . %params{‘username’},
‘password’ => “” . %params{‘password’});
lookup(%arguments);
}

sub australia_lookup
{
my (%params) = @_;
my $server_endpoint = “https://www.regcheck.org.uk/api/json.aspx/CheckAustralia/&#8221; . %params{‘registration_number’} . “/” . %params{‘state’};
%arguments = ( ‘url’ => $server_endpoint,
‘username’ => “” . %params{‘username’},
‘password’ => “” . %params{‘password’});
lookup(%arguments);
}

sub europe_lookup
{
my (%params) = @_;
my $server_endpoint = “https://www.regcheck.org.uk/api/json.aspx/&#8221; . %params{‘endpoint’} . “/” . %params{‘registration_number’};
%arguments = ( ‘url’ => $server_endpoint,
‘username’ => “” . %params{‘username’},
‘password’ => “” . %params{‘password’});
lookup(%arguments);
}

sub lookup
{
my (%params) = @_;
my $ua = LWP::UserAgent->new;
my $encoded = encode_base64(%params{‘username’} . ‘:’ . %params{‘password’});
my $req = HTTP::Request->new(GET => “” . %params{‘url’});
$req->header(‘Authorization’ => ‘Basic ‘ . $encoded);
my $resp = $ua->request($req);
if ($resp->is_success) {
my $message = $resp->decoded_content;
my $json = JSON->new;
my $data = $json->decode($message);
return $data;
}
else {
print “HTTP GET error code: “, $resp->code, “\n”;
print “HTTP GET error message: “, $resp->message, “\n”;
}
}

Copy that perl module to perl/vendor

And here is a perl script to call it:

 

use InfiniteLoop::CarRegistration qw(usa_lookup australia_lookup europe_lookup);

### code examples

%params = ( ‘endpoint’ => ‘Check’,
‘registration_number’ => ‘Po14ryh’,
‘username’ => ‘** your username **’,
‘password’ => ‘** your password **’);

$data = europe_lookup(%params);
print $data->{Description} . “\n”;

%params2 = ( ‘registration_number’ => ‘hij934’,
‘state’ => ‘pr’,
‘username’ => ‘** your username **’,
‘password’ => ‘** your password **’);

$data2 = usa_lookup(%params2);
print $data2->{Description} . “\n”;

%params3 = ( ‘registration_number’ => ‘490JLN’,
‘state’ => ‘QLD’,
‘username’ => ‘** your username **’,
‘password’ => ‘** your password **’);

$data3 = australia_lookup(%params3);
print $data3->{Description}. “\n”;

You’ll obviously need your own username and password to call this 🙂

This code will hopefully shortly be up on Github and CPan.
 

Categories: Uncategorized

Car Registration API available as a #Go #Package

6884317034_b20d1d86e5_z

Following on from my earlier post on making an authenticated HTTP request in GO, I’ve packaged up the code, and published it to github for Go developers to easily import a wrapper for the http://www.vehicleregistrationapi.com API into their GO code.

The Repo lives at https://github.com/infiniteloopltd/GoCarRegistrationAPI

Here’s the documentation if you want to use the code –

 

GoCarRegistrationAPI

A wrapper for the Car Registration API in Go. To use this package you will need a username and password from http://www.vehicleregistrationapi.com

Usage

package main
import "github.com/infiniteloopltd/GoCarRegistrationAPI"
import "fmt"

func main() {  
    data := car_registration.Australia_lookup("YHC14Y","NSW","***Your Username***","***Your Password***")
    m := data.(map[string]interface{})
    //fmt.Printf("%+v", m)
    fmt.Println(m["Description"])
}

The methods of car_registration are Australia_lookup, USA_lookup and European_lookup, all methods reuturn an interface{}, which can be cast to a string map as shown above.

Australia_lookup

Australia lookup accepts four parameters, the registration number, the state, and your username and password, in that order.

USA_lookup

USA lookup accepts four parameters, the registration number, the state, and your username and password, in that order.

European_lookup

European lookup accepts four parameters, the endpoint, the registration number, and your username and password, in that order, where the endpoint can be one of:

  • Check (UK)
  • CheckBelgium
  • CheckCroatia
  • CheckCzechRepublic
  • CheckDenmark
  • CheckEstonia
  • CheckFinland
  • CheckFrance
  • CheckHungary
  • CheckIndia
  • CheckIreland
  • CheckItaly
  • CheckNetherlands
  • CheckNewZealand
  • CheckNigeria
  • CheckNorway
  • CheckPortugal
  • CheckRussia
  • CheckSlovakia
  • CheckSouthAfrica
  • CheckSpain
  • CheckSriLanka
  • CheckSweden
  • CheckUAE
Categories: Uncategorized

Make a #Synchronous #HTTP request in #Swift3

swift

Often you may want to chain HTTP requests in Swift, So, you may want to request something, then wait until that’s finished before doing something else. – for example, you may not want your terminal script to exit before the last HTTP call is made. So cobbling together a few code examples, this is what I came up with

import Foundation

extension URLSession {
func synchronousDataTask(urlrequest: URLRequest) -> (Data?, URLResponse?, Error?) {
var data: Data?
var response: URLResponse?
var error: Error?

let semaphore = DispatchSemaphore(value: 0)

let dataTask = self.dataTask(with: urlrequest) {
data = $0
response = $1
error = $2

semaphore.signal()
}
dataTask.resume()

_ = semaphore.wait(timeout: .distantFuture)

return (data, response, error)
}
}

var request = URLRequest(url: URL(string: “http://icanhazip.com&#8221;)!)

request.httpMethod = “GET”
let (data, response, error) = URLSession.shared.synchronousDataTask(urlrequest: request)
if let error = error {
print(“Synchronous task ended with error: \(error)”)
}
else {
print(NSString(data: data!, encoding: String.Encoding.utf8.rawValue) ?? “Error”)
}

Categories: Uncategorized

Make an authenticated #HTTP Get request and parse #JSON in #Golang

1-br-Z8sy61DQ6l5FmG129OQ

Go is a programming language developed by Google, and with a name like that behind it, it’s worth learning a little about it, so, here’s a quick code example that make a HTTP get request, with basic authentication, and parses the response as a Json object.

package main

import “net/http”
import “fmt”
import “io/ioutil”
import “encoding/base64”
import “encoding/json”

func basicAuth(username, password string) string {
auth := username + “:” + password
return base64.StdEncoding.EncodeToString([]byte(auth))
}

func australia_lookup(registration_number, state, username, password string) interface{} {

url := string(“https://www.regcheck.org.uk/api/json.aspx/CheckAustralia/&#8221; + registration_number + “/” + state)
return generic_lookup(url, username, password)
}

func usa_lookup(registration_number, state, username, password string) interface{} {

url := string(“https://www.regcheck.org.uk/api/json.aspx/CheckUSA/&#8221; + registration_number + “/” + state)
return generic_lookup(url, username, password)
}

func european_lookup(endpoint, registration_number, username, password string) interface{} {

url := string(“https://www.regcheck.org.uk/api/json.aspx/&#8221; + endpoint + “/” + registration_number)
return generic_lookup(url, username, password)
}

func generic_lookup(url, username, password string) interface{} {

var client http.Client

req, err := http.NewRequest(“GET”, url, nil)
req.Header.Add(“Authorization”,”Basic “+basicAuth(username,password))

if err != nil {}
resp, err3 := client.Do(req)

if err3 != nil {}

defer resp.Body.Close()

if resp.StatusCode == 200 { // OK
bodyBytes, err2 := ioutil.ReadAll(resp.Body)
bodyString := string(bodyBytes)
var data interface{}
json.Unmarshal([]byte(bodyString), &data)
return data
if err2 != nil {}
}
return nil

}

func main() {

data := european_lookup(“Check”,”SL14MKM”,”***your username***”,”***your password***”)

m := data.(map[string]interface{})
//fmt.Printf(“%+v”, m)
fmt.Println(m[“Description”])
}

The example uses the RegCheck webservice, so you’ll need a username and password to check this out.

Categories: Uncategorized

Car Registration API now available as a Crate for #Rust developers


If you program in Rust, then you know just how useful crates are, and how they are an integral part of the language itself.

So to help Rust developers use our API, we’ve wrapped ours up in a Rust Crate that makes it super easy to call our API from your Rust code.

You can find the code documentation here: https://blog.dotnetframework.org/car-registration-api-crate-documentation/

And the link to the crate itself here:

https://crates.io/crates/car_registration

For those interested in seeing how it works under the hood, the GIT repo is public, and you can see that here: https://github.com/infiniteloopltd/RustCrateCarRegistration

 

Categories: Uncategorized

Make a get #HTTP Request in #Rust using #Curl

rust

There are plenty of examples of making a HTTP request using Rust online, but so many of them gloss over very important details, like how to import the library you need to make the request, and for a beginner, it’s not really helpful to give a snippet of code without the surrounding instructions. Plus, it appears that perhaps there are different versions of code that just aren’t backwards compatible. This example works on

rustc 1.19.0 (0ade33941 2017-07-17)

If you have a different version, then, I can’t guarantee this works, but try it anyway.

First off, you need to install Cargo, I am using cargo version

cargo 0.20.0 (a60d185c8 2017-07-13)

Create a new cargo project called http by typing

cargo new http — bin

Then edit the cargo.toml file, and add the CURL dependency here;

[dependencies]
curl = “0.2.11”

now, edit the main.rs file, and add this code;

extern crate curl;

use curl::http;

// Thanks to https://github.com/hjr3/rust-get-data-from-url
pub fn main() {

let url = “http://icanhazip.com/&#8221;;
let resp = http::handle()
.get(url)
.exec()
.unwrap_or_else(|e| {
panic!(“Failed to get {}; error is {}”, url, e);
});

if resp.get_code() != 200 {
println!(“Unable to handle HTTP response code {}”, resp.get_code());
return;
}

let body = std::str::from_utf8(resp.get_body()).unwrap_or_else(|e| {
panic!(“Failed to parse response from {}; error is {}”, url, e);
});

println!(“{}”,body);
}

What this does, is it makes a CURL get HTTP request to http://icanhazip.com/ , which simply returns the IP address of the client (you), and prints it to screen.

To run it, type cargo build, then

./target/debug/http

:::Update:::

Ok, being a bit of a noob here, I have noticed, that this example is quite dated, using CURL version 0.2.11, when the latest is 0.4.8 ; but you have to change the code completely to use version 0.4.8

First, update the cargo.toml to

[dependencies]
curl = “0.4.8”

Then the main.rs to

extern crate curl;

use curl::easy::{Easy, List};

// Capture output into a local `Vec`.
fn main() {
let mut easy = Easy::new();
easy.url(“http://icanhazip.com&#8221;).unwrap();

let mut html: String = String::new();
{
let mut transfer = easy.transfer();
transfer.write_function(|data| {
html = String::from_utf8(Vec::from(data)).unwrap();
Ok(data.len())
}).unwrap();

transfer.perform().unwrap();
};
println!(“{}”,html);
}

Categories: Uncategorized

Car Registration #API now has a home on #Packagist for #PHP #devs

 

 

 

 

 

 

 

 

 

Packagist is a public repository for composer packages for PHP, and it makes it super easy to load third party PHP code into your application. So, not to be left out of the game, we’ve submitted our package to Packagist. at the url below

https://packagist.org/packages/infiniteloop/carregistration

You install the package via

composer require infiniteloop/carregistration

Usage

require_once 'vendor/autoload.php';

use carregistration\carregistration;

$conv = new carregistration;

$json = $conv->lookup('***your username***','CheckUSA','H84jae','nj');
print_r($json->Description);    

Parameters

The function “lookup” returns an associative array that differs by country, but maintains consistency where possible. It accepts four parameters, being username, endpoint, registration number and state, in that order.

The username is that which is used on www.vehicleregistrationapi.com

The endpoint specifies the country to be searched, and must be one of the following.

  • Check (UK)
  • CheckBelgium
  • CheckCroatia
  • CheckCzechRepublic
  • CheckDenmark
  • CheckEstonia
  • CheckFinland
  • CheckFrance
  • CheckHungary
  • CheckIndia
  • CheckIreland
  • CheckItaly
  • CheckNetherlands
  • CheckNewZealand
  • CheckNigeria
  • CheckNorway
  • CheckPortugal
  • CheckRussia
  • CheckSlovakia
  • CheckSouthAfrica
  • CheckSpain
  • CheckSriLanka
  • CheckSweden
  • CheckUAE
  • CheckUSA
  • CheckAustralia

The state parameter is only used for USA and Australia, and can be left empty for all other countries.

Categories: Uncategorized