google-api-client 0.4.4 → 0.4.5

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.
@@ -53,6 +53,28 @@ module Google
53
53
  content_type[/^([^;]*);?.*$/, 1].strip.downcase
54
54
  end
55
55
 
56
+ def error?
57
+ return self.response.status >= 400
58
+ end
59
+
60
+ def success?
61
+ return !self.error?
62
+ end
63
+
64
+ def error_message
65
+ if self.data?
66
+ if self.data.respond_to?(:error) &&
67
+ self.data.error.respond_to?(:message)
68
+ # You're going to get a terrible error message if the response isn't
69
+ # parsed successfully as an error.
70
+ return self.data.error.message
71
+ elsif self.data['error'] && self.data['error']['message']
72
+ return self.data['error']['message']
73
+ end
74
+ end
75
+ return self.body
76
+ end
77
+
56
78
  def data?
57
79
  self.media_type == 'application/json'
58
80
  end
@@ -22,7 +22,7 @@ if !defined?(::Google::APIClient::VERSION)
22
22
  module VERSION
23
23
  MAJOR = 0
24
24
  MINOR = 4
25
- TINY = 4
25
+ TINY = 5
26
26
 
27
27
  STRING = [MAJOR, MINOR, TINY].join('.')
28
28
  end
@@ -18,22 +18,26 @@ require 'google/api_client'
18
18
  require 'google/api_client/version'
19
19
 
20
20
  describe Google::APIClient::BatchRequest do
21
- before do
22
- @client = Google::APIClient.new
21
+ CLIENT ||= Google::APIClient.new
22
+
23
+ after do
24
+ # Reset client to not-quite-pristine state
25
+ CLIENT.key = nil
26
+ CLIENT.user_ip = nil
23
27
  end
24
28
 
25
29
  it 'should raise an error if making an empty batch request' do
26
30
  batch = Google::APIClient::BatchRequest.new
27
31
 
28
32
  (lambda do
29
- @client.execute(batch)
33
+ CLIENT.execute(batch)
30
34
  end).should raise_error(Google::APIClient::BatchError)
31
35
  end
32
36
 
33
37
  describe 'with the discovery API' do
34
38
  before do
35
- @client.authorization = nil
36
- @discovery = @client.discovered_api('discovery', 'v1')
39
+ CLIENT.authorization = nil
40
+ @discovery = CLIENT.discovered_api('discovery', 'v1')
37
41
  end
38
42
 
39
43
  describe 'with two valid requests' do
@@ -69,7 +73,7 @@ describe Google::APIClient::BatchRequest do
69
73
  batch.add(@call1, ids[0])
70
74
  batch.add(@call2, ids[1])
71
75
 
72
- @client.execute(batch)
76
+ CLIENT.execute(batch)
73
77
  block_called.should == 2
74
78
  end
75
79
 
@@ -86,7 +90,7 @@ describe Google::APIClient::BatchRequest do
86
90
  result.status.should == 200
87
91
  end
88
92
 
89
- @client.execute(batch)
93
+ CLIENT.execute(batch)
90
94
  call1_returned.should == true
91
95
  call2_returned.should == true
92
96
  end
@@ -139,7 +143,7 @@ describe Google::APIClient::BatchRequest do
139
143
  batch.add(@call1, ids[0])
140
144
  batch.add(@call2, ids[1])
141
145
 
142
- @client.execute(batch)
146
+ CLIENT.execute(batch)
143
147
  block_called.should == 2
144
148
  end
145
149
 
@@ -157,7 +161,7 @@ describe Google::APIClient::BatchRequest do
157
161
  result.status.should < 500
158
162
  end
159
163
 
160
- @client.execute(batch)
164
+ CLIENT.execute(batch)
161
165
  call1_returned.should == true
162
166
  call2_returned.should == true
163
167
  end
@@ -166,8 +170,8 @@ describe Google::APIClient::BatchRequest do
166
170
 
167
171
  describe 'with the calendar API' do
168
172
  before do
169
- @client.authorization = nil
170
- @calendar = @client.discovered_api('calendar', 'v3')
173
+ CLIENT.authorization = nil
174
+ @calendar = CLIENT.discovered_api('calendar', 'v3')
171
175
  end
172
176
 
173
177
  describe 'with two valid requests' do
@@ -207,14 +211,14 @@ describe Google::APIClient::BatchRequest do
207
211
  @call1 = {
208
212
  :api_method => @calendar.events.insert,
209
213
  :parameters => {'calendarId' => 'myemail@mydomain.tld'},
210
- :body => JSON.dump(event1),
214
+ :body => MultiJson.dump(event1),
211
215
  :headers => {'Content-Type' => 'application/json'}
212
216
  }
213
217
 
