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.
- data/CHANGELOG +8 -0
- data/README +1 -1
- data/bin/google-api +174 -120
- data/lib/google/api_client.rb +333 -135
- data/lib/google/api_client/discovery.rb +106 -108
- data/lib/google/api_client/environment.rb +13 -0
- data/lib/google/api_client/errors.rb +30 -0
- data/lib/google/api_client/parsers/json_parser.rb +1 -0
- data/lib/google/api_client/version.rb +3 -2
- data/lib/google/inflection.rb +23 -0
- data/spec/google/api_client/discovery_spec.rb +381 -381
- data/spec/google/api_client_spec.rb +78 -28
- data/tasks/gem.rake +4 -6
- metadata +32 -60
@@ -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,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 =
|
20
|
-
TINY =
|
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
|
24
|
+
describe Google::APIClient do
|
25
25
|
before do
|
26
26
|
@client = Google::APIClient.new
|
27
27
|
end
|
28
28
|
|
29
|
-
it 'should
|
29
|
+
it 'should raise a type error for bogus authorization' do
|
30
30
|
(lambda do
|
31
|
-
|
32
|
-
end).should raise_error(
|
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
|
-
|
52
|
-
end).should raise_error(
|
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.
|
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.
|
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
|
248
|
-
(
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
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
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
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
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
''
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
end
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
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
|