google-api-client 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,30 @@
1
+ # Copyright 2010 Google Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module Google
17
+ class APIClient
18
+ ##
19
+ # An error which is raised when there is an unexpected response or other
20
+ # transport error that prevents an operation from succeeding.
21
+ class TransmissionError < StandardError
22
+ end
23
+
24
+ ##
25
+ # An exception that is raised if a method is called with missing or
26
+ # invalid parameter values.
27
+ class ValidationError < StandardError
28
+ end
29
+ end
30
+ end
@@ -12,6 +12,7 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+
15
16
  require 'json'
16
17
 
17
18
  module Google
@@ -12,12 +12,13 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+
15
16
  module Google
16
17
  class APIClient
17
18
  module VERSION
18
19
  MAJOR = 0
19
- MINOR = 1
20
- TINY = 3
20
+ MINOR = 2
21
+ TINY = 0
21
22
 
22
23
  STRING = [MAJOR, MINOR, TINY].join('.')
23
24
  end
@@ -0,0 +1,23 @@
1
+ # Copyright 2010 Google Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module Google
17
+ if defined?(ActiveSupport::Inflector)
18
+ INFLECTOR = ActiveSupport::Inflector
19
+ else
20
+ require 'extlib/inflection'
21
+ INFLECTOR = Extlib::Inflection
22
+ end
23
+ end
@@ -21,422 +21,422 @@ require 'google/api_client'
21
21
  require 'google/api_client/version'
22
22
  require 'google/api_client/parsers/json_parser'
23
23
 
24
- describe Google::APIClient, 'unconfigured' do
24
+ describe Google::APIClient do
25
25
  before do
26
26
  @client = Google::APIClient.new
27
27
  end
28
28
 
29
- it 'should not be able to determine the discovery URI' do
29
+ it 'should raise a type error for bogus authorization' do
30
30
  (lambda do
31
- @client.discovery_uri
32
- end).should raise_error(ArgumentError)
33
- end
34
- end
35
-
36
- describe Google::APIClient, 'configured for a bogus API' do
37
- before do
38
- @client = Google::APIClient.new(:service => 'bogus')
31
+ Google::APIClient.new(:authorization => 42)
32
+ end).should raise_error(TypeError)
39
33
  end
40
34
 
41
- it 'should not be able to retrieve the discovery document' do
35
+ it 'should not be able to retrieve the discovery document for a bogus API' do
42
36
  (lambda do
43
- @client.discovery_document
37
+ @client.discovery_document('bogus')
44
38
  end).should raise_error(Google::APIClient::TransmissionError)
45
- end
46
- end
47
-
48
- describe Google::APIClient, 'configured for bogus authorization' do
49
- it 'should raise a type error' do
50
39
  (lambda do
51
- Google::APIClient.new(:service => 'prediction', :authorization => 42)
52
- end).should raise_error(TypeError)
53
- end
54
- end
55
-
56
- describe Google::APIClient, 'configured for the prediction API' do
57
- before do
58
- @client = Google::APIClient.new(:service => 'prediction')
59
- end
60
-
61
- it 'should correctly determine the discovery URI' do
62
- @client.discovery_uri.should ===
63
- 'http://www.googleapis.com/discovery/0.1/describe?api=prediction'
64
- end
65
-
66
- it 'should have multiple versions available' do
67
- @client.discovered_services.size.should > 1
68
- end
69
-
70
- it 'should find APIs that are in the discovery document' do
71
- @client.discovered_service('prediction').name.should == 'prediction'
72
- @client.discovered_service('prediction').version.should == 'v1'
73
- @client.discovered_service(:prediction).name.should == 'prediction'
74
- @client.discovered_service(:prediction).version.should == 'v1'
75
- end
76
-
77
- it 'should find API versions that are in the discovery document' do
78
- @client.discovered_service('prediction', 'v1.1').version.should == 'v1.1'
79
- end
80
-
81
- it 'should not find APIs that are not in the discovery document' do
82
- @client.discovered_service('bogus').should == nil
40
+ @client.discovered_api('bogus')
41
+ end).should raise_error(Google::APIClient::TransmissionError)
83
42
  end
84
43
 
85
44
  it 'should raise an error for bogus services' do
86
45
  (lambda do
87
- @client.discovered_service(42)
46
+ @client.discovered_api(42)
88
47
  end).should raise_error(TypeError)
89
48
  end
90
49
 
