Class: GdsApi::Mapit

Inherits:
Base
  • Object
show all
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 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

#areas_for_type(type) ⇒ Object



14
15
16
# File 'lib/gds_api/mapit.rb', line 14

def areas_for_type(type)
  get_json("#{base_url}/areas/#{type}.json")
end

#location_for_postcode(postcode) ⇒ Object



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

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