google_places 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- google_places (0.0.5)
4
+ google_places (0.0.8)
5
5
  httparty
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- crack (0.1.8)
11
- diff-lcs (1.1.2)
10
+ diff-lcs (1.1.3)
12
11
  fakeweb (1.3.0)
13
- httparty (0.7.7)
14
- crack (= 0.1.8)
15
- rspec (2.6.0)
16
- rspec-core (~> 2.6.0)
17
- rspec-expectations (~> 2.6.0)
18
- rspec-mocks (~> 2.6.0)
19
- rspec-core (2.6.0)
20
- rspec-expectations (2.6.0)
21
- diff-lcs (~> 1.1.2)
22
- rspec-mocks (2.6.0)
23
- vcr (1.9.0)
12
+ httparty (0.8.3)
13
+ multi_json (~> 1.0)
14
+ multi_xml
15
+ multi_json (1.3.6)
16
+ multi_xml (0.5.1)
17
+ rspec (2.10.0)
18
+ rspec-core (~> 2.10.0)
19
+ rspec-expectations (~> 2.10.0)
20
+ rspec-mocks (~> 2.10.0)
21
+ rspec-core (2.10.1)
22
+ rspec-expectations (2.10.0)
23
+ diff-lcs (~> 1.1.3)
24
+ rspec-mocks (2.10.1)
25
+ vcr (2.2.2)
24
26
 
25
27
  PLATFORMS
26
28
  ruby
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "google_places"
6
- s.version = '0.0.8'
6
+ s.version = '0.1.0'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Marcel de Graaf"]
9
9
  s.email = ["mail@marceldegraaf.net"]
@@ -15,5 +15,9 @@ module GooglePlaces
15
15
  def spot(reference, options = {})
16
16
  Spot.find(reference, @api_key, @options.merge(options))
17
17
  end
18
+
19
+ def spots_by_query(query, options = {})
20
+ Spot.list_by_query(query, @api_key, @options.merge(options))
21
+ end
18
22
  end
19
23
  end
@@ -7,19 +7,23 @@ module GooglePlaces
7
7
 
8
8
  SPOTS_LIST_URL = 'https://maps.googleapis.com/maps/api/place/search/json'
9
9
  SPOT_URL = 'https://maps.googleapis.com/maps/api/place/details/json'
10
+ SPOTS_LIST_QUERY_URL = 'https://maps.googleapis.com/maps/api/place/textsearch/json'
10
11
 
11
12
  def self.spots(options = {})
12
- # pp options
13
13
  request = new(SPOTS_LIST_URL, options)
14
14
  request.parsed_response
15
15
  end
16
16
 
17
17
  def self.spot(options = {})
18
- # pp options
19
18
  request = new(SPOT_URL, options)
20
19
  request.parsed_response
21
20
  end
22
21
 
22
+ def self.spots_by_query(options = {})
23
+ request = new(SPOTS_LIST_QUERY_URL, options)
24
+ request.parsed_response
25
+ end
26
+
23
27
  def initialize(url, options)
24
28
  retry_options = options.delete(:retry_options) || {}
25
29
 
@@ -54,6 +54,53 @@ module GooglePlaces
54
54
  self.new(response['result'])
55
55
  end
56
56
 
