Class: GdsApi::Mapit

Inherits:
Base
  • Object
show all
Includes:
ExceptionHandling
Defined in:
lib/gds_api/mapit.rb

Defined Under Namespace

Classes: Location

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods included from ExceptionHandling

#ignoring

Methods inherited from Base

#client, #create_client, #get_list!, #initialize, #url_for_slug

Constructor Details

This class inherits a constructor from GdsApi::Base

Instance Method Details

#location_for_postcode(postcode) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/gds_api/mapit.rb', line 7

def location_for_postcode(postcode)
  response = get_json("#{base_url}/postcode/#{CGI.escape postcode}.json")
  return Location.new(response) unless response.nil?
rescue GdsApi::HTTPErrorResponse => e
  # allow 400 errors, as they can be invalid postcodes people have entered
  raise GdsApi::HTTPErrorResponse.new(e.code) unless e.code == 400
end