Skip to content

Instantly share code, notes, and snippets.

@Taelkir
Created March 13, 2019 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Taelkir/3d3fe794c103f9ad0fec3269494150db to your computer and use it in GitHub Desktop.
Save Taelkir/3d3fe794c103f9ad0fec3269494150db to your computer and use it in GitHub Desktop.
Example code for using Postcoder in Ruby. For more information on Postcoder visit https://postcoder.com
# Postcoder Ruby example
# Allies Computing Ltd
#
# 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 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/
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