57
+ def self.list_by_query(query, api_key, options)
58
+ if options.has_key?(:lat) && options.has_key?(:lng)
59
+ with_location = true
60
+ else
61
+ with_location = false
62
+ end
63
+
64
+ if options.has_key?(:radius)
65
+ with_radius = true
66
+ else
67
+ with_radius = false
68
+ end
69
+
70
+ query = query
71
+ sensor = options.delete(:sensor) || false
72
+ location = Location.new(options.delete(:lat), options.delete(:lng)) if with_location
73
+ radius = options.delete(:radius) if with_radius
74
+ language = options.delete(:language)
75
+ types = options.delete(:types)
76
+ exclude = options.delete(:exclude) || []
77
+ retry_options = options.delete(:retry_options) || {}
78
+
79
+ exclude = [exclude] unless exclude.is_a?(Array)
80
+
81
+ options = {
82
+ :query => query,
83
+ :sensor => sensor,
84
+ :key => api_key,
85
+ :language => language,
86
+ :retry_options => retry_options
87
+ }
88
+
89
+ options[:location] = location.format if with_location
90
+ options[:radius] = radius if with_radius
91
+
92
+ # Accept Types as a string or array
93
+ if types
94
+ types = (types.is_a?(Array) ? types.join('|') : types)
95
+ options.merge!(:types => types)
96
+ end
97
+
98
+ response = Request.spots_by_query(options)
99
+ response['results'].map do |result|
100
+ self.new(result) if (result['types'] & exclude) == []
101
+ end.compact
102
+ end
103
+
57
104
  def initialize(json_result_object)
58
105
  @reference = json_result_object['reference']
59
106
  @vicinity = json_result_object['vicinity']
@@ -84,7 +131,7 @@ module GooglePlaces
84
131
  component.first[address_component_length] unless component.first.nil?
85
132
  end
86
133
  end
87
-
134
+
88
135
  def address_components_of_type(type)
89
136
  @address_components.select{ |c| c['types'].include?(type.to_s) } unless @address_components.nil?
90
137
  end
@@ -27,4 +27,11 @@ describe GooglePlaces::Client do
27
27
  @client.spot(reference)
28
28
  end
29
29
 
30
+ it 'should request spots by query' do
31
+ query = "Statue of liberty, New York"
32
+ @client = GooglePlaces::Client.new(api_key)
33
+ GooglePlaces::Spot.should_receive(:list_by_query).with(query, api_key, {})
34
+
35
+ @client.spots_by_query(query)
36
+ end
30
37
  end
@@ -4,14 +4,14 @@ describe GooglePlaces::Request do
4
4
 
5
5
  before :each do
6
6
  @location = GooglePlaces::Location.new('-33.8670522', '151.1957362').format
7
+ @query = "Statue of liberty, New York"
7
8
  @radius = 200
8
9
  @sensor = false
9
- @reference = "CoQBeAAAAO-prCRp9Atcj_rvavsLyv-DnxbGkw8QyRZb6Srm6QHOcww6lqFhIs2c7Ie6fMg3PZ4PhicfJL7ZWlaHaLDTqmRisoTQQUn61WTcSXAAiCOzcm0JDBnafqrskSpFtNUgzGAOx29WGnWSP44jmjtioIsJN9ik8yjK7UxP4buAmMPVEhBXPiCfHXk1CQ6XRuQhpztsGhQU4U6-tWjTHcLSVzjbNxoiuihbaA"
10
+ @reference = "CnRsAAAASc4grenwL0h3X5VPNp5fkDNfqbjt3iQtWIPlKS-3ms9GbnCxR_FLHO0B0ZKCgJSg19qymkeHagjQFB4aUL87yhp4mhFTc17DopK1oiYDaeGthztSjERic8TmFNe-6zOpKSdiZWKE6xlQvcbSiWIJchIQOEYZqunSSZqNDoBSs77bWRoUJcMMVANtSlhy0llKI0MI6VcC7DU"
10
11
  end
11
12
 
12
13
  context 'Listing spots' do
13
14
  use_vcr_cassette 'list_spots'
14
-
15
15
  context 'with valid options' do
16
16
  it 'should retrieve a list of spots' do
17
17
  response = GooglePlaces::Request.spots(
@@ -20,11 +20,9 @@ describe GooglePlaces::Request do
20
20
  :sensor => @sensor,
21
21
  :key => api_key
22
22
  )
23
-
24
23
  response['results'].should_not be_empty
25
24
  end
26
25
  end
27
-
28
26
  context 'with missing sensor' do
