periplus 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +14 -8
- data/VERSION +1 -1
- data/lib/periplus.rb +14 -4
- data/lib/periplus/bing_response.rb +15 -5
- data/lib/periplus/request.rb +48 -9
- data/periplus.gemspec +7 -7
- data/spec/bing_response_spec.rb +60 -0
- data/spec/request_spec.rb +91 -5
- metadata +17 -19
- data/spec/bing_response.spec +0 -36
data/README.rdoc
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
= periplus
|
2
2
|
|
3
|
-
Bing Maps REST API client.
|
3
|
+
Simple Bing Maps REST API client.
|
4
|
+
|
5
|
+
Currently supports:
|
6
|
+
|
7
|
+
* Routing
|
8
|
+
* Geocoding
|
9
|
+
* Mapping
|
4
10
|
|
5
11
|
== Use it
|
6
12
|
require 'periplus'
|
7
13
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
14
|
+
response = Periplus.route_details 'my_bing_key',
|
15
|
+
[{:street => "1600 Pennsylvania Ave.",
|
16
|
+
:city => "Washington",
|
17
|
+
:state => "DC",
|
18
|
+
:postal_code => "20500"},
|
19
|
+
{:postal_code => "90210"}],
|
20
|
+
:distanceUnit => :mi
|
15
21
|
|
16
22
|
puts "#{response.distance} #{response.distance_units.to_s}.pluralize, #{response.duration} seconds"
|
17
23
|
# "2665.06415 miles, 137797 seconds"
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/periplus.rb
CHANGED
@@ -8,6 +8,16 @@ module Periplus
|
|
8
8
|
include HTTParty
|
9
9
|
format :json
|
10
10
|
|
11
|
+
@verbose = false
|
12
|
+
|
13
|
+
def self.verbose=(value)
|
14
|
+
@verbose = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.verbose
|
18
|
+
@verbose
|
19
|
+
end
|
20
|
+
|
11
21
|
def self.route_details(key, waypoints, options = {})
|
12
22
|
request = Request.new key
|
13
23
|
url = request.route_details_url waypoints, options
|
@@ -20,13 +30,13 @@ module Periplus
|
|
20
30
|
Location.new (get url)
|
21
31
|
end
|
22
32
|
|
23
|
-
def self.route_map_url(key, waypoints, options = {})
|
33
|
+
def self.route_map_url(key, waypoints, pushpins = [], options = {})
|
24
34
|
request = Request.new key
|
25
|
-
request.route_map_url waypoints, options
|
35
|
+
request.route_map_url waypoints, pushpins, options
|
26
36
|
end
|
27
37
|
|
28
|
-
def self.address_map_url(key, address, options = {})
|
38
|
+
def self.address_map_url(key, address, pushpins = [], options = {})
|
29
39
|
request = Request.new key
|
30
|
-
request.address_map_url address, options
|
40
|
+
request.address_map_url address, pushpins, options
|
31
41
|
end
|
32
42
|
end
|
@@ -1,13 +1,11 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
1
3
|
module Periplus
|
2
4
|
class BingResponse
|
3
5
|
def initialize(httparty_response)
|
4
6
|
@response = httparty_response
|
5
7
|
|
6
|
-
if @response.response.kind_of? Net::HTTPClientError
|
7
|
-
http_code = @response.response.code
|
8
|
-
http_message = @response.response.message
|
9
|
-
raise "An error has occurred communicating with the Bing Maps service. HTTP Status: #{http_code} (#{http_message})"
|
10
|
-
end
|
8
|
+
raise error if @response.response.kind_of? Net::HTTPClientError
|
11
9
|
|
12
10
|
parse
|
13
11
|
end
|
@@ -21,5 +19,17 @@ module Periplus
|
|
21
19
|
|
22
20
|
@primary_resource = resources.first
|
23
21
|
end
|
22
|
+
|
23
|
+
def error
|
24
|
+
http_code = @response.response.code
|
25
|
+
http_message = @response.response.message
|
26
|
+
message = "An error has occurred communicating with the Bing Maps service. HTTP Status: #{http_code} (#{http_message})"
|
27
|
+
if Periplus.verbose
|
28
|
+
message << "\n URL: #{@response.request.path}"
|
29
|
+
message << "\n Response:"
|
30
|
+
message << "\n #{PP.pp(@response.response.body, "")}"
|
31
|
+
end
|
32
|
+
message
|
33
|
+
end
|
24
34
|
end
|
25
35
|
end
|
data/lib/periplus/request.rb
CHANGED
@@ -7,7 +7,7 @@ module Periplus
|
|
7
7
|
@api_key = api_key
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
BING_MAPS_URL = "http://dev.virtualearth.net/REST/v1/"
|
11
11
|
ROUTE_PATH = "Routes"
|
12
12
|
LOCATION_PATH = "Locations"
|
13
13
|
ROUTE_IMAGE_PATH = "Imagery/Map/Road/Routes/Driving"
|
@@ -17,24 +17,48 @@ module Periplus
|
|
17
17
|
options = default_options(options).merge(hashify_waypoints(waypoints))
|
18
18
|
.merge(:o => "json")
|
19
19
|
|
20
|
-
"#{
|
20
|
+
"#{BING_MAPS_URL}#{ROUTE_PATH}?#{options.to_params}"
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
# Generate a URL for a routes map.
|
24
|
+
#
|
25
|
+
# * waypoints is a list of hashes or objects with properties or keys like
|
26
|
+
# street, address, city, state, province, etc.
|
27
|
+
# * pushpins is an optional list of hashes with :latitude, :longitude,
|
28
|
+
# :type (optional -- 1, 2, 3, etc. per the bing spec) or :label (optional -- no longer than 2 characters per bing spec)
|
29
|
+
# * options is a hash that gets turned directly into url params for bing
|
30
|
+
def route_map_url(waypoints, pushpins = [], options = {})
|
24
31
|
options = options.merge(hashify_waypoints(waypoints))
|
25
32
|
.merge(:key => @api_key)
|
26
|
-
"#{
|
33
|
+
base = "#{BING_MAPS_URL}#{ROUTE_IMAGE_PATH}?#{options.to_params}"
|
34
|
+
if pushpins and pushpins.length > 0
|
35
|
+
formatted_pins = pushpins.map {|p| "pp=#{format_pushpin(p)}" }.join '&'
|
36
|
+
base = "#{base}&#{formatted_pins}" if pushpins
|
37
|
+
end
|
38
|
+
base
|
27
39
|
end
|
28
40
|
|
29
|
-
|
41
|
+
# Generate a URL for a location map
|
42
|
+
#
|
43
|
+
# * address is a hash or object with properties or keys like
|
44
|
+
# street, address, city, state, province, etc.
|
45
|
+
# * pushpins is an optional list of hashes with :latitude, :longitude,
|
46
|
+
# :type (optional -- 1, 2, 3, etc. per the bing spec) or :label (optional -- no longer than 2 characters per bing spec)
|
47
|
+
# * options is a hash that gets turned directly into url params for bing
|
48
|
+
def address_map_url(address, pushpins = [], options = {})
|
30
49
|
options = default_options(options)
|
31
|
-
"#{
|
50
|
+
base = "#{BING_MAPS_URL}#{QUERY_IMAGE_PATH}#{URI.escape(format_waypoint(address))}?#{options.to_params}"
|
51
|
+
if pushpins and pushpins.length > 0
|
52
|
+
formatted_pins = pushpins.map {|p| "pp=#{format_pushpin(p)}" }.join '&'
|
53
|
+
base = "#{base}&#{formatted_pins}" if pushpins
|
54
|
+
end
|
55
|
+
base
|
32
56
|
end
|
33
57
|
|
34
58
|
def location_details_url(address, options = {})
|
35
59
|
options = default_options(options).merge(:o => "json")
|
36
60
|
.merge(structure_address(address))
|
37
|
-
"#{
|
61
|
+
"#{BING_MAPS_URL}#{LOCATION_PATH}?#{options.to_params}"
|
38
62
|
end
|
39
63
|
|
40
64
|
private
|
@@ -66,10 +90,15 @@ module Periplus
|
|
66
90
|
object.send key_or_attribute
|
67
91
|
end
|
68
92
|
end
|
93
|
+
|
94
|
+
def format_pushpin(pushpin)
|
95
|
+
"#{pushpin[:latitude]},#{pushpin[:longitude]};#{pushpin[:type] || ""};#{pushpin[:label] || ""}"
|
96
|
+
end
|
69
97
|
|
70
98
|
ADDRESS_STRUCTURE = {
|
71
99
|
:street => :addressLine,
|
72
100
|
:address => :addressLine,
|
101
|
+
:name => :addressLine,
|
73
102
|
:city => :locality,
|
74
103
|
:state => :adminDistrict,
|
75
104
|
:province => :adminDistrict,
|
@@ -82,13 +111,15 @@ module Periplus
|
|
82
111
|
}
|
83
112
|
|
84
113
|
def structure_address(address)
|
114
|
+
return {:query => address} if address.kind_of? String
|
115
|
+
|
85
116
|
ADDRESS_STRUCTURE.inject({}) do |structured, key_val|
|
86
117
|
unconverted, converted = key_val
|
87
118
|
|
88
119
|
if has_key_or_attribute? address, converted
|
89
|
-
structured[converted]
|
120
|
+
structured[converted] ||= get_by_key_or_attribute address, converted
|
90
121
|
elsif has_key_or_attribute? address, unconverted
|
91
|
-
structured[converted]
|
122
|
+
structured[converted] ||= get_by_key_or_attribute address, unconverted
|
92
123
|
end
|
93
124
|
structured
|
94
125
|
end
|
@@ -110,6 +141,14 @@ module Periplus
|
|
110
141
|
def format_waypoint(waypoint)
|
111
142
|
return waypoint if waypoint.instance_of? String
|
112
143
|
|
144
|
+
# use lat/long if provided
|
145
|
+
if has_key_or_attribute?(waypoint, :latitude) and
|
146
|
+
has_key_or_attribute?(waypoint, :longitude)
|
147
|
+
latitude = get_by_key_or_attribute waypoint, :latitude
|
148
|
+
longitude = get_by_key_or_attribute waypoint, :longitude
|
149
|
+
return "#{latitude},#{longitude}" if latitude and longitude
|
150
|
+
end
|
151
|
+
|
113
152
|
if WAYPOINT_FORMAT
|
114
153
|
.find_all { |el| el.instance_of? Symbol }
|
115
154
|
.any? { |key| has_key_or_attribute?(waypoint, key) }
|
data/periplus.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{periplus}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
12
|
-
s.date = %q{2011-
|
11
|
+
s.authors = [%q{Ryan Crum}]
|
12
|
+
s.date = %q{2011-08-03}
|
13
13
|
s.description = %q{A library that behaves as a client for the Bing Maps REST sdk}
|
14
14
|
s.email = %q{ryan.j.crum@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/periplus/request.rb",
|
32
32
|
"lib/periplus/route.rb",
|
33
33
|
"periplus.gemspec",
|
34
|
-
"spec/
|
34
|
+
"spec/bing_response_spec.rb",
|
35
35
|
"spec/location_spec.rb",
|
36
36
|
"spec/periplus_spec.rb",
|
37
37
|
"spec/request_spec.rb",
|
@@ -39,9 +39,9 @@ Gem::Specification.new do |s|
|
|
39
39
|
"spec/spec_helper.rb"
|
40
40
|
]
|
41
41
|
s.homepage = %q{http://github.com/thorstadt/periplus}
|
42
|
-
s.licenses = [
|
43
|
-
s.require_paths = [
|
44
|
-
s.rubygems_version = %q{1.
|
42
|
+
s.licenses = [%q{MIT}]
|
43
|
+
s.require_paths = [%q{lib}]
|
44
|
+
s.rubygems_version = %q{1.8.5.1}
|
45
45
|
s.summary = %q{Bing Maps REST Client}
|
46
46
|
|
47
47
|
if s.respond_to? :specification_version then
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Periplus::BingResponse do
|
4
|
+
it "throws an exception if the httparty response is HTTP status 4xx" do
|
5
|
+
http_error = Net::HTTPUnauthorized.new "1_1", 401, "Unauthorized"
|
6
|
+
response = mock HTTParty::Response, :response => http_error
|
7
|
+
|
8
|
+
lambda do
|
9
|
+
Periplus::BingResponse.new(response)
|
10
|
+
end.should raise_error(RuntimeError, "An error has occurred communicating with the Bing Maps service. HTTP Status: 401 (Unauthorized)")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "provides helpful debugging information for service failrues" do
|
14
|
+
http_error = Net::HTTPNotFound.new("1_1", 404, "Not Found")
|
15
|
+
http_error.stub!(:body).and_return(
|
16
|
+
{:some_really_long_properties_that_extend => {:deeply_past_the_place_where => {:they_wrap => "stuff"}}}
|
17
|
+
)
|
18
|
+
http_request = HTTParty::Request.new "GET", "/API/cheese"
|
19
|
+
response = mock HTTParty::Response, :response => http_error,
|
20
|
+
:request => http_request
|
21
|
+
|
22
|
+
Periplus.verbose = true
|
23
|
+
|
24
|
+
lambda do
|
25
|
+
begin
|
26
|
+
Periplus::BingResponse.new(response)
|
27
|
+
rescue RuntimeError => e
|
28
|
+
e.message.should == <<-EOF
|
29
|
+
An error has occurred communicating with the Bing Maps service. HTTP Status: 404 (Not Found)
|
30
|
+
URL: /API/cheese
|
31
|
+
Response:
|
32
|
+
{:some_really_long_properties_that_extend=>
|
33
|
+
{:deeply_past_the_place_where=>{:they_wrap=>"stuff"}}}
|
34
|
+
EOF
|
35
|
+
raise e
|
36
|
+
end
|
37
|
+
end.should raise_error(RuntimeError)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "throws an exception if the httparty response contains no routes" do
|
41
|
+
http_ok = Net::HTTPOK.new "1_1", 200, "OK"
|
42
|
+
empty_resource_sets = {
|
43
|
+
"resourceSets" => []
|
44
|
+
}
|
45
|
+
|
46
|
+
empty_single_resource_set = {
|
47
|
+
"resourceSets" => [{"resources" => []}]
|
48
|
+
}
|
49
|
+
|
50
|
+
[empty_resource_sets, empty_single_resource_set].each do |parsed_response|
|
51
|
+
response = mock HTTParty::Response, :response => http_ok, :parsed_response => parsed_response
|
52
|
+
|
53
|
+
begin
|
54
|
+
Periplus::BingResponse.new(response)
|
55
|
+
rescue Exception => e
|
56
|
+
e.message.should == "Not found."
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/spec/request_spec.rb
CHANGED
@@ -47,11 +47,11 @@ describe "Request" do
|
|
47
47
|
|
48
48
|
it "formats an address object correctly" do
|
49
49
|
class PeriplusAddress
|
50
|
-
attr_accessor :address
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
attr_accessor :address,
|
51
|
+
:city,
|
52
|
+
:state,
|
53
|
+
:country,
|
54
|
+
:postal_code
|
55
55
|
end
|
56
56
|
|
57
57
|
address = PeriplusAddress.new
|
@@ -67,6 +67,32 @@ describe "Request" do
|
|
67
67
|
formatted.should == "1600 Pennsylvania Ave Washington, DC US 20500"
|
68
68
|
end
|
69
69
|
|
70
|
+
it "formats an address object correctly with latitude/longitude" do
|
71
|
+
class PeriplusAddress
|
72
|
+
attr_accessor :address,
|
73
|
+
:city,
|
74
|
+
:state,
|
75
|
+
:country,
|
76
|
+
:postal_code,
|
77
|
+
:latitude,
|
78
|
+
:longitude
|
79
|
+
end
|
80
|
+
|
81
|
+
address = PeriplusAddress.new
|
82
|
+
address.address = "1600 Pennsylvania Ave"
|
83
|
+
address.city = "Washington"
|
84
|
+
address.state = "DC"
|
85
|
+
address.country = "US"
|
86
|
+
address.postal_code = 20500
|
87
|
+
address.latitude = "40.32332"
|
88
|
+
address.longitude = "-2.32142"
|
89
|
+
|
90
|
+
req = Periplus::Request.new 'fake key'
|
91
|
+
formatted = req.send :format_waypoint, address
|
92
|
+
|
93
|
+
formatted.should == "40.32332,-2.32142"
|
94
|
+
end
|
95
|
+
|
70
96
|
it "builds a location details url correctly" do
|
71
97
|
address = {
|
72
98
|
:street => "1600 Pennsylvania Ave",
|
@@ -80,4 +106,64 @@ describe "Request" do
|
|
80
106
|
url = req.location_details_url address
|
81
107
|
url.should == "http://dev.virtualearth.net/REST/v1/Locations?key=fake%20key&o=json&addressLine=1600%20Pennsylvania%20Ave&locality=Washington&adminDistrict=DC&countryRegion=US&postalCode=20500"
|
82
108
|
end
|
109
|
+
|
110
|
+
it "builds a location details url from a query string correctly" do
|
111
|
+
address = "1600 Pennsylvania Ave Washington, DC"
|
112
|
+
req = Periplus::Request.new 'fake key'
|
113
|
+
url = req.location_details_url address
|
114
|
+
url.should == "http://dev.virtualearth.net/REST/v1/Locations?key=fake%20key&o=json&query=1600%20Pennsylvania%20Ave%20Washington%2C%20DC"
|
115
|
+
end
|
116
|
+
|
117
|
+
it "builds a location details url correctly with a place name" do
|
118
|
+
address = {
|
119
|
+
:name => "The White House",
|
120
|
+
:city => "Washington",
|
121
|
+
:state => "DC",
|
122
|
+
:country => "US",
|
123
|
+
:zip => 20500
|
124
|
+
}
|
125
|
+
|
126
|
+
req = Periplus::Request.new 'fake key'
|
127
|
+
url = req.location_details_url address
|
128
|
+
url.should == "http://dev.virtualearth.net/REST/v1/Locations?key=fake%20key&o=json&addressLine=The%20White%20House&locality=Washington&adminDistrict=DC&countryRegion=US&postalCode=20500"
|
129
|
+
end
|
130
|
+
|
131
|
+
it "builds a location details url correctly with a place name and an address" do
|
132
|
+
address = {
|
133
|
+
:name => "The White House",
|
134
|
+
:street => "1600 Pennsylvania Ave",
|
135
|
+
:city => "Washington",
|
136
|
+
:state => "DC",
|
137
|
+
:country => "US",
|
138
|
+
:zip => 20500
|
139
|
+
}
|
140
|
+
|
141
|
+
req = Periplus::Request.new 'fake key'
|
142
|
+
url = req.location_details_url address
|
143
|
+
url.should == "http://dev.virtualearth.net/REST/v1/Locations?key=fake%20key&o=json&addressLine=1600%20Pennsylvania%20Ave&locality=Washington&adminDistrict=DC&countryRegion=US&postalCode=20500"
|
144
|
+
end
|
145
|
+
|
146
|
+
it "formats pushpins correctly" do
|
147
|
+
req = Periplus::Request.new 'fake key'
|
148
|
+
|
149
|
+
pushpin = {:latitude => 1337, :longitude => 42.24}
|
150
|
+
formatted = req.send :format_pushpin, pushpin
|
151
|
+
formatted.should == "1337,42.24;;"
|
152
|
+
|
153
|
+
pushpin = {:latitude => 1337, :longitude => 42.24, :label => "pi"}
|
154
|
+
formatted = req.send :format_pushpin, pushpin
|
155
|
+
formatted.should == "1337,42.24;;pi"
|
156
|
+
|
157
|
+
pushpin = {:latitude => 1337, :longitude => 42.24, :type => 3, :label => "pi"}
|
158
|
+
formatted = req.send :format_pushpin, pushpin
|
159
|
+
formatted.should == "1337,42.24;3;pi"
|
160
|
+
end
|
161
|
+
|
162
|
+
it "formats a route url correctly with pushpins" do
|
163
|
+
req = Periplus::Request.new 'fake_key'
|
164
|
+
|
165
|
+
waypoints = ["New York, NY", "Buffalo, NY", "Louisville, KY"]
|
166
|
+
url = req.route_map_url waypoints, [{:latitude => 1337, :longitude => 42}, {:latitude => 42, :longitude => 1337, :label => "sw"}]
|
167
|
+
url.should == "http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/Routes/Driving?wp.1=New%20York%2C%20NY&wp.2=Buffalo%2C%20NY&wp.3=Louisville%2C%20KY&key=fake_key&pp=1337,42;;&pp=42,1337;;sw"
|
168
|
+
end
|
83
169
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: periplus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
13
|
-
default_executable:
|
12
|
+
date: 2011-08-03 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: httparty
|
17
|
-
requirement: &
|
16
|
+
requirement: &7342460 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
18
|
requirements:
|
20
19
|
- - ! '>='
|
@@ -22,10 +21,10 @@ dependencies:
|
|
22
21
|
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
24
|
+
version_requirements: *7342460
|
26
25
|
- !ruby/object:Gem::Dependency
|
27
26
|
name: activesupport
|
28
|
-
requirement: &
|
27
|
+
requirement: &7341160 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
29
|
requirements:
|
31
30
|
- - ! '>='
|
@@ -33,10 +32,10 @@ dependencies:
|
|
33
32
|
version: '0'
|
34
33
|
type: :runtime
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *7341160
|
37
36
|
- !ruby/object:Gem::Dependency
|
38
37
|
name: rspec
|
39
|
-
requirement: &
|
38
|
+
requirement: &7339640 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
41
|
- - ~>
|
@@ -44,10 +43,10 @@ dependencies:
|
|
44
43
|
version: 2.4.0
|
45
44
|
type: :development
|
46
45
|
prerelease: false
|
47
|
-
version_requirements: *
|
46
|
+
version_requirements: *7339640
|
48
47
|
- !ruby/object:Gem::Dependency
|
49
48
|
name: bundler
|
50
|
-
requirement: &
|
49
|
+
requirement: &7338260 !ruby/object:Gem::Requirement
|
51
50
|
none: false
|
52
51
|
requirements:
|
53
52
|
- - ~>
|
@@ -55,10 +54,10 @@ dependencies:
|
|
55
54
|
version: 1.0.0
|
56
55
|
type: :development
|
57
56
|
prerelease: false
|
58
|
-
version_requirements: *
|
57
|
+
version_requirements: *7338260
|
59
58
|
- !ruby/object:Gem::Dependency
|
60
59
|
name: jeweler
|
61
|
-
requirement: &
|
60
|
+
requirement: &7337440 !ruby/object:Gem::Requirement
|
62
61
|
none: false
|
63
62
|
requirements:
|
64
63
|
- - ~>
|
@@ -66,10 +65,10 @@ dependencies:
|
|
66
65
|
version: 1.6.2
|
67
66
|
type: :development
|
68
67
|
prerelease: false
|
69
|
-
version_requirements: *
|
68
|
+
version_requirements: *7337440
|
70
69
|
- !ruby/object:Gem::Dependency
|
71
70
|
name: rcov
|
72
|
-
requirement: &
|
71
|
+
requirement: &7336020 !ruby/object:Gem::Requirement
|
73
72
|
none: false
|
74
73
|
requirements:
|
75
74
|
- - ! '>='
|
@@ -77,7 +76,7 @@ dependencies:
|
|
77
76
|
version: '0'
|
78
77
|
type: :development
|
79
78
|
prerelease: false
|
80
|
-
version_requirements: *
|
79
|
+
version_requirements: *7336020
|
81
80
|
description: A library that behaves as a client for the Bing Maps REST sdk
|
82
81
|
email: ryan.j.crum@gmail.com
|
83
82
|
executables: []
|
@@ -100,13 +99,12 @@ files:
|
|
100
99
|
- lib/periplus/request.rb
|
101
100
|
- lib/periplus/route.rb
|
102
101
|
- periplus.gemspec
|
103
|
-
- spec/
|
102
|
+
- spec/bing_response_spec.rb
|
104
103
|
- spec/location_spec.rb
|
105
104
|
- spec/periplus_spec.rb
|
106
105
|
- spec/request_spec.rb
|
107
106
|
- spec/route_spec.rb
|
108
107
|
- spec/spec_helper.rb
|
109
|
-
has_rdoc: true
|
110
108
|
homepage: http://github.com/thorstadt/periplus
|
111
109
|
licenses:
|
112
110
|
- MIT
|
@@ -122,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
122
120
|
version: '0'
|
123
121
|
segments:
|
124
122
|
- 0
|
125
|
-
hash:
|
123
|
+
hash: 94696388149448647
|
126
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
125
|
none: false
|
128
126
|
requirements:
|
@@ -131,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
129
|
version: '0'
|
132
130
|
requirements: []
|
133
131
|
rubyforge_project:
|
134
|
-
rubygems_version: 1.
|
132
|
+
rubygems_version: 1.8.5.1
|
135
133
|
signing_key:
|
136
134
|
specification_version: 3
|
137
135
|
summary: Bing Maps REST Client
|
data/spec/bing_response.spec
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'periplus'
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
-
|
4
|
-
describe "BingResponse" do
|
5
|
-
it "throws an exception if the httparty response is HTTP status 4xx" do
|
6
|
-
http_error = Net::HTTPUnauthorized.new "1_1", 401, "Unauthorized"
|
7
|
-
response = mock HTTParty::Response, :response => http_error
|
8
|
-
|
9
|
-
begin
|
10
|
-
Periplus::BingResponse.new(response)
|
11
|
-
rescue Exception => e
|
12
|
-
e.message.should == "An error has occurred communicating with the Bing Maps service. HTTP Status: 401 (Unauthorized)"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
it "throws an exception if the httparty response contains no routes" do
|
17
|
-
http_ok = Net::HTTPOK.new "1_1", 200, "OK"
|
18
|
-
empty_resource_sets = {
|
19
|
-
"resourceSets" => []
|
20
|
-
}
|
21
|
-
|
22
|
-
empty_single_resource_set = {
|
23
|
-
"resourceSets" => [{"resources" => []}]
|
24
|
-
}
|
25
|
-
|
26
|
-
[empty_resource_sets, empty_single_resource_set].each do |parsed_response|
|
27
|
-
response = mock HTTParty::Response, :response => http_ok, :parsed_response => parsed_response
|
28
|
-
|
29
|
-
begin
|
30
|
-
Periplus::BingResponse.new(response)
|
31
|
-
rescue Exception => e
|
32
|
-
e.message.should == "Not found."
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|