bing 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,18 @@
1
+ === 0.3.0 / 2014-06-22
2
+ * 11 minor enhancement(s):
3
+
4
+ * Add info about traffic to Bing Maps routes
5
+ * Added imagery to manifest and rm'd hacks for Travis CI.
6
+ * Began imagery connection.
7
+ * Beginning stages of imagery integration.
8
+ * Hack to build.
9
+ * Imagery is basically done but is messy.
10
+ * Merge pull request #1 from skrobul/master
11
+ * Some readme notes.
12
+ * add duration in traffic
13
+ * add getter for traffic time
14
+ * see if build will succeed this time...
15
+
1
16
  === 0.2.0 / 2011-08-05
2
17
  * 4 minor enhancement(s):
3
18
 
data/Manifest.txt CHANGED
@@ -7,6 +7,7 @@ Rakefile
7
7
  lib/bing.rb
8
8
  lib/bing/core_ext.rb
9
9
  lib/bing/errors.rb
10
+ lib/bing/imagery.rb
10
11
  lib/bing/location.rb
11
12
  lib/bing/request.rb
12
13
  lib/bing/rest_resource.rb
@@ -14,6 +15,7 @@ lib/bing/route.rb
14
15
  lib/bing/route/itinerary.rb
15
16
  test/helper.rb
16
17
  test/test_bing.rb
18
+ test/test_bing_imagery.rb
17
19
  test/test_bing_location.rb
18
20
  test/test_bing_request.rb
19
21
  test/test_bing_rest_resource.rb
data/README.txt CHANGED
@@ -14,6 +14,15 @@ Bing api client library that exposes all of Bing's api features.
14
14
 
15
15
  == SYNOPSIS:
16
16
 
17
+ All methods for retrieval strive to just pass through params to Bing. This is
18
+ desired to have Bing be canonical on the API integration with limited mapping
19
+ client side. What this means is that when Bing says it accepts the param
20
+ "centerPoint", you can pass this straight through as :center_point. The values
21
+ are simply strings which means when Bing says you do "centerPoint=47.610,
22
+ -122.107", you will do :center_point => '47.610,-122.107'.
23
+
24
+ Some code examples:
25
+
17
26
  # For locations
18
27
  require 'bing/location'
19
28
 
@@ -71,3 +80,4 @@ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
71
80
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
72
81
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
73
82
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
83
+
@@ -0,0 +1,83 @@
1
+ require 'bing/rest_resource'
2
+
3
+ ##
4
+ # Responsible for generating static Bing maps.
5
+ # Note: Bing static map generation is not very good. Even examples on their
6
+ # api docs (http://msdn.microsoft.com/en-us/library/ff701724.aspx) do not work
7
+ # as expected. One typical usage that does work is:
8
+ #
9
+ # Bing::Imagery.find_by_query '123 Street City STATE'
10
+ #
11
+ # The Bing documentation is okay in that some params do not work with other
12
+ # params like:
13
+ #
14
+ # Bing::Imagery.find_by_query '123 Street City STATE', :zoom_level => 20
15
+ #
16
+ # This has no affect on the static maps by query :(. The only way for it to
17
+ # work is to use a point search:
18
+ #
19
+ # Bing::Imagery.find_by_center_point [LAT, LON]
20
+ # Bing::Imagery.find_by_center_point [LAT, LON], :zoom_level => 10
21
+
22
+ class Bing::Imagery < Bing::RestResource
23
+ # TODO need to clean up and have it work better, but I don't have time right
24
+ # now. This is a pretty big mess :(
25
+
26
+ def self.find_by_center_point coords, opts = {}
27
+ imagery_set = opts.delete :imagery_set
28
+ zoom_level = opts.delete(:zoom_level) || 15
29
+
30
+ coords = coords.join ','
31
+ coords_and_zoom = [coords, zoom_level].join '/'
32
+ opts[:push_pin] ||= coords
33
+
34
+ # TODO need to figure out path below to potentially clean this up.
35
+ uri = Bing.config[:map_uri].merge(
36
+ "#{path imagery_set, coords_and_zoom}?key=#{Bing.config[:api_key]}&#{opts.to_lower_camelized_param}"
37
+ )
38
+
39
+ Bing::Request.get uri
40
+ end
41
+
42
+ ##
43
+ # Find a static map based off of a query E.g. 123 Street City STATE.
44
+ # +query+ should be a non-escaped text sequence. If it is already escaped
45
+ # Bing will 40* you. Basically GIGO.
46
+
47
+ def self.find_by_query query, opts = {}
48
+ imagery_set = opts.delete :imagery_set
49
+
50
+ # TODO need to figure out path below to potentially clean this up.
51
+ uri = Bing.config[:map_uri].merge(
52
+ "#{path imagery_set, query}?key=#{Bing.config[:api_key]}&#{opts.to_lower_camelized_param}"
53
+ )
54
+
55
+ Bing::Request.get uri
56
+ end
57
+
58
+ def self.find_by_waypoints waypoints, opts = {}
59
+ imagery_set = opts.delete :imagery_set
60
+
61
+ query = "Routes"
62
+ waypoints = format_waypoints waypoints
63
+ params = [opts.to_lower_camelized_param, waypoints].join '&'
64
+
65
+ # TODO need to figure out path below to potentially clean this up.
66
+ uri = Bing.config[:map_uri].merge(
67
+ "#{path imagery_set, query}?key=#{Bing.config[:api_key]}&#{params}"
68
+ )
69
+
70
+ Bing::Request.get uri
71
+ end
72
+
73
+ # TODO this is not my favorite at all. I need to figure out a way to handle
74
+ # paths better
75
+
76
+ def self.path imagery_set = nil, resource = nil
77
+ imagery_set ||= 'Road'
78
+ resource = resource ? "/#{URI.escape resource}" : nil
79
+ super "/Imagery/Map/#{imagery_set}#{resource}"
80
+ end
81
+
82
+ end
83
+
data/lib/bing/request.rb CHANGED
@@ -13,6 +13,8 @@ class Bing::Request
13
13
  def self.get uri