29
27
  it do
30
28
  lambda {
@@ -36,7 +34,6 @@ describe GooglePlaces::Request do
36
34
  }.should raise_error GooglePlaces::RequestDeniedError
37
35
  end
38
36
  end
39
-
40
37
  context 'without location' do
41
38
  context 'without retry options' do
42
39
  it do
@@ -49,7 +46,6 @@ describe GooglePlaces::Request do
49
46
  }.should raise_error GooglePlaces::InvalidRequestError
50
47
  end
51
48
  end
52
-
53
49
  context 'with retry options' do
54
50
  context 'without timeout' do
55
51
  it do
@@ -67,7 +63,6 @@ describe GooglePlaces::Request do
67
63
  }.should raise_error GooglePlaces::RetryError
68
64
  end
69
65
  end
70
-
71
66
  context 'with timeout' do
72
67
  it do
73
68
  lambda {
@@ -89,9 +84,84 @@ describe GooglePlaces::Request do
89
84
  end
90
85
  end
91
86
 
87
+
88
+ context 'Listing spots by query' do
89
+ use_vcr_cassette 'list_spots'
90
+
91
+ context 'with valid options' do
92
+ it 'should retrieve a list of spots' do
93
+ response = GooglePlaces::Request.spots_by_query(
94
+ :query => @query,
95
+ :sensor => @sensor,
96
+ :key => api_key
97
+ )
98
+
99
+ response['results'].should_not be_empty
100
+ end
101
+ end
102
+
103
+ context 'with missing sensor' do
104
+ it do
105
+ lambda {
106
+ GooglePlaces::Request.spots_by_query(
107
+ :query => @query,
108
+ :key => api_key
109
+ )
110
+ }.should raise_error GooglePlaces::RequestDeniedError
111
+ end
112
+ end
113
+
114
+ context 'without query' do
115
+ context 'without retry options' do
116
+ it do
117
+ lambda {
118
+ GooglePlaces::Request.spots_by_query(
119
+ :sensor => @sensor,
120
+ :key => api_key
121
+ )
122
+ }.should raise_error GooglePlaces::InvalidRequestError
123
+ end
124
+ end
125
+
126
+ context 'with retry options' do
127
+ context 'without timeout' do
128
+ it do
129
+ lambda {
130
+ GooglePlaces::Request.spots_by_query(
131
+ :sensor => @sensor,
132
+ :key => api_key,
133
+ :retry_options => {
134
+ :max => 3,
135
+ :status => 'INVALID_REQUEST',
136
+ :delay => 1
137
+ }
138
+ )
139
+ }.should raise_error GooglePlaces::RetryError
140
+ end
141
+ end
142
+
143
+ context 'with timeout' do
144
+ it do
145
+ lambda {
146
+ GooglePlaces::Request.spots_by_query(
147
+ :sensor => @sensor,
148
+ :key => api_key,
149
+ :retry_options => {
150
+ :max => 3,
151
+ :status => 'INVALID_REQUEST',
152
+ :delay => 10,
153
+ :timeout => 1
154
+ }
155
+ )
156
+ }.should raise_error GooglePlaces::RetryTimeoutError
157
+ end
158
+ end
159
+ end
160
+ end
161
+ end
162
+
92
163
  context 'Spot details' do
93
164
  use_vcr_cassette 'single_spot'
94
-
95
165
  context 'with valid options' do
96
166
  it 'should retrieve a single spot' do
97
167
  response = GooglePlaces::Request.spot(
@@ -99,11 +169,9 @@ describe GooglePlaces::Request do
99
169
  :sensor => @sensor,
100
170
  :key => api_key
101
171
  )
102
-
103
172
  response['result'].should_not be_empty
104
173
  end
105
174
  end
106
-
107
175
  context 'with missing sensor' do
108
176
  it do
109
177
  lambda {
@@ -114,7 +182,6 @@ describe GooglePlaces::Request do
114
182
  }.should raise_error GooglePlaces::RequestDeniedError
115
183
  end
116
184
  end
117
-
118
185
  context 'with missing reference' do
119
186
  context 'without retry options' do
120
187
  it do
@@ -126,7 +193,6 @@ describe GooglePlaces::Request do
126
193
  }.should raise_error GooglePlaces::InvalidRequestError