214
218
  @call2 = {
215
219
  :api_method => @calendar.events.insert,
216
220
  :parameters => {'calendarId' => 'myemail@mydomain.tld'},
217
- :body => JSON.dump(event2),
221
+ :body => MultiJson.dump(event2),
218
222
  :headers => {'Content-Type' => 'application/json'}
219
223
  }
220
224
  end
@@ -17,20 +17,24 @@
17
17
 
18
18
  require 'spec_helper'
19
19
 
20
- gem 'faraday', '~> 0.7.0'
20
+ gem 'faraday', '~> 0.8.1'
21
21
  require 'faraday'
22
22
  require 'faraday/utils'
23
23
  require 'multi_json'
24
24
 
25
- gem 'signet', '~> 0.3.0'
25
+ gem 'signet', '~> 0.4.0'
26
26
  require 'signet/oauth_1/client'
27
27
 
28
28
  require 'google/api_client'
29
29
  require 'google/api_client/version'
30
30
 
31
31
  describe Google::APIClient do
32
- before do
33
- @client = Google::APIClient.new
32
+ CLIENT ||= Google::APIClient.new
33
+
34
+ after do
35
+ # Reset client to not-quite-pristine state
36
+ CLIENT.key = nil
37
+ CLIENT.user_ip = nil
34
38
  end
35
39
 
36
40
  it 'should raise a type error for bogus authorization' do
@@ -41,199 +45,203 @@ describe Google::APIClient do
41
45
 
42
46
  it 'should not be able to retrieve the discovery document for a bogus API' do
43
47
  (lambda do
44
- @client.discovery_document('bogus')
48
+ CLIENT.discovery_document('bogus')
45
49
  end).should raise_error(Google::APIClient::TransmissionError)
46
50
  (lambda do
47
- @client.discovered_api('bogus')
51
+ CLIENT.discovered_api('bogus')
48
52
  end).should raise_error(Google::APIClient::TransmissionError)
49
53
  end
50
54
 
51
55
  it 'should raise an error for bogus services' do
52
56
  (lambda do
53
- @client.discovered_api(42)
57
+ CLIENT.discovered_api(42)
54
58
  end).should raise_error(TypeError)
55
59
  end
56
60
 
57
61
  it 'should raise an error for bogus services' do
58
62
  (lambda do
59
- @client.preferred_version(42)
63
+ CLIENT.preferred_version(42)
60
64
  end).should raise_error(TypeError)
61
65
  end
62
66
 
63
67
  it 'should raise an error for bogus methods' do
64
68
  (lambda do
65
- @client.generate_request(42)
69
+ CLIENT.generate_request(42)
66
70
  end).should raise_error(TypeError)
67
71
  end
68
72
 
69
73
  it 'should not return a preferred version for bogus service names' do
70
- @client.preferred_version('bogus').should == nil
74
+ CLIENT.preferred_version('bogus').should == nil
71
75
  end
72
76
 
73
77
  describe 'with the prediction API' do
74
78
  before do
75
- @client.authorization = nil
79
+ CLIENT.authorization = nil
76
80
  # The prediction API no longer exposes a v1, so we have to be
77
81
  # careful about looking up the wrong API version.
78
- @prediction = @client.discovered_api('prediction', 'v1.2')
82
+ @prediction = CLIENT.discovered_api('prediction', 'v1.2')
79
83
  end
80
84
 
81
85
  it 'should correctly determine the discovery URI' do
82
- @client.discovery_uri('prediction').should ===
86
+ CLIENT.discovery_uri('prediction').should ===
83
87
  'https://www.googleapis.com/discovery/v1/apis/prediction/v1/rest'
84
88
  end
85
89
 
86
90
  it 'should correctly determine the discovery URI if :user_ip is set' do
