Class: Periplus::BingResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/periplus/bing_response.rb

Direct Known Subclasses

Location, Route

Instance Method Summary collapse

Constructor Details

#initialize(httparty_response) ⇒ BingResponse

Returns a new instance of BingResponse.



5
6
7
8
9
10
11
# File 'lib/periplus/bing_response.rb', line 5

def initialize(httparty_response)
  @response = httparty_response

  raise error if @response.response.kind_of? Net::HTTPClientError

  parse
end

Instance Method Details

#errorObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/periplus/bing_response.rb', line 23

def error
  http_code = @response.response.code
  http_message = @response.response.message
  message = "An error has occurred communicating with the Bing Maps service. HTTP Status: #{http_code} (#{http_message})"
  if Periplus.verbose
    message << "\n  URL: #{@response.request.path}"
    message << "\n  Response:"
    message << "\n  #{PP.pp(@response.response.body, "")}"
  end
  message
end

#parseObject



13
14
15
16
17
18
19
20
21
# File 'lib/periplus/bing_response.rb', line 13

def parse
  resource_sets = @response.parsed_response["resourceSets"]
  raise "Not found." if resource_sets == nil or resource_sets.length == 0

  resources = resource_sets.first["resources"]
  raise "Not found." if resources == nil or resources.length == 0

  @primary_resource = resources.first
end