14
14
  response = HTTP.request uri
15
15
 
16
+ puts uri if ENV['DEBUG']
17
+
16
18
  raise Bing::BadGateway.bad_response(response.code, uri) unless
17
19
  response.code =~ /20\d/
18
20
 
@@ -7,14 +7,6 @@ class Bing::RestResource
7
7
 
8
8
  BASE_PATH = "/REST/#{Bing.config[:api_version]}"
9
9
 
10
- def self._find uri
11
- body = JSON.parse Bing::Request.get(uri).body
12
-
13
- body['resourceSets'].first['resources'].map do |resource|
14
- new resource
15
- end.compact
16
- end
17
-
18
10
  def self.map_uri params
19
11
  Bing.config[:map_uri].merge(
20
12
  "#{path}?key=#{Bing.config[:api_key]}&#{params}"
@@ -22,7 +14,12 @@ class Bing::RestResource
22
14
  end
23
15
 
24
16
  def self.map_find params
25
- _find map_uri params
17
+ resp = Bing::Request.get map_uri params
18
+ body = JSON.parse resp.body
19
+
20
+ body['resourceSets'].first['resources'].map do |resource|
21
+ new resource
22
+ end.compact
26
23
  end
27
24
 
28
25
  def self.path subclass_path = nil
@@ -47,5 +44,18 @@ class Bing::RestResource
47
44
  }
48
45
  end
49
46
 
47
+ private
48
+
49
+ def self.format_waypoints waypoints
50
+ return unless waypoints
51
+ ways = []
52
+
53
+ waypoints.each_with_index do |way, i|
54
+ ways << "waypoint.#{i}=#{CGI.escape way}"
55
+ end
56
+
57
+ ways.join '&'
58
+ end
59
+
50
60
  end
51
61
 
data/lib/bing/route.rb CHANGED
@@ -49,6 +49,7 @@ class Bing::Route < Bing::RestResource
49
49
  attr_reader :starting_coordinates
50
50
  attr_reader :total_distance
51
51
  attr_reader :total_duration
52
+ attr_reader :total_duration_traffic
52
53
  attr_reader :type
53
54
 
54
55
  def initialize resource
@@ -58,6 +59,7 @@ class Bing::Route < Bing::RestResource
58
59
  @duration_unit = resource['durationUnit']
59
60
  @total_distance = resource['travelDistance']
60
61
  @total_duration = resource['travelDuration']
62
+ @total_duration_traffic = resource['travelDurationTraffic']
61
63
 
62
64
  if resource['bbox'] then
63
65
  @bounding_box = bbox resource['bbox']
@@ -84,19 +86,6 @@ class Bing::Route < Bing::RestResource
84
86
  end
85
87
  end
86
88
 
87
- private
88
-
89
- def self.format_waypoints waypoints
90
- return unless waypoints
91
- ways = []
92
-
93
- waypoints.each_with_index do |way, i|
94
- ways << "waypoint.#{i}=#{CGI.escape way}"
95
- end
96
-
97
- ways.join '&'
98
- end
99
-
100
89
  end
101
90
 
102
91
  require 'bing/route/itinerary'
data/lib/bing.rb CHANGED
@@ -5,7 +5,7 @@ require 'json'
5
5
 