87
- @client.user_ip = '127.0.0.1'
88
- request = @client.generate_request(
91
+ CLIENT.user_ip = '127.0.0.1'
92
+ request = CLIENT.generate_request(
89
93
  :http_method => 'GET',
90
- :uri => @client.discovery_uri('prediction', 'v1.2'),
94
+ :uri => CLIENT.discovery_uri('prediction', 'v1.2'),
91
95
  :authenticated => false
92
96
  )
93
- request.to_env(Faraday.default_connection)[:url].should === (
97
+ request.to_env(Faraday.default_connection)[:url].to_s.should === (
94
98
  'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
95
99
  '?userIp=127.0.0.1'
96
100
  )
97
101
  end
98
102
 
99
103
  it 'should correctly determine the discovery URI if :key is set' do
100
- @client.key = 'qwerty'
101
- request = @client.generate_request(
104
+ CLIENT.key = 'qwerty'
105
+ request = CLIENT.generate_request(
102
106
  :http_method => 'GET',
103
- :uri => @client.discovery_uri('prediction', 'v1.2'),
107
+ :uri => CLIENT.discovery_uri('prediction', 'v1.2'),
104
108
  :authenticated => false
105
109
  )
106
- request.to_env(Faraday.default_connection)[:url].should === (
110
+ request.to_env(Faraday.default_connection)[:url].to_s.should === (
107
111
  'https://www.googleapis.com/discovery/v1/apis/prediction/v1.2/rest' +
108
112
  '?key=qwerty'
109
113
  )
110
114
  end
111
115
 
112
116
  it 'should correctly determine the discovery URI if both are set' do
113
- @client.key = 'qwerty'
114
- @client.user_ip = '127.0.0.1'
115
- request = @client.generate_request(
117
+ CLIENT.key = 'qwerty'
118
+ CLIENT.user_ip = '127.0.0.1'
119
+ request = CLIENT.generate_request(
116
120
  :http_method => 'GET',
117
- :uri => @client.discovery_uri('prediction', 'v1.2'),
121
+ :uri => CLIENT.discovery_uri('prediction', 'v1.2'),
118
122
  :authenticated => false
119
123
  )
120
- request.to_env(Faraday.default_connection)[:url].query_values.should == {
124
+ Addressable::URI.parse(
125
+ request.to_env(Faraday.default_connection)[:url]
126
+ ).query_values.should == {
121
127
  'key' => 'qwerty',
122
128
  'userIp' => '127.0.0.1'
123
129
  }
124
130
  end
125
131
 
126
132
  it 'should correctly generate API objects' do
127
- @client.discovered_api('prediction', 'v1.2').name.should == 'prediction'
128
- @client.discovered_api('prediction', 'v1.2').version.should == 'v1.2'
129
- @client.discovered_api(:prediction, 'v1.2').name.should == 'prediction'
130
- @client.discovered_api(:prediction, 'v1.2').version.should == 'v1.2'
133
+ CLIENT.discovered_api('prediction', 'v1.2').name.should == 'prediction'
134
+ CLIENT.discovered_api('prediction', 'v1.2').version.should == 'v1.2'
135
+ CLIENT.discovered_api(:prediction, 'v1.2').name.should == 'prediction'
136
+ CLIENT.discovered_api(:prediction, 'v1.2').version.should == 'v1.2'
131
137
  end
132
138
 
133
139
  it 'should discover methods' do
134
- @client.discovered_method(
140
+ CLIENT.discovered_method(
135
141
  'prediction.training.insert', 'prediction', 'v1.2'
136
142
  ).name.should == 'insert'
137
- @client.discovered_method(
143
+ CLIENT.discovered_method(
138
144
  :'prediction.training.insert', :prediction, 'v1.2'
139
145
  ).name.should == 'insert'
140
- @client.discovered_method(
146
+ CLIENT.discovered_method(
141
147
  'prediction.training.delete', 'prediction', 'v1.2'
142
148
  ).name.should == 'delete'
143
149
  end
144
150
 
145
151
  it 'should define the origin API in discovered methods' do
146
- @client.discovered_method(
152
+ CLIENT.discovered_method(
147
153
  'prediction.training.insert', 'prediction', 'v1.2'
148
154
  ).api.name.should == 'prediction'
149
155
  end
150
156
 
151
157
  it 'should not find methods that are not in the discovery document' do
152
- @client.discovered_method(
158
+ CLIENT.discovered_method(
153
159
  'prediction.bogus', 'prediction', 'v1.2'
154
160
  ).should == nil
155
161
  end
156
162
 
157
163
  it 'should raise an error for bogus methods' do
158
164
  (lambda do
159
- @client.discovered_method(42, 'prediction', 'v1.2')
165
+ CLIENT.discovered_method(42, 'prediction', 'v1.2')
160
166
  end).should raise_error(TypeError)
161
167
  end
162
168
 
163
169
  it 'should raise an error for bogus methods' do
164
170
  (lambda do
165
- @client.generate_request(@client.discovered_api('prediction', 'v1.2'))
171
+ CLIENT.generate_request(CLIENT.discovered_api('prediction', 'v1.2'))
166
172
  end).should raise_error(TypeError)
167
173
  end
168
174
 
169
175
  it 'should correctly determine the preferred version' do
170
- @client.preferred_version('prediction').version.should_not == 'v1'
171
- @client.preferred_version(:prediction).version.should_not == 'v1'
176
+ CLIENT.preferred_version('prediction').version.should_not == 'v1'
177
+ CLIENT.preferred_version(:prediction).version.should_not == 'v1'
172
178
  end
173
179
 
174
180
  it 'should return a batch path' do
175
- @client.discovered_api('prediction', 'v1.2').batch_path.should_not be_nil
181
+ CLIENT.discovered_api('prediction', 'v1.2').batch_path.should_not be_nil
176
182
  end
177
183
 
178
184
  it 'should generate valid requests' do
179
- request = @client.generate_request(
185
+ request = CLIENT.generate_request(
180
186
  :api_method => @prediction.training.insert,
181
- :parameters => {'data' => '12345', }
187
+ :parameters => {'data' => '12345'}
182
188
  )
183
189
  request.method.should == :post
184
- request.to_env(Faraday.default_connection)[:url].should ===
190
+ request.to_env(Faraday.default_connection)[:url].to_s.should ===
185
191
  'https://www.googleapis.com/prediction/v1.2/training?data=12345'
186
192
  request.headers.should be_empty
187
193
  request.body.should == ''
188
194
  end
189
195
 
190
196
  it 'should generate valid requests when repeated parameters are passed' do
191
- request = @client.generate_request(
197
+ request = CLIENT.generate_request(
192
198
  :api_method => @prediction.training.insert,
193
- :parameters => [['data', '1'],['data','2']]
199
+ :parameters => [['data', '1'], ['data','2']]
194
200
  )
195
201
  request.method.should == :post
196
- request.to_env(Faraday.default_connection)[:url].should ===
202
+ request.to_env(Faraday.default_connection)[:url].to_s.should ===
197
203
  'https://www.googleapis.com/prediction/v1.2/training?data=1&data=2'
198
204
  end
199
205
 
200
206
  it 'should generate requests against the correct URIs' do
201
- request = @client.generate_request(
207
+ request = CLIENT.generate_request(
202
208
  :api_method => @prediction.training.insert,
203
209
  :parameters => {'data' => '12345'}
204
210
  )
205
- request.to_env(Faraday.default_connection)[:url].should ===
211
+ request.to_env(Faraday.default_connection)[:url].to_s.should ===
206
212
  'https://www.googleapis.com/prediction/v1.2/training?data=12345'
207
213
  end
208
214
 
209
215
  it 'should generate requests against the correct URIs' do
210
- request = @client.generate_request(
216
+ request = CLIENT.generate_request(
211
217
  :api_method => @prediction.training.insert,
212
218
  :parameters => {'data' => '12345'}
213
219
  )
214
- request.to_env(Faraday.default_connection)[:url].should ===
220
+ request.to_env(Faraday.default_connection)[:url].to_s.should ===
215
221
  'https://www.googleapis.com/prediction/v1.2/training?data=12345'
216
222
  end
217
223
 
218
224
  it 'should allow modification to the base URIs for testing purposes' do
219
- prediction = @client.discovered_api('prediction', 'v1.2')
220
- prediction.method_base =
221
- 'https://testing-domain.googleapis.com/prediction/v1.2/'
222
- request = @client.generate_request(
223
- :api_method => prediction.training.insert,
225
+ # Using a new client instance here to avoid caching rebased discovery doc
226
+ prediction_rebase =
227
+ Google::APIClient.new.discovered_api('prediction', 'v1.2')
228
+ prediction_rebase.method_base =
229
+ 'https://testing-domain.example.com/prediction/v1.2/'
230
+ request = CLIENT.generate_request(
231
+ :api_method => prediction_rebase.training.insert,
224
232
  :parameters => {'data' => '123'}
225
233
  )
226
- request.to_env(Faraday.default_connection)[:url].should === (
227
- 'https://testing-domain.googleapis.com/' +
234
+ request.to_env(Faraday.default_connection)[:url].to_s.should === (
235
+ 'https://testing-domain.example.com/' +
228
236
  'prediction/v1.2/training?data=123'
229
237
  )
230
238
  end
231
239
 
232
240
  it 'should generate OAuth 1 requests' do
233
- @client.authorization = :oauth_1
234
- @client.authorization.token_credential_key = '12345'
235
- @client.authorization.token_credential_secret = '12345'
236
- request = @client.generate_request(
241
+ CLIENT.authorization = :oauth_1
242
+ CLIENT.authorization.token_credential_key = '12345'
243
+ CLIENT.authorization.token_credential_secret = '12345'
244
+ request = CLIENT.generate_request(
237
245
  :api_method => @prediction.training.insert,
238
246
  :parameters => {'data' => '12345'}
239
247
  )
@@ -242,9 +250,9 @@ describe Google::APIClient do
242
250
  end
243
251
 
244
252
  it 'should generate OAuth 2 requests' do
245
- @client.authorization = :oauth_2
246
- @client.authorization.access_token = '12345'
247
- request = @client.generate_request(
253
+ CLIENT.authorization = :oauth_2
254
+ CLIENT.authorization.access_token = '12345'
255
+ request = CLIENT.generate_request(
248
256
  :api_method => @prediction.training.insert,
249
257
  :parameters => {'data' => '12345'}
250
258
  )
@@ -253,10 +261,10 @@ describe Google::APIClient do
253
261
  end
254
262
 
255
263
  it 'should not be able to execute improperly authorized requests' do
256
- @client.authorization = :oauth_1
257
- @client.authorization.token_credential_key = '12345'
258
- @client.authorization.token_credential_secret = '12345'
259
- result = @client.execute(
264
+ CLIENT.authorization = :oauth_1
265
+ CLIENT.authorization.token_credential_key = '12345'
266
+ CLIENT.authorization.token_credential_secret = '12345'
267
+ result = CLIENT.execute(
260
268
  @prediction.training.insert,
261
269
  {'data' => '12345'}
262
270
  )
@@ -264,9 +272,9 @@ describe Google::APIClient do
264
272
  end
265
273
 
266
274
  it 'should not be able to execute improperly authorized requests' do
267
- @client.authorization = :oauth_2
268
- @client.authorization.access_token = '12345'
269
- result = @client.execute(
275
+ CLIENT.authorization = :oauth_2
276
+ CLIENT.authorization.access_token = '12345'
277
+ result = CLIENT.execute(
270
278
  @prediction.training.insert,
271
279
  {'data' => '12345'}
272
280
  )
@@ -275,10 +283,10 @@ describe Google::APIClient do
275
283
 
276
284
  it 'should not be able to execute improperly authorized requests' do
277
285
  (lambda do
278
- @client.authorization = :oauth_1
279
- @client.authorization.token_credential_key = '12345'
280
- @client.authorization.token_credential_secret = '12345'
281
- result = @client.execute!(
286
+ CLIENT.authorization = :oauth_1
287
+ CLIENT.authorization.token_credential_key = '12345'
288
+ CLIENT.authorization.token_credential_secret = '12345'
289
+ result = CLIENT.execute!(
282
290
  @prediction.training.insert,
283
291
  {'data' => '12345'}
284
292
  )
@@ -287,9 +295,9 @@ describe Google::APIClient do
287
295
 
288
296
  it 'should not be able to execute improperly authorized requests' do
289
297
  (lambda do
290
- @client.authorization = :oauth_2
291
- @client.authorization.access_token = '12345'
292
- result = @client.execute!(
298
+ CLIENT.authorization = :oauth_2
299
+ CLIENT.authorization.access_token = '12345'
300
+ result = CLIENT.execute!(
293
301
  @prediction.training.insert,
294
302
  {'data' => '12345'}
295
303
  )
@@ -297,9 +305,9 @@ describe Google::APIClient do
297
305
  end
298
306
 
299
307
  it 'should correctly handle unnamed parameters' do
300
- @client.authorization = :oauth_2
301
- @client.authorization.access_token = '12345'
302
- result = @client.execute(
308
+ CLIENT.authorization = :oauth_2
309
+ CLIENT.authorization.access_token = '12345'
310
+ result = CLIENT.execute(
303
311
  @prediction.training.insert,
304
312
  {},
305
313
  MultiJson.dump({"id" => "bucket/object"}),
@@ -311,48 +319,48 @@ describe Google::APIClient do
311
319
 
312
320
  describe 'with the plus API' do
313
321
  before do
314
- @client.authorization = nil
315
- @plus = @client.discovered_api('plus')
322
+ CLIENT.authorization = nil
323
+ @plus = CLIENT.discovered_api('plus')
316
324
  end
317
325
 
318
326
  it 'should correctly determine the discovery URI' do
319
- @client.discovery_uri('plus').should ===
327
+ CLIENT.discovery_uri('plus').should ===
320
328
  'https://www.googleapis.com/discovery/v1/apis/plus/v1/rest'
321
329
  end
322
330
 
323
331
  it 'should find APIs that are in the discovery document' do
324
- @client.discovered_api('plus').name.should == 'plus'
325
- @client.discovered_api('plus').version.should == 'v1'
326
- @client.discovered_api(:plus).name.should == 'plus'
327
- @client.discovered_api(:plus).version.should == 'v1'
332
+ CLIENT.discovered_api('plus').name.should == 'plus'
333
+ CLIENT.discovered_api('plus').version.should == 'v1'
334
+ CLIENT.discovered_api(:plus).name.should == 'plus'
335
+ CLIENT.discovered_api(:plus).version.should == 'v1'
328
336
  end
329
337
 
330
338
  it 'should find methods that are in the discovery document' do
331
339
  # TODO(bobaman) Fix this when the RPC names are correct
332
- @client.discovered_method(
340
+ CLIENT.discovered_method(
333
341
  'plus.activities.list', 'plus'
334
342
  ).name.should == 'list'
335
343
  end
336
344
 
337
345
  it 'should define the origin API in discovered methods' do
338
- @client.discovered_method(
346
+ CLIENT.discovered_method(
339
347
  'plus.activities.list', 'plus'
340
348
  ).api.name.should == 'plus'
341
349
  end
342
350
 
343
351
  it 'should not find methods that are not in the discovery document' do
344
- @client.discovered_method('plus.bogus', 'plus').should == nil
352
+ CLIENT.discovered_method('plus.bogus', 'plus').should == nil
345
353
  end
346
354
 
347
355
  it 'should generate requests against the correct URIs' do
348
- request = @client.generate_request(
356
+ request = CLIENT.generate_request(
349
357
  :api_method => @plus.activities.list,
350
358
  :parameters => {
351
359
  'userId' => '107807692475771887386', 'collection' => 'public'
352
360
  },
353
361
  :authenticated => false
354
362
  )
355
- request.to_env(Faraday.default_connection)[:url].should === (
363
+ request.to_env(Faraday.default_connection)[:url].to_s.should === (
356
364
  'https://www.googleapis.com/plus/v1/' +
357
365
  'people/107807692475771887386/activities/public'
358
366
  )
@@ -360,7 +368,7 @@ describe Google::APIClient do
360
368
 
361
369
  it 'should correctly validate parameters' do
362
370
  (lambda do
363
- @client.generate_request(
371
+ CLIENT.generate_request(
364
372
  :api_method => @plus.activities.list,
365
373
  :parameters => {'alt' => 'json'},
366
374
  :authenticated => false
@@ -370,7 +378,7 @@ describe Google::APIClient do
370
378
 
371
379
  it 'should correctly validate parameters' do
372
380
  (lambda do
373
- @client.generate_request(
381
+ CLIENT.generate_request(
374
382
  :api_method => @plus.activities.list,
375
383
  :parameters => {
376
384
  'userId' => '107807692475771887386', 'collection' => 'bogus'
@@ -383,60 +391,60 @@ describe Google::APIClient do
383
391
 
384
392
  describe 'with the latitude API' do
385
393
  before do
386
- @client.authorization = nil
387
- @latitude = @client.discovered_api('latitude')
394
+ CLIENT.authorization = nil
395
+ @latitude = CLIENT.discovered_api('latitude')
388
396
  end
389
397
 
390
398
  it 'should correctly determine the discovery URI' do
391
- @client.discovery_uri('latitude').should ===
399
+ CLIENT.discovery_uri('latitude').should ===
392
400
  'https://www.googleapis.com/discovery/v1/apis/latitude/v1/rest'
393
401
  end
394
402
 
395
403
  it 'should find APIs that are in the discovery document' do
396
- @client.discovered_api('latitude').name.should == 'latitude'
397
- @client.discovered_api('latitude').version.should == 'v1'
404
+ CLIENT.discovered_api('latitude').name.should == 'latitude'
405
+ CLIENT.discovered_api('latitude').version.should == 'v1'
398
406
  end
399
407
 
400
408
  it 'should return a batch path' do
401
- @client.discovered_api('latitude').batch_path.should_not be_nil
409
+ CLIENT.discovered_api('latitude').batch_path.should_not be_nil
402
410
  end
403
411
 
404
412
  it 'should find methods that are in the discovery document' do
405
- @client.discovered_method(
413
+ CLIENT.discovered_method(
406
414
  'latitude.currentLocation.get', 'latitude'
407
415
  ).name.should == 'get'
408
416
  end
409
417
 
410
418
  it 'should define the origin API in discovered methods' do
411
- @client.discovered_method(
419
+ CLIENT.discovered_method(
412
420
  'latitude.currentLocation.get', 'latitude'
413
421
  ).api.name.should == 'latitude'
414
422
  end
415
423
 
416
424
  it 'should not find methods that are not in the discovery document' do
417
- @client.discovered_method('latitude.bogus', 'latitude').should == nil
425
+ CLIENT.discovered_method('latitude.bogus', 'latitude').should == nil
418
426
  end
419
427
 
420
428
  it 'should generate requests against the correct URIs' do
421
- request = @client.generate_request(
429
+ request = CLIENT.generate_request(
422
430
  :api_method => 'latitude.currentLocation.get',
423
431
  :authenticated => false
424
432
  )
425
- request.to_env(Faraday.default_connection)[:url].should ===
433
+ request.to_env(Faraday.default_connection)[:url].to_s.should ===
426
434
  'https://www.googleapis.com/latitude/v1/currentLocation'
427
435
  end
428
436
 
429
437
  it 'should generate requests against the correct URIs' do
430
- request = @client.generate_request(
438
+ request = CLIENT.generate_request(
431
439
  :api_method => @latitude.current_location.get,
432
440
  :authenticated => false
433
441
  )
434
- request.to_env(Faraday.default_connection)[:url].should ===
442
+ request.to_env(Faraday.default_connection)[:url].to_s.should ===
435
443
  'https://www.googleapis.com/latitude/v1/currentLocation'
436
444
  end
437
445
 
438
446
  it 'should not be able to execute requests without authorization' do
439
- result = @client.execute(
447
+ result = CLIENT.execute(
440
448
  :api_method => 'latitude.currentLocation.get',
441
449
  :authenticated => false
442
450
  )
@@ -446,60 +454,60 @@ describe Google::APIClient do
446
454
 
447
455
  describe 'with the moderator API' do
448
456
  before do
449
- @client.authorization = nil
450
- @moderator = @client.discovered_api('moderator')
457
+ CLIENT.authorization = nil
458
+ @moderator = CLIENT.discovered_api('moderator')
451
459
  end
452
460
 
453
461
  it 'should correctly determine the discovery URI' do
454
- @client.discovery_uri('moderator').should ===
462
+ CLIENT.discovery_uri('moderator').should ===
455
463
  'https://www.googleapis.com/discovery/v1/apis/moderator/v1/rest'
456
464
  end
457
465
 
458
466
  it 'should find APIs that are in the discovery document' do
459
- @client.discovered_api('moderator').name.should == 'moderator'
460
- @client.discovered_api('moderator').version.should == 'v1'
467
+ CLIENT.discovered_api('moderator').name.should == 'moderator'
468
+ CLIENT.discovered_api('moderator').version.should == 'v1'
461
469
  end
462
470
 
463
471
  it 'should find methods that are in the discovery document' do
464
- @client.discovered_method(
472
+ CLIENT.discovered_method(
465
473
  'moderator.profiles.get', 'moderator'
466
474
  ).name.should == 'get'
467
475
  end
468
476
 
469
477
  it 'should define the origin API in discovered methods' do
470
- @client.discovered_method(
478
+ CLIENT.discovered_method(
471
479
  'moderator.profiles.get', 'moderator'
472
480
  ).api.name.should == 'moderator'
473
481
  end
474
482
 
475
483
  it 'should not find methods that are not in the discovery document' do
476
- @client.discovered_method('moderator.bogus', 'moderator').should == nil
484
+ CLIENT.discovered_method('moderator.bogus', 'moderator').should == nil
477
485
  end
478
486
 
479
487
  it 'should return a batch path' do
480
- @client.discovered_api('moderator').batch_path.should_not be_nil
488
+ CLIENT.discovered_api('moderator').batch_path.should_not be_nil
481
489
  end
482
490
 
483
491
  it 'should generate requests against the correct URIs' do
484
- request = @client.generate_request(
492
+ request = CLIENT.generate_request(
485
493
  :api_method => 'moderator.profiles.get',
486
494
  :authenticated => false
487
495
  )
488
- request.to_env(Faraday.default_connection)[:url].should ===
496
+ request.to_env(Faraday.default_connection)[:url].to_s.should ===
489
497
  'https://www.googleapis.com/moderator/v1/profiles/@me'
490
498
  end
491
499
 
492
500
  it 'should generate requests against the correct URIs' do
493
- request = @client.generate_request(
501
+ request = CLIENT.generate_request(
494
502
  :api_method => @moderator.profiles.get,
495
503
  :authenticated => false
496
504
  )
497
- request.to_env(Faraday.default_connection)[:url].should ===
505
+ request.to_env(Faraday.default_connection)[:url].to_s.should ===
498
506
  'https://www.googleapis.com/moderator/v1/profiles/@me'
499
507
  end
500
508
 
501
509
  it 'should not be able to execute requests without authorization' do
502
- result = @client.execute(
510
+ result = CLIENT.execute(
503
511
  'moderator.profiles.get',
504
512
  {},
505
513
  '',
@@ -512,54 +520,54 @@ describe Google::APIClient do
512
520
 
513
521
  describe 'with the adsense API' do
514
522
  before do
515
- @client.authorization = nil
516
- @adsense = @client.discovered_api('adsense', 'v1')
523
+ CLIENT.authorization = nil
524
+ @adsense = CLIENT.discovered_api('adsense', 'v1')
517
525
  end
518
526
 
519
527
  it 'should correctly determine the discovery URI' do
520
- @client.discovery_uri('adsense').should ===
528
+ CLIENT.discovery_uri('adsense').should ===
521
529
  'https://www.googleapis.com/discovery/v1/apis/adsense/v1/rest'
522
530
  end
523
531
 
524
532
  it 'should find APIs that are in the discovery document' do
525
- @client.discovered_api('adsense').name.should == 'adsense'
526
- @client.discovered_api('adsense').version.should == 'v1'
533
+ CLIENT.discovered_api('adsense').name.should == 'adsense'
534
+ CLIENT.discovered_api('adsense').version.should == 'v1'
527
535
  end
528
536
 
529
537
  it 'should return a batch path' do
530
- @client.discovered_api('adsense').batch_path.should_not be_nil
538
+ CLIENT.discovered_api('adsense').batch_path.should_not be_nil
531
539
  end
532
540
 
533
541
  it 'should find methods that are in the discovery document' do
534
- @client.discovered_method(
542
+ CLIENT.discovered_method(
535
543
  'adsense.reports.generate', 'adsense'
536
544
  ).name.should == 'generate'
537
545
  end
538
546
 
539
547
  it 'should not find methods that are not in the discovery document' do
540
- @client.discovered_method('adsense.bogus', 'adsense').should == nil
548
+ CLIENT.discovered_method('adsense.bogus', 'adsense').should == nil
541
549
  end
542
550
 
543
551
  it 'should generate requests against the correct URIs' do
544
- request = @client.generate_request(
552
+ request = CLIENT.generate_request(
545
553
  :api_method => 'adsense.adclients.list',
546
554
  :authenticated => false
547
555
  )
548
- request.to_env(Faraday.default_connection)[:url].should ===
556
+ request.to_env(Faraday.default_connection)[:url].to_s.should ===
549
557
  'https://www.googleapis.com/adsense/v1/adclients'
550
558
  end
551
559
 
552
560
  it 'should generate requests against the correct URIs' do
553
- request = @client.generate_request(
561
+ request = CLIENT.generate_request(
554
562
  :api_method => @adsense.adclients.list,
555
563
  :authenticated => false
556
564
  )
557
- request.to_env(Faraday.default_connection)[:url].should ===
565
+ request.to_env(Faraday.default_connection)[:url].to_s.should ===
558
566
  'https://www.googleapis.com/adsense/v1/adclients'
559
567
  end
560
568
 
561
569
  it 'should not be able to execute requests without authorization' do
562
- result = @client.execute(
570
+ result = CLIENT.execute(
563
571
  :api_method => 'adsense.adclients.list',
564
572
  :authenticated => false
565
573
  )
@@ -568,7 +576,7 @@ describe Google::APIClient do
568
576
 
569
577
  it 'should fail when validating missing required parameters' do
570
578
  (lambda do
571
- @client.generate_request(
579
+ CLIENT.generate_request(
572
580
  :api_method => @adsense.reports.generate,
573
581
  :authenticated => false
574
582
  )
@@ -577,7 +585,7 @@ describe Google::APIClient do
577
585
 
578
586
  it 'should succeed when validating parameters in a correct call' do
579
587
  (lambda do
580
- @client.generate_request(
588
+ CLIENT.generate_request(
581
589
  :api_method => @adsense.reports.generate,
582
590
  :parameters => {
583
591
  'startDate' => '2000-01-01',
@@ -592,7 +600,7 @@ describe Google::APIClient do
592
600
 
593
601
  it 'should fail when validating parameters with invalid values' do
594
602
  (lambda do
595
- @client.generate_request(
603
+ CLIENT.generate_request(
596
604
  :api_method => @adsense.reports.generate,
597
605
  :parameters => {
598
606
  'startDate' => '2000-01-01',
@@ -607,7 +615,7 @@ describe Google::APIClient do
607
615
 
608
616
  it 'should succeed when validating repeated parameters in a correct call' do
609
617
  (lambda do
610
- @client.generate_request(
618
+ CLIENT.generate_request(
611
619
  :api_method => @adsense.reports.generate,
612
620
  :parameters => {
613
621
  'startDate' => '2000-01-01',
@@ -622,7 +630,7 @@ describe Google::APIClient do
622
630
 
623
631
  it 'should fail when validating incorrect repeated parameters' do
624
632
  (lambda do
625
- @client.generate_request(
633
+ CLIENT.generate_request(
626
634
  :api_method => @adsense.reports.generate,
627
635
  :parameters => {
628
636
  'startDate' => '2000-01-01',
@@ -635,25 +643,25 @@ describe Google::APIClient do
635
643
  end).should raise_error(ArgumentError)
636
644
  end
637
645
  end
638
-
646
+
639
647
  describe 'with the Drive API' do
640
648
  before do
641
- @client.authorization = nil
642
- @drive = @client.discovered_api('drive', 'v1')
649
+ CLIENT.authorization = nil
650
+ @drive = CLIENT.discovered_api('drive', 'v1')
643
651
  end
644
-
652
+
645
653
  it 'should include media upload info methods' do
646
654
  @drive.files.insert.media_upload.should_not == nil
647
655
  end
648
-
656
+
649
657
  it 'should include accepted media types' do
650
658
  @drive.files.insert.media_upload.accepted_types.should_not be_empty
651
659
  end
652
-
660
+
653
661
  it 'should have an upload path' do
654
662
  @drive.files.insert.media_upload.uri_template.should_not == nil
655
663
  end
656
-
664
+
657
665
  it 'should have a max file size' do
658
666
  @drive.files.insert.media_upload.max_size.should_not == nil
659
667
  end