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
46
47
48
49
50
51
52
|
# File 'lib/gds_api/imminence.rb', line 46
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
|
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/gds_api/imminence.rb', line 32
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
14
15
16
17
18
19
|
# File 'lib/gds_api/imminence.rb', line 14
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, lat, lon, limit = 5) ⇒ Object
5
6
7
|
# File 'lib/gds_api/imminence.rb', line 5
def api_url(type, lat, lon, limit=5)
"#{@endpoint}/places/#{type}.json?limit=#{limit}&lat=#{lat}&lng=#{lon}"
end
|
#business_support_schemes(facets_hash) ⇒ Object
25
26
27
28
29
|
# File 'lib/gds_api/imminence.rb', line 25
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
9
10
11
12
|
# File 'lib/gds_api/imminence.rb', line 9
def places(type, lat, lon, limit=5)
places = get_json(api_url(type, lat, lon, limit)) || []
places.map { |p| self.class.parse_place_hash(p) }
end
|
#places_kml(type) ⇒ Object
21
22
23
|
# File 'lib/gds_api/imminence.rb', line 21
def places_kml(type)
get_raw("#{@endpoint}/places/#{type}.kml").body
end
|