google-api-client 0.6.4 → 0.7.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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +14 -0
  3. data/Gemfile +13 -3
  4. data/README.md +133 -97
  5. data/Rakefile +1 -1
  6. data/lib/cacerts.pem +2183 -0
  7. data/lib/google/api_client/auth/compute_service_account.rb +28 -0
  8. data/lib/google/api_client/auth/file_storage.rb +87 -0
  9. data/lib/google/api_client/auth/installed_app.rb +8 -1
  10. data/lib/google/api_client/auth/jwt_asserter.rb +0 -11
  11. data/lib/google/api_client/client_secrets.rb +1 -1
  12. data/lib/google/api_client/discovery/method.rb +1 -0
  13. data/lib/google/api_client/errors.rb +11 -0
  14. data/lib/google/api_client/gzip.rb +28 -0
  15. data/lib/google/api_client/media.rb +80 -5
  16. data/lib/google/api_client/request.rb +15 -9
  17. data/lib/google/api_client/service/batch.rb +103 -0
  18. data/lib/google/api_client/service/request.rb +144 -0
  19. data/lib/google/api_client/service/resource.rb +40 -0
  20. data/lib/google/api_client/service/result.rb +162 -0
  21. data/lib/google/api_client/service/simple_file_store.rb +151 -0
  22. data/lib/google/api_client/service/stub_generator.rb +59 -0
  23. data/lib/google/api_client/service.rb +233 -0
  24. data/lib/google/api_client/service_account.rb +1 -0
  25. data/lib/google/api_client/version.rb +4 -3
  26. data/lib/google/api_client.rb +81 -42
  27. data/spec/google/api_client/batch_spec.rb +4 -4
  28. data/spec/google/api_client/discovery_spec.rb +60 -102
  29. data/spec/google/api_client/gzip_spec.rb +86 -0
  30. data/spec/google/api_client/media_spec.rb +49 -1
  31. data/spec/google/api_client/request_spec.rb +30 -0
  32. data/spec/google/api_client/result_spec.rb +3 -4
  33. data/spec/google/api_client/service_account_spec.rb +21 -0
  34. data/spec/google/api_client/service_spec.rb +586 -0
  35. data/spec/google/api_client/simple_file_store_spec.rb +137 -0
  36. data/spec/google/api_client_spec.rb +101 -3
  37. data/spec/spec_helper.rb +3 -0
  38. data/tasks/gem.rake +3 -4
  39. metadata +95 -50
  40. data/bin/google-api +0 -391
  41. /data/{CONTRIB.md → CONTRIBUTING.md} +0 -0
@@ -57,6 +57,54 @@ describe Google::APIClient::UploadIO do
57
57
  end
58
58
  end
59
59
 
60
+ describe Google::APIClient::RangedIO do
61
+ before do
62
+ @source = StringIO.new("1234567890abcdef")
63
+ @io = Google::APIClient::RangedIO.new(@source, 1, 5)
64
+ end
65
+
66
+ it 'should return the correct range when read entirely' do
67
+ @io.read.should == "23456"
68
+ end
69
+
70
+ it 'should maintain position' do
71
+ @io.read(1).should == '2'
72
+ @io.read(2).should == '34'
73
+ @io.read(2).should == '56'
74
+ end
75
+
76
+ it 'should allow rewinds' do
77
+ @io.read(2).should == '23'
78
+ @io.rewind()
79
+ @io.read(2).should == '23'
80
+ end
81
+
82
+ it 'should allow setting position' do
83
+ @io.pos = 3
84
+ @io.read.should == '56'
85
+ end
86
+
87
+ it 'should not allow position to be set beyond range' do
88
+ @io.pos = 10
89
+ @io.read.should == ''
90
+ end
91
+
92
+ it 'should return empty string when read amount is zero' do
93
+ @io.read(0).should == ''
94
+ end
95
+
96
+ it 'should return empty string at EOF if amount is nil' do
97
+ @io.read
98
+ @io.read.should == ''
99
+ end
100
+
101
+ it 'should return nil at EOF if amount is positive int' do
102
+ @io.read
103
+ @io.read(1).should == nil
104
+ end
105
+
106
+ end
107
+
60
108
  describe Google::APIClient::ResumableUpload do
61
109
  CLIENT = Google::APIClient.new(:application_name => 'API Client Tests') unless defined?(CLIENT)
62
110
 
@@ -125,7 +173,7 @@ describe Google::APIClient::ResumableUpload do
125
173
 
126
174
  def mock_result(status, headers = {})
127
175
  reference = Google::APIClient::Reference.new(:api_method => @drive.files.insert)
128
- stub('result', :status => status, :headers => headers, :reference => reference)
176
+ double('result', :status => status, :headers => headers, :reference => reference)
129
177
  end
130
178
 
131
179
  end
@@ -0,0 +1,30 @@
1
+ # Copyright 2012 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
+ require 'spec_helper'
16
+
17
+ require 'google/api_client'
18
+ require 'google/api_client/version'
19
+
20
+ describe Google::APIClient::Request do
21
+ CLIENT = Google::APIClient.new(:application_name => 'API Client Tests') unless defined?(CLIENT)
22
+
23
+ it 'should normalize parameter names to strings' do
24
+ request = Google::APIClient::Request.new(:uri => 'https://www.google.com', :parameters => {
25
+ :a => '1', 'b' => '2'
26
+ })
27
+ request.parameters['a'].should == '1'
28
+ request.parameters['b'].should == '2'
29
+ end
30
+ end
@@ -34,8 +34,8 @@ describe Google::APIClient::Result do
34
34
  })
35
35
  @request = @reference.to_http_request
36
36
 
37
- # Response stub
38
- @response = stub("response")
37
+ # Response double
38
+ @response = double("response")
39
39
  @response.stub(:status).and_return(200)
40
40
  @response.stub(:headers).and_return({
41
41
  'etag' => '12345',
@@ -78,11 +78,10 @@ describe Google::APIClient::Result do
78
78
  end
79
79
 
80
80
  it 'should escape the next page token when calling next_page' do
81
- pending("This is caused by Faraday's encoding of query parameters.")
82
81
  reference = @result.next_page
83
82
  Hash[reference.parameters].should include('pageToken')
84
83
  Hash[reference.parameters]['pageToken'].should == 'NEXT+PAGE+TOKEN'
85
- url = reference.to_env(Faraday.default_connection)[:url]
84
+ url = reference.to_env(CLIENT.connection)[:url]
86
85
  url.to_s.should include('pageToken=NEXT%2BPAGE%2BTOKEN')
87
86
  end
88
87
 
@@ -141,3 +141,24 @@ describe Google::APIClient::JWTAsserter do
141
141
  end
142
142
  end
143
143
 
144
+ describe Google::APIClient::ComputeServiceAccount do
145
+ include ConnectionHelpers
146
+
147
+ it 'should query metadata server' do
148
+ conn = stub_connection do |stub|
149
+ stub.get('/computeMetadata/v1beta1/instance/service-accounts/default/token') do |env|
150
+ env.url.host.should == 'metadata'
151
+ [200, {}, '{
152
+ "access_token" : "1/abcdef1234567890",
153
+ "token_type" : "Bearer",
154
+ "expires_in" : 3600
155
+ }']
156
+ end
157
+ end
158
+ service_account = Google::APIClient::ComputeServiceAccount.new
159
+ auth = service_account.fetch_access_token!({ :connection => conn })
160
+ auth.should_not == nil?
161
+ auth["access_token"].should == "1/abcdef1234567890"
162
+ conn.verify
163
+ end
164
+ end