Last active
March 13, 2019 12:22
-
-
Save stephenkeable-allies/5b573c561ac9d6d7dfc6 to your computer and use it in GitHub Desktop.
Example code for using Postcoder Web in Ruby. For more information on Postcoder Web visit http://www.alliescomputing.com/products/postcoder-web-api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PostCoder Web Service V3 example | |
# Allies Computing Ltd 2014 | |
# | |
# This demo shows how to perform an address lookup in ruby. | |
# | |
# Note: This script has been developed for ruby >= 1.9.3 | |
# | |
require 'cgi' | |
require 'json' | |
require 'net/http' | |
searchkey = 'PCW45-12345-12345-1234X'; # Test search key, repalce with yours | |
searchterm = 'NR14 7PZ'; # string to use for an address search | |
puts "PostCoder Web V3 Ruby Client Snippet\n\n" | |
URL = 'ws.postcoder.com' | |
QUERY = '/pcw/' + searchkey + '/address/UK/' + CGI::escape(searchterm).gsub("+", "%20") | |
# for other uri options see https://developers.alliescomputing.com/postcoder-web-api/address-lookup/premise | |
http = Net::HTTP.new(URL) | |
request = Net::HTTP::Get.new(QUERY) | |
response = http.request(request) | |
puts JSON.pretty_generate(JSON.parse(response.body)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment