Class: Bing::Location

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

Overview

Responsible for obtaining a location based off of data passed in.

Constant Summary

Constants inherited from RestResource

RestResource::BASE_PATH

Instance Attribute Summary collapse

Attributes inherited from RestResource

#bounding_box

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RestResource

#bbox, map_find, map_uri

Constructor Details

#initialize(resource) ⇒ Location

Returns a new instance of Location.



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bing/location.rb', line 38

def initialize resource
  raise Bing::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.



27
28
29
# File 'lib/bing/location.rb', line 27

def address
  @address
end

#canonical_descriptionObject (readonly)

Returns the value of attribute canonical_description.



28
29
30
# File 'lib/bing/location.rb', line 28

def canonical_description
  @canonical_description
end

#cityObject (readonly)

Returns the value of attribute city.



30
31
32
# File 'lib/bing/location.rb', line 30

def city
  @city
end

#confidenceObject (readonly)

Returns the value of attribute confidence.



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

def confidence
  @confidence
end

#coordinatesObject (readonly)

Returns the value of attribute coordinates.



29
30
31
# File 'lib/bing/location.rb', line 29

def coordinates
  @coordinates
end

#countryObject (readonly)

Returns the value of attribute country.



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

def country
  @country
end

#entity_typeObject (readonly)

Returns the value of attribute entity_type.



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

def entity_type
  @entity_type
end

#full_nameObject (readonly)

Returns the value of attribute full_name.



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

def full_name
  @full_name
end

#stateObject (readonly)

Returns the value of attribute state.



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

def state
  @state
end

#zipObject (readonly)

Returns the value of attribute zip.



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

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. Will support any param that bing supports.

Example

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



16
17
18
# File 'lib/bing/location.rb', line 16

def self.find opts
  map_find opts.to_lower_camelized_param
end

.pathObject

Path to route resource.



23
24
25
# File 'lib/bing/location.rb', line 23

def self.path
  super '/Locations'
end