Class: GdsApi::Imminence
- Inherits:
-
Base
- Object
- Base
- GdsApi::Imminence
show all
- Defined in:
- lib/gds_api/imminence.rb
Instance Attribute Summary
Attributes inherited from Base
#options
Class Method Summary
collapse
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
Class Method Details
65
66
67
68
69
70
71
|
# File 'lib/gds_api/imminence.rb', line 65
def self.(place_hash)
address_fields = [
place_hash["address1"],
place_hash["address2"]
].reject { |a| a.nil? or a == "" }
{"address" => address_fields.map(&:strip).join(", ")}
end
|
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/gds_api/imminence.rb', line 51
def self.(location)
case location
when Array
{"latitude" => location[0], "longitude" => location[1]}
when Hash
location
when nil
{"latitude" => nil, "longitude" => nil}
end
end
|
.parse_place_hash(place_hash) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/gds_api/imminence.rb', line 23
def self.parse_place_hash(place_hash)
location = self.(place_hash["location"])
address = self.(place_hash)
place_hash.merge(location).merge(address)
end
|
Instance Method Details
#api_url(type, params) ⇒ Object
5
6
7
8
9
|
# File 'lib/gds_api/imminence.rb', line 5
def api_url(type, params)
vals = [:limit, :lat, :lng, :postcode].select{ |p| params.include? p }
querystring = URI.encode_www_form vals.map { |p| [p, params[p]] }
"#{@endpoint}/places/#{type}.json?#{querystring}"
end
|
#areas_for_postcode(postcode) ⇒ Object
40
41
42
43
|
# File 'lib/gds_api/imminence.rb', line 40
def areas_for_postcode(postcode)
url = "#{@endpoint}/areas/#{URI.encode(postcode)}.json"
get_json(url)
end
|
#areas_for_type(type) ⇒ Object
45
46
47
48
|
# File 'lib/gds_api/imminence.rb', line 45
def areas_for_type(type)
url = "#{@endpoint}/areas/#{type}.json"
get_json(url)
end
|
#business_support_schemes(facets_hash) ⇒ Object
34
35
36
37
38
|
# File 'lib/gds_api/imminence.rb', line 34
def business_support_schemes(facets_hash)
query = facets_hash.keys.sort.map { |k| "#{k.to_s}=#{facets_hash[k]}" }.join("&")
query = "?#{query}" unless query.empty?
get_json!("#{@endpoint}/business_support_schemes.json#{query}")
end
|
#places(type, lat, lon, limit = 5) ⇒ Object
11
12
13
14
15
|
# File 'lib/gds_api/imminence.rb', line 11
def places(type, lat, lon, limit=5)
url = api_url(type, lat: lat, lng: lon, limit: limit)
places = get_json(url) || []
places.map { |p| self.class.parse_place_hash(p) }
end
|
#places_for_postcode(type, postcode, limit = 5) ⇒ Object
17
18
19
20
21
|
# File 'lib/gds_api/imminence.rb', line 17
def places_for_postcode(type, postcode, limit=5)
url = api_url(type, postcode: postcode, limit: limit)
places = get_json(url) || []
places.map { |p| self.class.parse_place_hash(p) }
end
|
#places_kml(type) ⇒ Object
30
31
32
|
# File 'lib/gds_api/imminence.rb', line 30
def places_kml(type)
get_raw("#{@endpoint}/places/#{type}.kml").body
end
|