6
6
  module Bing
7
7
 
8
- VERSION = '0.2.0'
8
+ VERSION = '0.3.0'
9
9
 
10
10
  DEFAULTS = {
11
11
  :api_key => 'AtsQ7PXwSqL266EUdxMYj3b4-H5A6ubkf8DwH-B4k3rVmmPycUrhmH-lZKHeWXm-',
data/test/helper.rb CHANGED
@@ -3,8 +3,8 @@ require 'logger'
3
3
  require "minitest/autorun"
4
4
  require "webmock"
5
5
 
6
- require "bing"
7
6
  require "bing/location"
7
+ require "bing/imagery"
8
8
  require "bing/route"
9
9
 
10
10
  include WebMock::API
@@ -0,0 +1,32 @@
1
+ require 'helper'
2
+
3
+ # TODO need to add more tests.
4
+
5
+ class TestBingImagery < MiniTest::Unit::TestCase
6
+ BI = Bing::Imagery
7
+
8
+ def test_cls_path
9
+ assert_match %r[Imagery/Map/Road], BI.path
10
+ assert_match %r[Imagery/Map/Road], BI.path('Road')
11
+ assert_match %r[Imagery/Map/AerialWithLabels], BI.path('AerialWithLabels')
12
+
13
+ assert_match %r[Imagery/Map/Road/funky], BI.path(nil, 'funky')
14
+ assert_match %r[Imagery/Map/Road/funky%20monkey], BI.path(nil, 'funky monkey')
15
+ end
16
+
17
+ def test_cls_find
18
+ location_body = {
19
+ "resourceSets" =>[{
20
+ "resources" =>[{
21
+ "point" => {"coordinates" => [34.148294, -118.255262]}
22
+ }]
23
+ }]}.to_json
24
+
25
+ mock_map_request 200, Bing::Location.path, location_body
26
+ mock_map_request 200, BI.path, ''
27
+
28
+ BI.find_by_query "doesn't matter"
29
+ end
30
+
31
+ end
32
+
@@ -1,6 +1,10 @@
1
1
  require 'helper'
2
2
 
3
3
  class Bing::RestResource
4
+ class << self
5
+ public :format_waypoints
6
+ end
7
+
4
8
  def initialize *args
5
9
  end
6
10
  end
@@ -13,10 +17,18 @@ class TestBingRestResource < MiniTest::Unit::TestCase
13
17
  assert_equal '/REST/v1', BRR::BASE_PATH
14
18
  end
15
19
 
16
- def test_cls__find
17
- stub_request(:any, /.*/).to_return(:status => 200, :body => body)
20
+ def test_format_waypoints
21
+ waypoints = ['start', 'end']
22
+
23
+ assert_equal 'waypoint.0=start&waypoint.1=end',
24
+ BRR.format_waypoints(waypoints)
25
+
26
+ waypoints = ["4.9, -1.2", "1.2, 2.2"]
27
+
28
+ assert_equal 'waypoint.0=4.9%2C+-1.2&waypoint.1=1.2%2C+2.2',
29
+ BRR.format_waypoints(waypoints)
18
30
 
19
- assert_resource BRR._find URI.parse 'http://example.com'
31
+ assert_equal nil, BRR.format_waypoints(nil)
20
32
  end
21
33
 
22
34
  def test_map_uri
@@ -1,11 +1,5 @@
1
1
  require 'helper'
2
2
 
3
- class Bing::Route
4
- class << self
5
- public :format_waypoints
6
- end
7
- end
8
-
9
3
  class TestBingRoute < MiniTest::Unit::TestCase
10
4
 
11
5
  BR = Bing::Route
@@ -24,20 +18,6 @@ class TestBingRoute < MiniTest::Unit::TestCase
24
18
  route = BR.find :waypoints => ['start', 'end']
25
19
  end
26
20
 
27
- def test_cls_format_waypoints
28
- waypoints = ['start', 'end']
29
-
30
- assert_equal 'waypoint.0=start&waypoint.1=end',
31
- BR.format_waypoints(waypoints)
32
-
33
- waypoints = ["4.9, -1.2", "1.2, 2.2"]
34
-
35
- assert_equal 'waypoint.0=4.9%2C+-1.2&waypoint.1=1.2%2C+2.2',
36
- BR.format_waypoints(waypoints)
37
-
38
- assert_equal nil, BR.format_waypoints(nil)
39
- end
40
-
41
21
  def test_cls_path
42
22
  assert_match %r[Route], BR.path
43
23
  end
metadata CHANGED
@@ -1,136 +1,154 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bing
3
- version: !ruby/object:Gem::Version
4
- hash: 23
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 0
10
- version: 0.2.0
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Adam Avilla
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-05 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2014-06-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: net-http-persistent
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 1
31
- - 6
32
- version: "1.6"
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: json
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 5
44
- segments:
45
- - 1
46
- - 5
47
- - 3
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
48
37
  version: 1.5.3
49
38
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: minitest
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
55
- none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.5.3
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '4.0'
63
54
  type: :development
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: git
67
55
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
69
- none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: minitest
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
77
70
  type: :development
78
- version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
80
- name: webmock
81
71
  prerelease: false
82
- requirement: &id005 !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: git
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
91
86
  type: :development
92
- version_requirements: *id005
93
- - !ruby/object:Gem::Dependency
94
- name: ZenTest
95
87
  prerelease: false
96
- requirement: &id006 !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ">="
100
- - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
- version: "0"
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
105
102
  type: :development
106
- version_requirements: *id006
107
- - !ruby/object:Gem::Dependency
108
- name: hoe
109
103
  prerelease: false
110
- requirement: &id007 !ruby/object:Gem::Requirement
104
+ version_requirements: !ruby/object:Gem::Requirement
111
105
  none: false
112
- requirements:
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: ZenTest
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: hoe
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
113
131
  - - ~>
114
- - !ruby/object:Gem::Version
115
- hash: 23
116
- segments:
117
- - 2
118
- - 10
119
- version: "2.10"
132
+ - !ruby/object:Gem::Version
133
+ version: '3.12'
120
134
  type: :development
121
- version_requirements: *id007
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: '3.12'
122
142
  description: Bing api client library that exposes all of Bing's api features.
123
- email:
143
+ email:
124
144
  - adam@avil.la
125
145
  executables: []
126
-
127
146
  extensions: []
128
-
129
- extra_rdoc_files:
147
+ extra_rdoc_files:
130
148
  - History.txt
131
149
  - Manifest.txt
132
150
  - README.txt
133
- files:
151
+ files:
134
152
  - .autotest
135
153
  - .gitignore
136
154
  - History.txt
@@ -140,6 +158,7 @@ files:
140
158
  - lib/bing.rb
141
159
  - lib/bing/core_ext.rb
142
160
  - lib/bing/errors.rb
161
+ - lib/bing/imagery.rb
143
162
  - lib/bing/location.rb
144
163
  - lib/bing/request.rb
145
164
  - lib/bing/rest_resource.rb
@@ -147,6 +166,7 @@ files:
147
166
  - lib/bing/route/itinerary.rb
148
167
  - test/helper.rb
149
168
  - test/test_bing.rb
169
+ - test/test_bing_imagery.rb
150
170
  - test/test_bing_location.rb
151
171
  - test/test_bing_request.rb
152
172
  - test/test_bing_rest_resource.rb
@@ -155,44 +175,38 @@ files:
155
175
  - test/test_core_ext.rb
156
176
  - .gemtest
157
177
  homepage: https://github.com/hekaldama/bing
158
- licenses: []
159
-
178
+ licenses:
179
+ - MIT
160
180
  post_install_message:
161
- rdoc_options:
181
+ rdoc_options:
162
182
  - --main
163
183
  - README.txt
164
- require_paths:
184
+ require_paths:
165
185
  - lib
166
- required_ruby_version: !ruby/object:Gem::Requirement
186
+ required_ruby_version: !ruby/object:Gem::Requirement
167
187
  none: false
168
- requirements:
169
- - - ">="
170
- - !ruby/object:Gem::Version
171
- hash: 3
172
- segments:
173
- - 0
174
- version: "0"
175
- required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ! '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
193
  none: false
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- hash: 3
181
- segments:
182
- - 0
183
- version: "0"
194
+ requirements:
195
+ - - ! '>='
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
184
198
  requirements: []
185
-
186
- rubyforge_project: bing
187
- rubygems_version: 1.8.6
199
+ rubyforge_project:
200
+ rubygems_version: 1.8.25
188
201
  signing_key:
189
202
  specification_version: 3
190
203
  summary: Bing api client library that exposes all of Bing's api features.
191
- test_files:
204
+ test_files:
205
+ - test/test_bing_route_itinerary.rb
192
206
  - test/test_bing.rb
193
- - test/test_bing_location.rb
194
- - test/test_bing_rest_resource.rb
195
- - test/test_core_ext.rb
196
207
  - test/test_bing_route.rb
197
- - test/test_bing_route_itinerary.rb
208
+ - test/test_bing_rest_resource.rb
198
209
  - test/test_bing_request.rb
210
+ - test/test_bing_imagery.rb
211
+ - test/test_core_ext.rb
212
+ - test/test_bing_location.rb