Class: Bing::RestResource

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

Direct Known Subclasses

Imagery, Location, Route

Constant Summary collapse

BASE_PATH =

Base Bing Rest route.

"/REST/#{Bing.config[:api_version]}"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bounding_boxObject (readonly)

The map’s bounding box.



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

def bounding_box
  @bounding_box
end

Class Method Details

.map_find(params) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/bing/rest_resource.rb', line 16

def self.map_find params
  resp = Bing::Request.get map_uri params
  body = JSON.parse resp.body

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

.map_uri(params) ⇒ Object



10
11
12
13
14
# File 'lib/bing/rest_resource.rb', line 10

def self.map_uri params
  Bing.config[:map_uri].merge(
    "#{path}?key=#{Bing.config[:api_key]}&#{params}"
  )
end

.path(subclass_path = nil) ⇒ Object



25
26
27
# File 'lib/bing/rest_resource.rb', line 25

def self.path subclass_path = nil
  "#{BASE_PATH}#{subclass_path}"
end

Instance Method Details

#bbox(box) ⇒ Object

Decipher bounding box from bbox in Bing response.



37
38
39
40
41
42
43
44
45
# File 'lib/bing/rest_resource.rb', line 37

def bbox box
  south, west, north, east = *box
  {
    :north => north,
    :east  => east,
    :south => south,
    :west  => west,
  }
end