127
194
  end
128
195
  end
129
-
130
196
  context 'with retry options' do
131
197
  context 'without timeout' do
132
198
  it do
@@ -143,7 +209,6 @@ describe GooglePlaces::Request do
143
209
  }.should raise_error GooglePlaces::RetryError
144
210
  end
145
211
  end
146
-
147
212
  context 'with timeout' do
148
213
  it do
149
214
  lambda {
@@ -7,7 +7,7 @@ describe GooglePlaces::Spot do
7
7
  @lng = '151.1957362'
8
8
  @radius = 200
9
9
  @sensor = false
10
- @reference = "CoQBeAAAAO-prCRp9Atcj_rvavsLyv-DnxbGkw8QyRZb6Srm6QHOcww6lqFhIs2c7Ie6fMg3PZ4PhicfJL7ZWlaHaLDTqmRisoTQQUn61WTcSXAAiCOzcm0JDBnafqrskSpFtNUgzGAOx29WGnWSP44jmjtioIsJN9ik8yjK7UxP4buAmMPVEhBXPiCfHXk1CQ6XRuQhpztsGhQU4U6-tWjTHcLSVzjbNxoiuihbaA"
10
+ @reference = "CnRsAAAASc4grenwL0h3X5VPNp5fkDNfqbjt3iQtWIPlKS-3ms9GbnCxR_FLHO0B0ZKCgJSg19qymkeHagjQFB4aUL87yhp4mhFTc17DopK1oiYDaeGthztSjERic8TmFNe-6zOpKSdiZWKE6xlQvcbSiWIJchIQOEYZqunSSZqNDoBSs77bWRoUJcMMVANtSlhy0llKI0MI6VcC7DU"
11
11
  end
12
12
 
13
13
  context 'List spots' do
@@ -116,17 +116,30 @@ describe GooglePlaces::Spot do
116
116
 
117
117
  end
118
118
 
119
+
120
+
121
+
122
+ context 'List spots by query' do
123
+ use_vcr_cassette 'list_spots'
124
+
125
+ after(:each) do
126
+ @collection.map(&:class).uniq.should == [GooglePlaces::Spot]
127
+ end
128
+
129
+ it 'should be a collection of Spots' do
130
+ @collection = GooglePlaces::Spot.list_by_query("Statue of liberty, New York", api_key, :sensor => @sensor)
131
+ end
132
+
133
+ end
134
+
119
135
  context 'Find a single spot' do
120
136
  use_vcr_cassette 'single_spot'
121
-
122
137
  before :each do
123
138
  @spot = GooglePlaces::Spot.find(@reference, api_key, :sensor => @sensor)
124
139
  end
125
-
126
140
  it 'should be a Spot' do
127
141
  @spot.class.should == GooglePlaces::Spot
128
142
  end
129
-
130
143
  %w(reference vicinity lat lng name icon types id formatted_phone_number international_phone_number formatted_address address_components street_number street city region postal_code country rating url types website).each do |attribute|
131
144
  it "should have the attribute: #{attribute}" do
132
145
  @spot.respond_to?(attribute).should == true
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_places
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 8
10
- version: 0.0.8
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marcel de Graaf
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-13 00:00:00 Z
18
+ date: 2012-07-01 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: httparty
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  requirements: []
132
132
 
133
133
  rubyforge_project:
134
- rubygems_version: 1.8.6
134
+ rubygems_version: 1.8.23
135
135
  signing_key:
136
136
  specification_version: 3
137
137
  summary: A Ruby wrapper around the Google Places API.