91
- it 'should find methods that are in the discovery document' do
92
- @client.discovered_method('prediction.training.insert').name.should ==
93
- 'insert'
94
- @client.discovered_method(:'prediction.training.insert').name.should ==
95
- 'insert'
96
- end
97
-
98
- it 'should find methods for versions that are in the discovery document' do
99
- @client.discovered_method(
100
- 'prediction.training.delete', 'v1.1'
101
- ).should_not == nil
102
- end
103
-
104
- it 'should not find methods that are not in the discovery document' do
105
- @client.discovered_method('prediction.training.delete', 'v1').should == nil
106
- @client.discovered_method('prediction.bogus').should == nil
107
- end
108
-
109
- it 'should raise an error for bogus methods' do
110
- (lambda do
111
- @client.discovered_method(42)
112
- end).should raise_error(TypeError)
113
- end
114
-
115
- it 'should correctly determine the latest version' do
116
- @client.latest_service_version('prediction').version.should_not == 'v1'
117
- @client.latest_service_version(:prediction).version.should_not == 'v1'
118
- end
119
-
120
50
  it 'should raise an error for bogus services' do
121
51
  (lambda do
122
- @client.latest_service_version(42)
52
+ @client.preferred_version(42)
123
53
  end).should raise_error(TypeError)
124
54
  end
125
55
 
126
- it 'should correctly determine the latest version' do
127
- # Sanity check the algorithm
128
- @client.discovered_services.clear
129
- @client.discovered_services <<
130
- Google::APIClient::Service.new('magic', 'v1', {})
131
- @client.discovered_services <<
132
- Google::APIClient::Service.new('magic', 'v1.1', {})
133
- @client.discovered_services <<
134
- Google::APIClient::Service.new('magic', 'v1.10', {})
135
- @client.discovered_services <<
136
- Google::APIClient::Service.new('magic', 'v10.0.1', {})
137
- @client.discovered_services <<
138
- Google::APIClient::Service.new('magic', 'v10.1', {})
139
- @client.discovered_services <<
140
- Google::APIClient::Service.new('magic', 'v2.1', {})
141
- @client.discovered_services <<
142
- Google::APIClient::Service.new('magic', 'v10.0', {})
143
- @client.latest_service_version('magic').version.should == 'v10.1'
144
- end
145
-
146
- it 'should correctly determine the latest version' do
147
- # Sanity check the algorithm
148
- @client.discovered_services.clear
149
- @client.discovered_services <<
150
- Google::APIClient::Service.new('one', 'v3', {})
151
- @client.discovered_services <<
152
- Google::APIClient::Service.new('two', 'v1', {})
153
- @client.discovered_services <<
154
- Google::APIClient::Service.new('two', 'v1.1-r1c3', {})
155
- @client.discovered_services <<
156
- Google::APIClient::Service.new('two', 'v2', {})
157
- @client.discovered_services <<
158
- Google::APIClient::Service.new('two', 'v2beta1', {})
159
- @client.discovered_services <<
160
- Google::APIClient::Service.new('two', 'test2', {})
161
- @client.latest_service_version('two').version.should == 'v2'
162
- end
163
-
164
- it 'should return nil for bogus service names' do
165
- # Sanity check the algorithm
166
- @client.latest_service_version('bogus').should == nil
167
- end
168
-
169
- it 'should generate valid requests' do
170
- request = @client.generate_request(
171
- 'prediction.training.insert',
172
- {'query' => '12345'}
173
- )
174
- method, uri, headers, body = request
175
- method.should == 'POST'
176
- uri.should ==
177
- 'https://www.googleapis.com/prediction/v1/training?query=12345'
178
- (headers.inject({}) { |h,(k,v)| h[k]=v; h }).should == {}
179
- body.should respond_to(:each)
180
- end
181
-
182
- it 'should generate requests against the correct URIs' do
183
- request = @client.generate_request(
184
- :'prediction.training.insert',
185
- {'query' => '12345'}
186
- )
187
- method, uri, headers, body = request
188
- uri.should ==
189
- 'https://www.googleapis.com/prediction/v1/training?query=12345'
190
- end
191
-
192
- it 'should generate requests against the correct URIs' do
193
- prediction = @client.discovered_service('prediction', 'v1')
194
- request = @client.generate_request(
195
- prediction.training.insert,
196
- {'query' => '12345'}
197
- )
198
- method, uri, headers, body = request
199
- uri.should ==
200
- 'https://www.googleapis.com/prediction/v1/training?query=12345'
201
- end
202
-
203
- it 'should allow modification to the base URIs for testing purposes' do
204
- prediction = @client.discovered_service('prediction', 'v1')
205
- prediction.base = 'https://testing-domain.googleapis.com/prediction/v1/'
206
- request = @client.generate_request(
207
- prediction.training.insert,
208
- {'query' => '123'}
209
- )
210
- method, uri, headers, body = request
211
- uri.should ==
212
- 'https://testing-domain.googleapis.com/prediction/v1/training?query=123'
213
- end
214
-
215
- it 'should generate signed requests' do
216
- @client.authorization = :oauth_1
217
- @client.authorization.token_credential_key = '12345'
218
- @client.authorization.token_credential_secret = '12345'
219
- request = @client.generate_request(
220
- 'prediction.training.insert',
221
- {'query' => '12345'}
222
- )
223
- method, uri, headers, body = request
224
- headers = headers.inject({}) { |h,(k,v)| h[k]=v; h }
225
- headers.keys.should include('Authorization')
226
- headers['Authorization'].should =~ /^OAuth/
227
- end
228
-
229
- it 'should not be able to execute improperly authorized requests' do
230
- @client.authorization = :oauth_1
231
- @client.authorization.token_credential_key = '12345'
232
- @client.authorization.token_credential_secret = '12345'
233
- response = @client.execute(
234
- 'prediction.training.insert',
235
- {'query' => '12345'}
236
- )
237
- status, headers, body = response
238
- status.should == 401
239
- end
240
-
241
56
  it 'should raise an error for bogus methods' do
