Class: Bing::Location

Inherits:
Object show all
Defined in:
lib/bing/location.rb

Overview

Responsible for obtaining a location based off of data passed in. Most common method is to do:

Bing::Location.find :query => ‘123 Address City State’

Constant Summary collapse

PATH =

Path to location resource.

'/REST/v1/Locations'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Location

Returns a new instance of Location.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bing/location.rb', line 44

def initialize resource
  raise LocationResourceMissing if resource.blank?

  @confidence  = resource['confidence']
  @entity_type = resource['entityType']
  @full_name   = resource['name']

  if resource['address'] then
    @address = resource['address']['addressLine']
    @city    = resource['address']['locality']
    @country = resource['address']['countryRegion']
    @state   = resource['address']['adminDistrict']
    @zip     = resource['address']['postalCode']
  end

  if resource['bbox'] then
    @bounding_box = bbox resource['bbox']
  end

  if resource['point'] && resource['point']['coordinates'] then
    @coordinates = resource['point']['coordinates']
  end
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



32
33
34
# File 'lib/bing/location.rb', line 32

def address
  @address
end

#bounding_boxObject (readonly)

Returns the value of attribute bounding_box.



33
34
35
# File 'lib/bing/location.rb', line 33

def bounding_box
  @bounding_box
end

#canonical_descriptionObject (readonly)

Returns the value of attribute canonical_description.



34
35
36
# File 'lib/bing/location.rb', line 34

def canonical_description
  @canonical_description
end

#cityObject (readonly)

Returns the value of attribute city.



36
37
38
# File 'lib/bing/location.rb', line 36

def city
  @city
end

#confidenceObject (readonly)

Returns the value of attribute confidence.



37
38
39
# File 'lib/bing/location.rb', line 37

def confidence
  @confidence
end

#coordinatesObject (readonly)

Returns the value of attribute coordinates.



35
36
37
# File 'lib/bing/location.rb', line 35

def coordinates
  @coordinates
end

#countryObject (readonly)

Returns the value of attribute country.



38
39
40
# File 'lib/bing/location.rb', line 38

def country
  @country
end

#entity_typeObject (readonly)

Returns the value of attribute entity_type.



39
40
41
# File 'lib/bing/location.rb', line 39

def entity_type
  @entity_type
end

#full_nameObject (readonly)

Returns the value of attribute full_name.



40
41
42
# File 'lib/bing/location.rb', line 40

def full_name
  @full_name
end

#stateObject (readonly)

Returns the value of attribute state.



41
42
43
# File 'lib/bing/location.rb', line 41

def state
  @state
end

#zipObject (readonly)

Returns the value of attribute zip.



42
43
44
# File 'lib/bing/location.rb', line 42

def zip
  @zip
end

Class Method Details

.find(opts) ⇒ Object

Will find locations based off of query and return an array of Bing::Location objects.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bing/location.rb', line 20

def self.find opts
  uri = Bing.config[:map_uri].merge(
          "#{PATH}?key=#{Bing.config[:api_key]}&#{opts.to_param}"
        )

  body = JSON.parse get(uri).body

  body['resourceSets'].first['resources'].map do |resource|
    new resource
  end.compact
end