Class: Periplus::Request

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

Constant Summary collapse

BING_MAPS_URL =
"http://dev.virtualearth.net/REST/v1/"
ROUTE_PATH =
"Routes"
LOCATION_PATH =
"Locations"
ROUTE_IMAGE_PATH =
"Imagery/Map/Road/Routes/Driving"
QUERY_IMAGE_PATH =
"Imagery/Map/Road/"

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ Request

Returns a new instance of Request.



6
7
8
# File 'lib/periplus/request.rb', line 6

def initialize(api_key)
  @api_key = api_key
end

Instance Method Details

#address_map_url(address, pushpins = [], options = {}) ⇒ Object

Generate a URL for a location map

  • address is a hash or object with properties or keys like street, address, city, state, province, etc.

  • pushpins is an optional list of hashes with :latitude, :longitude, :type (optional – 1, 2, 3, etc. per the bing spec) or :label (optional – no longer than 2 characters per bing spec)

  • options is a hash that gets turned directly into url params for bing



48
49
50
51
52
53
54
55
56
# File 'lib/periplus/request.rb', line 48

def address_map_url(address, pushpins = [], options = {})
  options = default_options(options)
  base = "#{BING_MAPS_URL}#{QUERY_IMAGE_PATH}#{URI.escape(format_waypoint(address))}?#{options.to_params}"
  if pushpins and pushpins.length > 0
    formatted_pins = pushpins.map {|p| "pp=#{format_pushpin(p)}" }.join '&'
    base = "#{base}&#{formatted_pins}" if pushpins
  end
  base
end

#location_details_url(address, options = {}) ⇒ Object



58
59
60
61
62
# File 'lib/periplus/request.rb', line 58

def location_details_url(address, options = {})
  options = default_options(options).merge(:o => "json")
                                    .merge(structure_address(address))
  "#{BING_MAPS_URL}#{LOCATION_PATH}?#{options.to_params}"
end

#route_details_url(waypoints, options = {}) ⇒ Object



16
17
18
19
20
21
# File 'lib/periplus/request.rb', line 16

def route_details_url(waypoints, options = {})
  options = default_options(options).merge(hashify_waypoints(waypoints))
                                    .merge(:o => "json")

  "#{BING_MAPS_URL}#{ROUTE_PATH}?#{options.to_params}"
end

#route_map_url(waypoints, pushpins = [], options = {}) ⇒ Object

Generate a URL for a routes map.

  • waypoints is a list of hashes or objects with properties or keys like street, address, city, state, province, etc.

  • pushpins is an optional list of hashes with :latitude, :longitude, :type (optional – 1, 2, 3, etc. per the bing spec) or :label (optional – no longer than 2 characters per bing spec)

  • options is a hash that gets turned directly into url params for bing



30
31
32
33
34
35
36
37
38
39
# File 'lib/periplus/request.rb', line 30

def route_map_url(waypoints, pushpins = [], options = {})
  options = options.merge(hashify_waypoints(waypoints))
                   .merge(:key => @api_key)
  base = "#{BING_MAPS_URL}#{ROUTE_IMAGE_PATH}?#{options.to_params}"
  if pushpins and pushpins.length > 0
    formatted_pins = pushpins.map {|p| "pp=#{format_pushpin(p)}" }.join '&'
    base = "#{base}&#{formatted_pins}" if pushpins
  end
  base
end