242
57
  (lambda do
243
58
  @client.generate_request(42)
244
59
  end).should raise_error(TypeError)
245
60
  end
246
61
 
247
- it 'should raise an error for bogus methods' do
248
- (lambda do
249
- @client.generate_request(@client.discovered_service('prediction'))
250
- end).should raise_error(TypeError)
251
- end
252
- end
253
-
254
- describe Google::APIClient, 'configured for the buzz API' do
255
- before do
256
- @client = Google::APIClient.new(:service => 'buzz')
257
- end
258
-
259
- it 'should correctly determine the discovery URI' do
260
- @client.discovery_uri.should ===
261
- 'http://www.googleapis.com/discovery/0.1/describe?api=buzz'
262
- end
263
-
264
- it 'should find APIs that are in the discovery document' do
265
- @client.discovered_service('buzz').name.should == 'buzz'
266
- @client.discovered_service('buzz').version.should == 'v1'
267
- end
268
-
269
- it 'should not find APIs that are not in the discovery document' do
270
- @client.discovered_service('bogus').should == nil
271
- end
272
-
273
- it 'should find methods that are in the discovery document' do
274
- # TODO(bobaman) Fix this when the RPC names are correct
275
- @client.discovered_method('chili.activities.list').name.should == 'list'
276
- end
277
-
278
- it 'should not find methods that are not in the discovery document' do
279
- @client.discovered_method('buzz.bogus').should == nil
280
- end
281
-
282
- it 'should generate requests against the correct URIs' do
283
- # TODO(bobaman) Fix this when the RPC names are correct
284
- request = @client.generate_request(
285
- 'chili.activities.list',
286
- {'userId' => 'hikingfan', 'scope' => '@public'},
287
- '',
288
- [],
289
- {:signed => false}
290
- )
291
- method, uri, headers, body = request
292
- uri.should ==
293
- 'https://www.googleapis.com/buzz/v1/activities/hikingfan/@public'
294
- end
295
-
296
- it 'should correctly validate parameters' do
297
- # TODO(bobaman) Fix this when the RPC names are correct
298
- (lambda do
299
- @client.generate_request(
300
- 'chili.activities.list',
301
- {'alt' => 'json'},
62
+ it 'should not return a preferred version for bogus service names' do
63
+ @client.preferred_version('bogus').should == nil
64
+ end
65
+
66
+ describe 'with the prediction API' do
67
+ before do
68
+ @client.authorization = nil
69
+ end
70
+
71
+ it 'should correctly determine the discovery URI' do
72
+ @client.discovery_uri('prediction').should ===
73
+ 'https://www.googleapis.com/discovery/v1/apis/prediction/v1/rest'
74
+ end
75
+
76
+ it 'should correctly generate API objects' do
77
+ @client.discovered_api('prediction').name.should == 'prediction'
78
+ @client.discovered_api('prediction').version.should == 'v1'
79
+ @client.discovered_api(:prediction).name.should == 'prediction'
80
+ @client.discovered_api(:prediction).version.should == 'v1'
81
+ end
82
+
83
+ it 'should discover methods' do
84
+ @client.discovered_method(
85
+ 'prediction.training.insert', 'prediction'
86
+ ).name.should == 'insert'
87
+ @client.discovered_method(
88
+ :'prediction.training.insert', :prediction
89
+ ).name.should == 'insert'
90
+ end
91
+
92
+ it 'should discover methods' do
93
+ @client.discovered_method(
94
+ 'prediction.training.delete', 'prediction', 'v1.1'
95
+ ).name.should == 'delete'
96
+ end
97
+
98
+ it 'should not find methods that are not in the discovery document' do
99
+ @client.discovered_method(
100
+ 'prediction.training.delete', 'prediction', 'v1'
101
+ ).should == nil
102
+ @client.discovered_method(
103
+ 'prediction.bogus', 'prediction', 'v1'
104
+ ).should == nil
105
+ end
106
+
107
+ it 'should raise an error for bogus methods' do
108
+ (lambda do
109
+ @client.discovered_method(42, 'prediction', 'v1')
110
+ end).should raise_error(TypeError)
111
+ end
112
+
113
+ it 'should raise an error for bogus methods' do
114
+ (lambda do
115
+ @client.generate_request(@client.discovered_api('prediction'))
116
+ end).should raise_error(TypeError)
117
+ end
118
+
119
+ it 'should correctly determine the preferred version' do
120
+ @client.preferred_version('prediction').version.should_not == 'v1'
121
+ @client.preferred_version(:prediction).version.should_not == 'v1'
122
+ end
123
+
124
+ it 'should generate valid requests' do
125
+ request = @client.generate_request(
126
+ 'prediction.training.insert',
127
+ {'data' => '12345', }
128
+ )
129
+ method, uri, headers, body = request
130
+ method.should == 'POST'
131
+ uri.should ==
132
+ 'https://www.googleapis.com/prediction/v1/training?data=12345'
133
+ (headers.inject({}) { |h,(k,v)| h[k]=v; h }).should == {}
134
+ body.should respond_to(:each)
135
+ end
136
+
137
+ it 'should generate requests against the correct URIs' do
138
+ request = @client.generate_request(
139
+ :'prediction.training.insert',
140
+ {'data' => '12345'}
141
+ )
142
+ method, uri, headers, body = request
143
+ uri.should ==
144
+ 'https://www.googleapis.com/prediction/v1/training?data=12345'
145
+ end
146
+
147
+ it 'should generate requests against the correct URIs' do
148
+ prediction = @client.discovered_api('prediction', 'v1')
149
+ request = @client.generate_request(
150
+ prediction.training.insert,
151
+ {'data' => '12345'}
152
+ )
153
+ method, uri, headers, body = request
154
+ uri.should ==
155
+ 'https://www.googleapis.com/prediction/v1/training?data=12345'
156
+ end
157
+
158
+ it 'should allow modification to the base URIs for testing purposes' do
159
+ prediction = @client.discovered_api('prediction', 'v1')
160
+ prediction.method_base =
161
+ 'https://testing-domain.googleapis.com/prediction/v1/'
162
+ request = @client.generate_request(
163
+ prediction.training.insert,
164
+ {'data' => '123'}
165
+ )
166
+ method, uri, headers, body = request
167
+ uri.should ==
168
+ 'https://testing-domain.googleapis.com/prediction/v1/training?data=123'
169
+ end
170
+
171
+ it 'should generate OAuth 1 requests' do
172
+ @client.authorization = :oauth_1
173
+ @client.authorization.token_credential_key = '12345'
174
+ @client.authorization.token_credential_secret = '12345'
175
+ request = @client.generate_request(
176
+ 'prediction.training.insert',
177
+ {'data' => '12345'}
178
+ )
179
+ method, uri, headers, body = request
180
+ headers = headers.inject({}) { |h,(k,v)| h[k]=v; h }
181
+ headers.keys.should include('Authorization')
182
+ headers['Authorization'].should =~ /^OAuth/
183
+ end
184
+
185
+ it 'should generate OAuth 2 requests' do
186
+ @client.authorization = :oauth_2
187
+ @client.authorization.access_token = '12345'
188
+ request = @client.generate_request(
189
+ 'prediction.training.insert',
190
+ {'data' => '12345'}
191
+ )
192
+ method, uri, headers, body = request
193
+ headers = headers.inject({}) { |h,(k,v)| h[k]=v; h }
194
+ headers.keys.should include('Authorization')
195
+ headers['Authorization'].should =~ /^OAuth/
196
+ end
197
+
198
+ it 'should not be able to execute improperly authorized requests' do
199
+ @client.authorization = :oauth_1
200
+ @client.authorization.token_credential_key = '12345'
201
+ @client.authorization.token_credential_secret = '12345'
202
+ response = @client.execute(
203
+ 'prediction.training.insert',
204
+ {'data' => '12345'}
205
+ )
206
+ status, headers, body = response
207
+ status.should == 401
208
+ end
209
+
210
+ it 'should not be able to execute improperly authorized requests' do
211
+ @client.authorization = :oauth_2
212
+ @client.authorization.access_token = '12345'
213
+ response = @client.execute(
214
+ 'prediction.training.insert',
215
+ {'data' => '12345'}
216
+ )
217
+ status, headers, body = response
218
+ status.should == 401
219
+ end
220
+ end
221
+
222
+ describe 'with the buzz API' do
223
+ before do
224
+ @client.authorization = nil
225
+ @buzz = @client.discovered_api('buzz')
226
+ end
227
+
228
+ it 'should correctly determine the discovery URI' do
229
+ @client.discovery_uri('buzz').should ===
230
+ 'https://www.googleapis.com/discovery/v1/apis/buzz/v1/rest'
231
+ end
232
+
233
+ it 'should find APIs that are in the discovery document' do
234
+ @client.discovered_api('buzz').name.should == 'buzz'
235
+ @client.discovered_api('buzz').version.should == 'v1'
236
+ @client.discovered_api(:buzz).name.should == 'buzz'
237
+ @client.discovered_api(:buzz).version.should == 'v1'
238
+ end
239
+
240
+ it 'should find methods that are in the discovery document' do
241
+ # TODO(bobaman) Fix this when the RPC names are correct
242
+ @client.discovered_method(
243
+ 'chili.activities.list', 'buzz'
244
+ ).name.should == 'list'
245
+ end
246
+
247
+ it 'should not find methods that are not in the discovery document' do
248
+ @client.discovered_method('buzz.bogus', 'buzz').should == nil
249
+ end
250
+
251
+ it 'should fail for string RPC names that do not match API name' do
252
+ (lambda do
253
+ @client.generate_request(
254
+ 'chili.activities.list',
255
+ {'alt' => 'json'},
256
+ '',
257
+ [],
258
+ {:signed => false}
259
+ )
260
+ end).should raise_error(Google::APIClient::TransmissionError)
261
+ end
262
+
263
+ it 'should generate requests against the correct URIs' do
264
+ request = @client.generate_request(
265
+ @buzz.activities.list,
266
+ {'userId' => 'hikingfan', 'scope' => '@public'},
302
267
  '',
303
268
  [],
304
269
  {:signed => false}
305
270
  )
306
- end).should raise_error(ArgumentError)
307
- end
308
-
309
- it 'should correctly validate parameters' do
310
- # TODO(bobaman) Fix this when the RPC names are correct
311
- (lambda do
312
- @client.generate_request(
313
- 'chili.activities.list',
314
- {'userId' => 'hikingfan', 'scope' => '@bogus'},
271
+ method, uri, headers, body = request
272
+ uri.should ==
273
+ 'https://www.googleapis.com/buzz/v1/activities/hikingfan/@public'
274
+ end
275
+
276
+ it 'should correctly validate parameters' do
277
+ (lambda do
278
+ @client.generate_request(
279
+ @buzz.activities.list,
280
+ {'alt' => 'json'},
281
+ '',
282
+ [],
283
+ {:signed => false}
284
+ )
285
+ end).should raise_error(ArgumentError)
286
+ end
287
+
288
+ it 'should correctly validate parameters' do
289
+ (lambda do
290
+ @client.generate_request(
291
+ @buzz.activities.list,
292
+ {'userId' => 'hikingfan', 'scope' => '@bogus'},
293
+ '',
294
+ [],
295
+ {:signed => false}
296
+ )
297
+ end).should raise_error(ArgumentError)
298
+ end
299
+
300
+ it 'should be able to execute requests without authorization' do
301
+ response = @client.execute(
302
+ @buzz.activities.list,
303
+ {'alt' => 'json', 'userId' => 'hikingfan', 'scope' => '@public'},
315
304
  '',
316
305
  [],
317
306
  {:signed => false}
318
307
  )
319
- end).should raise_error(ArgumentError)
320
- end
321
-
322
- it 'should be able to execute requests without authorization' do
323
- # TODO(bobaman) Fix this when the RPC names are correct
324
- response = @client.execute(
325
- 'chili.activities.list',
326
- {'alt' => 'json', 'userId' => 'hikingfan', 'scope' => '@public'},
327
- '',
328
- [],
329
- {:signed => false}
330
- )
331
- status, headers, body = response
332
- status.should == 200
333
- end
334
- end
335
-
336
- describe Google::APIClient, 'configured for the latitude API' do
337
- before do
338
- @client = Google::APIClient.new(:service => 'latitude')
339
- end
340
-
341
- it 'should correctly determine the discovery URI' do
342
- @client.discovery_uri.should ===
343
- 'http://www.googleapis.com/discovery/0.1/describe?api=latitude'
344
- end
345
-
346
- it 'should find APIs that are in the discovery document' do
347
- @client.discovered_service('latitude').name.should == 'latitude'
348
- @client.discovered_service('latitude').version.should == 'v1'
349
- end
350
-
351
- it 'should not find APIs that are not in the discovery document' do
352
- @client.discovered_service('bogus').should == nil
353
- end
354
-
355
- it 'should find methods that are in the discovery document' do
356
- @client.discovered_method('latitude.currentLocation.get').name.should ==
357
- 'get'
358
- end
359
-
360
- it 'should not find methods that are not in the discovery document' do
361
- @client.discovered_method('latitude.bogus').should == nil
362
- end
363
-
364
- it 'should generate requests against the correct URIs' do
365
- request = @client.generate_request(
366
- 'latitude.currentLocation.get',
367
- {},
368
- '',
369
- [],
370
- {:signed => false}
371
- )
372
- method, uri, headers, body = request
373
- uri.should ==
374
- 'https://www.googleapis.com/latitude/v1/currentLocation'
375
- end
376
-
377
- it 'should not be able to execute requests without authorization' do
378
- response = @client.execute(
379
- 'latitude.currentLocation.get',
380
- {},
381
- '',
382
- [],
383
- {:signed => false}
384
- )
385
- status, headers, body = response
386
- status.should == 401
387
- end
388
- end
389
-
390
- describe Google::APIClient, 'configured for the moderator API' do
391
- before do
392
- @client = Google::APIClient.new(:service => 'moderator')
393
- end
394
-
395
- it 'should correctly determine the discovery URI' do
396
- @client.discovery_uri.should ===
397
- 'http://www.googleapis.com/discovery/0.1/describe?api=moderator'
398
- end
399
-
400
- it 'should find APIs that are in the discovery document' do
401
- @client.discovered_service('moderator').name.should == 'moderator'
402
- @client.discovered_service('moderator').version.should == 'v1'
403
- end
404
-
405
- it 'should not find APIs that are not in the discovery document' do
406
- @client.discovered_service('bogus').should == nil
407
- end
408
-
409
- it 'should find methods that are in the discovery document' do
410
- @client.discovered_method('moderator.profiles.get').name.should ==
411
- 'get'
412
- end
413
-
414
- it 'should not find methods that are not in the discovery document' do
415
- @client.discovered_method('moderator.bogus').should == nil
416
- end
417
-
418
- it 'should generate requests against the correct URIs' do
419
- request = @client.generate_request(
420
- 'moderator.profiles.get',
421
- {},
422
- '',
423
- [],
424
- {:signed => false}
425
- )
426
- method, uri, headers, body = request
427
- uri.should ==
428
- 'https://www.googleapis.com/moderator/v1/profiles/@me'
429
- end
430
-
431
- it 'should not be able to execute requests without authorization' do
432
- response = @client.execute(
433
- 'moderator.profiles.get',
434
- {},
435
- '',
436
- [],
437
- {:signed => false}
438
- )
439
- status, headers, body = response
440
- status.should == 401
308
+ status, headers, body = response
309
+ status.should == 200
310
+ end
311
+ end
312
+
313
+ describe 'with the latitude API' do
314
+ before do
315
+ @client.authorization = nil
316
+ @latitude = @client.discovered_api('latitude')
317
+ end
318
+
319
+ it 'should correctly determine the discovery URI' do
320
+ @client.discovery_uri('latitude').should ===
321
+ 'https://www.googleapis.com/discovery/v1/apis/latitude/v1/rest'
322
+ end
323
+
324
+ it 'should find APIs that are in the discovery document' do
325
+ @client.discovered_api('latitude').name.should == 'latitude'
326
+ @client.discovered_api('latitude').version.should == 'v1'
327
+ end
328
+
329
+ it 'should find methods that are in the discovery document' do
330
+ @client.discovered_method(
331
+ 'latitude.currentLocation.get', 'latitude'
332
+ ).name.should == 'get'
333
+ end
334
+
335
+ it 'should not find methods that are not in the discovery document' do
336
+ @client.discovered_method('latitude.bogus', 'latitude').should == nil
337
+ end
338
+
339
+ it 'should generate requests against the correct URIs' do
340
+ request = @client.generate_request(
341
+ 'latitude.currentLocation.get',
342
+ {},
343
+ '',
344
+ [],
345
+ {:signed => false}
346
+ )
347
+ method, uri, headers, body = request
348
+ uri.should ==
349
+ 'https://www.googleapis.com/latitude/v1/currentLocation'
350
+ end
351
+
352
+ it 'should generate requests against the correct URIs' do
353
+ request = @client.generate_request(
354
+ @latitude.current_location.get,
355
+ {},
356
+ '',
357
+ [],
358
+ {:signed => false}
359
+ )
360
+ method, uri, headers, body = request
361
+ uri.should ==
362
+ 'https://www.googleapis.com/latitude/v1/currentLocation'
363
+ end
364
+
365
+ it 'should not be able to execute requests without authorization' do
366
+ response = @client.execute(
367
+ 'latitude.currentLocation.get',
368
+ {},
369
+ '',
370
+ [],
371
+ {:signed => false}
372
+ )
373
+ status, headers, body = response
374
+ status.should == 401
375
+ end
376
+ end
377
+
378
+ describe 'with the moderator API' do
379
+ before do
380
+ @client.authorization = nil
381
+ @moderator = @client.discovered_api('moderator')
382
+ end
383
+
384
+ it 'should correctly determine the discovery URI' do
385
+ @client.discovery_uri('moderator').should ===
386
+ 'https://www.googleapis.com/discovery/v1/apis/moderator/v1/rest'
387
+ end
388
+
389
+ it 'should find APIs that are in the discovery document' do
390
+ @client.discovered_api('moderator').name.should == 'moderator'
391
+ @client.discovered_api('moderator').version.should == 'v1'
392
+ end
393
+
394
+ it 'should find methods that are in the discovery document' do
395
+ @client.discovered_method(
396
+ 'moderator.profiles.get', 'moderator'
397
+ ).name.should == 'get'
398
+ end
399
+
400
+ it 'should not find methods that are not in the discovery document' do
401
+ @client.discovered_method('moderator.bogus', 'moderator').should == nil
402
+ end
403
+
404
+ it 'should generate requests against the correct URIs' do
405
+ request = @client.generate_request(
406
+ 'moderator.profiles.get',
407
+ {},
408
+ '',
409
+ [],
410
+ {:signed => false}
411
+ )
412
+ method, uri, headers, body = request
413
+ uri.should ==
414
+ 'https://www.googleapis.com/moderator/v1/profiles/@me'
415
+ end
416
+
417
+ it 'should generate requests against the correct URIs' do
418
+ request = @client.generate_request(
419
+ @moderator.profiles.get,
420
+ {},
421
+ '',
422
+ [],
423
+ {:signed => false}
424
+ )
425
+ method, uri, headers, body = request
426
+ uri.should ==
427
+ 'https://www.googleapis.com/moderator/v1/profiles/@me'
428
+ end
429
+
430
+ it 'should not be able to execute requests without authorization' do
431
+ response = @client.execute(
432
+ 'moderator.profiles.get',
433
+ {},
434
+ '',
435
+ [],
436
+ {:signed => false}
437
+ )
438
+ status, headers, body = response
439
+ status.should == 401
440
+ end
441
441
  end
442
442
  end