google-api 0.3.0 → 0.4.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.
data/.rspec CHANGED
@@ -1,2 +1 @@
1
1
  --colour
2
- --format documentation
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.4.0 (2013-02-10)
2
+
3
+ * Bump dependency of OAuth2 to 0.9.x.
4
+
1
5
  ## v0.3.0 (2012-11-24)
2
6
 
3
7
  * Save encrypted values as Base64-encoded strings. (NOTE: This is a non-backward compatible change!)
data/google-api.gemspec CHANGED
@@ -11,10 +11,10 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
12
  gem.name = "google-api"
13
13
  gem.require_paths = ["lib"]
14
- gem.version = "0.3.0"
14
+ gem.version = "0.4.0"
15
15
 
16
16
  gem.add_runtime_dependency 'mime-types', '~> 1.0'
17
- gem.add_runtime_dependency 'oauth2', '~> 0.8.0'
17
+ gem.add_runtime_dependency 'oauth2', '~> 0.9.0'
18
18
  gem.add_development_dependency 'bundler'
19
19
  gem.add_development_dependency 'rake'
20
20
  gem.add_development_dependency 'rspec'
data/lib/google-api.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'mime/types'
2
2
  require 'oauth2'
3
- require 'google-api/oauth2'
4
3
  require 'google-api/api'
5
4
  require 'google-api/client'
6
5
  require 'google-api/encrypter'
@@ -1,61 +1,48 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  shared_context "api call" do
4
-
5
4
  let(:map) { fixture(:discovery_rest_drive)['resources']['files']['methods'] }
6
5
  let(:api) { GoogleAPI::API.new(client.access_token, :drive, map) }
7
6
  let(:stubbed_response) { OAuth2Response.new }
8
- before(:each) do
7
+
8
+ before do
9
9
  GoogleAPI.discovered_apis[:drive] = fixture(:discovery_rest_drive)
10
10
  client.client.connection = TEST_CONNECTION
11
11
  end
12
-
13
12
  end
14
13
 
15
14
  describe GoogleAPI::API do
16
15
 
17
16
  let(:object) { User.new }
18
17
  let(:client) { GoogleAPI::Client.new(object) }
19
- before(:each) do
18
+
19
+ before do
20
20
  GoogleAPI.configure do |config|
21
21
  config.client_id = 'test id'
22
22
  config.client_secret = 'test secret'
23
23
  config.encryption_key = 'encryption key'
24
24
  end
25
+ GoogleAPI.logger.stub(:error)
25
26
  object.authenticated = true
26
27
  end
27
28
 
28
29
  describe "#initialize" do
30
+ subject { GoogleAPI::API.new(client.access_token, :drive, fixture(:discovery_rest_drive)['resources']) }
29
31
 
30
- let(:api) { GoogleAPI::API.new(client.access_token, :drive, fixture(:discovery_rest_drive)['resources']) }
31
-
32
- it "should set the access_token attribute" do
33
- api.access_token.token.should == client.access_token.token
34
- end
35
-
36
- it "should set the api attribute" do
37
- api.api.should == :drive
38
- end
39
-
40
- it "should set the map attribute" do
41
- api.map.should == fixture(:discovery_rest_drive)['resources']
42
- end
43
-
32
+ its(:api) { should == :drive }
33
+ its(:map) { should == fixture(:discovery_rest_drive)['resources'] }
34
+ its('access_token.token') { should == client.access_token.token }
44
35
  end
45
36
 
46
37
  describe "API method generation" do
47
-
48
38
  context "when there are methods lower in the tree" do
49
-
50
39
  it "should build another GoogleAPI::API class with the correct map" do
51
40
  api = GoogleAPI::API.new(client.access_token, :drive, fixture(:discovery_rest_drive)['resources'])
52
41
  api.files.should be_an_instance_of(GoogleAPI::API)
53
42
  end
54
-
55
43
  end
56
44
 
57
45
  context "when the method tree is the lowest it can be" do
58
-
59
46
  include_context "api call"
60
47
 
61
48
  it "should call the #build_url method" do
@@ -65,40 +52,29 @@ describe GoogleAPI::API do
65
52
 
66
53
  %w(POST PUT PATCH).each do |http_method|
67
54
  context "when the method's HTTP method is #{http_method}" do
68
-
69
55
  it "should raise ArgumentError if no body was passed" do
70
- expect {
71
- api.insert(media: '/Test/File/Path.txt')
72
- }.to raise_error(ArgumentError)
56
+ expect { api.insert(media: '/Test/File/Path.txt') }.to raise_error(ArgumentError)
73
57
  end
74
-
75
58
  end
76
59
  end
77
60
 
78
61
  context "when the mediaUpload key is present" do
79
-
80
62
  it "should call the #upload method" do
81
63
  api.should_receive(:upload).with('post', 'https://www.googleapis.com/resumable/upload/drive/v2/files', body: {title: 'Test File.txt'}, media: '/Test/File/Path.txt')
82
64
  api.insert(body: {title: 'Test File.txt'}, media: '/Test/File/Path.txt')
83
65
  end
84
-
85
66
  end
86
67
 
87
68
  context "when it is a normal API method request" do
88
-
89
69
  it "should delegate to the #request method" do
90
70
  api.should_receive(:request).with('get', 'https://www.googleapis.com/drive/v2/files', {})
91
71
  api.list
92
72
  end
93
-
94
73
  end
95
-
96
74
  end
97
-
98
75
  end
99
76
 
100
77
  describe "#request" do
101
-
102
78
  include_context "api call"
103
79
 
104
80
  it "should build the correct headers hash" do
@@ -112,7 +88,6 @@ describe GoogleAPI::API do
112
88
  end
113
89
 
114
90
  context "when a request is successful" do
115
-
116
91
  it "should only make the request attempt once" do
117
92
  ::OAuth2::AccessToken.any_instance.should_receive(:get).once.and_return(stubbed_response)
118
93
  api.list
@@ -125,11 +100,9 @@ describe GoogleAPI::API do
125
100
  it "should return the full Response object if body is blank" do
126
101
  api.delete(fileId: 'adummyfileidnumber').should be_an_instance_of(::OAuth2::Response)
127
102
  end
128
-
129
103
  end
130
104
 
131
105
  context "when a request fails and development mode is turned off" do
132
-
133
106
  it "should attempt the request 5 times" do
134
107
  ::OAuth2::AccessToken.any_instance.should_receive(:put).exactly(5).times.and_return(OAuth2Response.new(404))
135
108
  api.update(fileId: 'adummyfileidnumber', body: {bad: 'attribute'})
@@ -140,16 +113,13 @@ describe GoogleAPI::API do
140
113
  ::OAuth2::AccessToken.any_instance.should_receive(:put).once.and_return(stubbed_response)
141
114
  api.update(fileId: 'adummyfileidnumber', body: {bad: 'attribute'})
142
115
  end
143
-
144
116
  end
145
-
146
117
  end
147
118
 
148
119
  describe "#upload" do
149
-
150
120
  include_context "api call"
151
121
 
152
- before(:each) { api.stub(:request).and_return(stubbed_response) }
122
+ before { api.stub(:request).and_return(stubbed_response) }
153
123
 
154
124
  it "should build the correct options hash that is passed to the first request" do
155
125
  api.should_receive(:request).with('post', 'https://www.googleapis.com/resumable/upload/drive/v2/files', body: {title: 'Test File.txt', mimeType: 'application/x-ruby'}, headers: {'X-Upload-Content-Type' => 'application/x-ruby'})
@@ -158,27 +128,22 @@ describe GoogleAPI::API do
158
128
 
159
129
  it "should change the original headers for the actual file upload" do
160
130
  api.should_receive(:request)
161
- api.should_receive(:request).with(:put, nil, body: File.read(File.expand_path('spec/spec_helper.rb')), headers: {'Content-Type' => 'application/x-ruby', 'Content-Length' => '399'})
131
+ api.should_receive(:request).with(:put, nil, body: File.read(File.expand_path('spec/spec_helper.rb')), headers: {'Content-Type' => 'application/x-ruby', 'Content-Length' => '392'})
162
132
  api.send(:upload, 'post', 'https://www.googleapis.com/resumable/upload/drive/v2/files', body: {title: 'Test File.txt'}, media: File.expand_path('spec/spec_helper.rb'))
163
133
  end
164
-
165
134
  end
166
135
 
167
136
  describe "#build_url" do
168
-
169
137
  include_context "api call"
170
138
 
171
139
  context "when the mediaUpload key is present" do
172
-
173
140
  it "should use the rootUrl of the discovered API" do
174
141
  url, options = api.send(:build_url, map['insert'], media: File.expand_path('spec/spec_helper.rb'))
175
142
  url.should == 'https://www.googleapis.com/resumable/upload/drive/v2/files'
176
143
  end
177
-
178
144
  end
179
145
 
180
146
  context "when it is a normal API method request" do
181
-
182
147
  it "should build the final URL" do
183
148
  url, options = api.send(:build_url, map['get'], fileId: 'adummyfileidnumber', updateViewedDate: true)
184
149
  url.should == 'https://www.googleapis.com/drive/v2/files/adummyfileidnumber?updateViewedDate=true'
@@ -190,13 +155,9 @@ describe GoogleAPI::API do
190
155
  end
191
156
 
192
157
  it "should raise ArgumentError if the parameter is required and the matching option isn't passed" do
193
- expect {
194
- api.send(:build_url, map['get'], updateViewedDate: true)
195
- }.to raise_error(ArgumentError)
158
+ expect { api.send(:build_url, map['get'], updateViewedDate: true) }.to raise_error(ArgumentError)
196
159
  end
197
-
198
160
  end
199
-
200
161
  end
201
162
 
202
163
  end
@@ -3,114 +3,89 @@ require 'spec_helper'
3
3
  describe GoogleAPI::Client do
4
4
 
5
5
  let(:object) { User.new }
6
- let(:client) { GoogleAPI::Client.new(object) }
7
- before(:each) do
6
+
7
+ subject { GoogleAPI::Client.new(object) }
8
+
9
+ before do
8
10
  GoogleAPI.configure do |config|
9
11
  config.client_id = 'test id'
10
12
  config.client_secret = 'test secret'
11
13
  config.encryption_key = 'encryption key'
12
14
  end
15
+ GoogleAPI.logger.stub(:info)
13
16
  object.authenticated = true
14
- client.client.connection = TEST_CONNECTION
17
+ subject.client.connection = TEST_CONNECTION
15
18
  end
16
19
 
17
- describe "#initialize" do
18
-
19
- it "should set the object attribute" do
20
- client = GoogleAPI::Client.new(object)
21
- client.object.should == object
22
- end
20
+ its(:object) { should == object }
21
+ its(:client) { should be_an_instance_of(::OAuth2::Client) }
23
22
 
23
+ describe "#initialize" do
24
24
  it "should raise NoMethodError if the object isn't oauthable" do
25
- expect {
26
- GoogleAPI::Client.new(Class.new)
27
- }.to raise_error(NoMethodError)
25
+ expect { GoogleAPI::Client.new(Class.new) }.to raise_error(NoMethodError)
28
26
  end
29
27
 
30
28
  it "should raise ArgumentError if the object isn't OAuth2 authenticated" do
31
29
  object.authenticated = false
32
- expect {
33
- GoogleAPI::Client.new(object)
34
- }.to raise_error(ArgumentError)
30
+ expect { GoogleAPI::Client.new(object) }.to raise_error(ArgumentError)
35
31
  end
36
-
37
32
  end
38
33
 
39
34
  describe "#access_token" do
40
-
41
35
  it "should call to the OAuth2 Access Token class" do
42
- client.access_token.token.should == object.oauth_hash[:access_token]
36
+ subject.access_token.token.should == object.oauth_hash[:access_token]
43
37
  end
44
38
 
45
39
  context "when the access token is expired" do
46
-
47
- before(:each) { object.expires_at = Time.now - 86400 }
40
+ before { object.expires_at = Time.now - 86400 }
48
41
 
49
42
  it "should call refresh on the OAuth2 Access Token" do
50
43
  stubbed_access_token = Class.new
51
44
  stubbed_access_token.stub(:token).and_return('test token')
52
45
  ::OAuth2::AccessToken.any_instance.should_receive(:refresh!).and_return(stubbed_access_token)
53
- client.access_token
46
+ subject.access_token
54
47
  end
55
48
 
56
49
  it "should update the object's stored OAuth information" do
57
50
  object.should_receive(:update_oauth!)
58
- client.access_token
51
+ subject.access_token
59
52
  end
60
-
61
53
  end
62
54
 
63
55
  context "when the access token is fresh" do
64
-
65
56
  it "should not try and refresh the token again" do
66
57
  ::OAuth2::AccessToken.any_instance.should_not_receive(:refresh!)
67
- client.access_token
58
+ subject.access_token
68
59
  end
69
-
70
60
  end
71
-
72
- end
73
-
74
- describe "#client" do
75
-
76
- it "should create the OAuth2 Client instance" do
77
- client.client.should be_an_instance_of(::OAuth2::Client)
78
- end
79
-
80
61
  end
81
62
 
82
63
  describe "API method generation" do
83
-
84
64
  context "when the API hasn't been discovered" do
85
-
86
65
  it "should call out to the Discovery API" do
87
66
  GoogleAPI.discovered_apis[:drive].should be_nil
88
- client.drive
67
+ subject.drive
89
68
  GoogleAPI.discovered_apis[:drive].should == fixture(:discovery_rest_drive)
90
69
  end
91
70
 
92
71
  it "should save the Discovery API map to the cache" do
93
- client.drive
72
+ subject.drive
94
73
  GoogleAPI.discovered_apis[:drive].should == fixture(:discovery_rest_drive)
95
74
  end
96
-
97
75
  end
98
76
 
99
77
  context "when the API has already been discovered" do
100
-
101
78
  it "should not fetch the Discovery API map" do
102
79
  GoogleAPI.discovered_apis[:drive] = fixture(:discovery_drive)
103
80
  ::OAuth2::AccessToken.any_instance.should_not_receive(:get)
104
- client.drive
81
+ subject.drive
105
82
  end
106
-
107
83
  end
108
84
 
109
85
  it "should build the GoogleAPI::API class" do
110
86
  GoogleAPI::API.should_receive(:new).with(an_instance_of(::OAuth2::AccessToken), :drive, fixture(:discovery_rest_drive)['resources'])
111
- client.drive
87
+ subject.drive
112
88
  end
113
-
114
89
  end
115
90
 
116
91
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe GoogleAPI::Encrypter do
4
4
 
5
- before(:each) do
5
+ before do
6
6
  GoogleAPI.configure do |config|
7
7
  config.client_id = 'test id'
8
8
  config.client_secret = 'test secret'
@@ -11,19 +11,15 @@ describe GoogleAPI::Encrypter do
11
11
  end
12
12
 
13
13
  describe "#encrypt!" do
14
-
15
14
  it "should return an encrypted version of the string" do
16
15
  GoogleAPI::Encrypter.encrypt!('test').should == "MMLzeQigMLGcvTvHczYxjg=="
17
16
  end
18
-
19
17
  end
20
18
 
21
19
  describe "#decrypt!" do
22
-
23
20
  it "should return an decrypted version of the string" do
24
21
  GoogleAPI::Encrypter.decrypt!("MMLzeQigMLGcvTvHczYxjg==").should == 'test'
25
22
  end
26
-
27
23
  end
28
24
 
29
25
  end
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
  describe GoogleAPI do
4
4
 
5
5
  describe "#configure" do
6
-
7
6
  it "should raise an error when the CLIENT ID is blank" do
8
7
  expect {
9
8
  GoogleAPI.configure do |config|
@@ -88,32 +87,25 @@ describe GoogleAPI do
88
87
  config.encryption_key = 'encryption key'
89
88
  end
90
89
  end
91
-
92
90
  end
93
91
 
94
92
  describe "#discovered_apis" do
93
+ subject { GoogleAPI.discovered_apis }
95
94
 
96
- it "should start as an empty hash" do
97
- GoogleAPI.discovered_apis.should == {}
98
- end
95
+ it { should be_an_instance_of(Hash) }
96
+ it { should be_empty }
99
97
 
100
- it "should keep a cache of discovered APIs" do
101
- GoogleAPI.discovered_apis[:test_api1] = {a: 1, b: 2, c: 3}
98
+ context "when a new api is cached" do
99
+ before { GoogleAPI.discovered_apis[:test_api1] = {a: 1, b: 2, c: 3} }
102
100
 
103
- GoogleAPI.discovered_apis[:test_api1].should == {a: 1, b: 2, c: 3}
101
+ its([:test_api1]) { should == {a: 1, b: 2, c: 3} }
104
102
  end
105
-
106
103
  end
107
104
 
108
105
  describe "#stdout_logger" do
106
+ subject { GoogleAPI.stdout_logger }
109
107
 
110
- let(:logger) { GoogleAPI.stdout_logger }
111
-
112
- it "should create a new Logger object" do
113
- logger = GoogleAPI.stdout_logger
114
- logger.should be_an_instance_of(Logger)
115
- end
116
-
108
+ it { should be_an_instance_of(Logger) }
117
109
  end
118
110
 
119
111
  end
data/spec/spec_helper.rb CHANGED
@@ -13,5 +13,5 @@ Faraday.default_adapter = :test
13
13
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
14
14
 
15
15
  RSpec.configure do |config|
16
- config.after(:each) { GoogleAPI.reset_environment! }
16
+ config.after { GoogleAPI.reset_environment! }
17
17
  end
@@ -24,4 +24,4 @@ class User
24
24
  def google
25
25
  end
26
26
 
27
- end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-25 00:00:00.000000000 Z
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.8.0
37
+ version: 0.9.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.8.0
45
+ version: 0.9.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: bundler
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -128,7 +128,6 @@ files:
128
128
  - lib/google-api/api.rb
129
129
  - lib/google-api/client.rb
130
130
  - lib/google-api/encrypter.rb
131
- - lib/google-api/oauth2.rb
132
131
  - lib/google-api/railtie.rb
133
132
  - spec/fixtures/discovery_drive.json
134
133
  - spec/fixtures/discovery_rest_drive.json
@@ -158,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
157
  version: '0'
159
158
  segments:
160
159
  - 0
161
- hash: -5125409393487118
160
+ hash: 3431589687934800430
162
161
  required_rubygems_version: !ruby/object:Gem::Requirement
163
162
  none: false
164
163
  requirements:
@@ -167,10 +166,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
166
  version: '0'
168
167
  segments:
169
168
  - 0
170
- hash: -5125409393487118
169
+ hash: 3431589687934800430
171
170
  requirements: []
172
171
  rubyforge_project:
173
- rubygems_version: 1.8.24
172
+ rubygems_version: 1.8.25
174
173
  signing_key:
175
174
  specification_version: 3
176
175
  summary: A simple but powerful ruby API wrapper for Google's services.
@@ -1,16 +0,0 @@
1
- # This can go away once the below commit is released with OAuth2.
2
- # https://github.com/intridea/oauth2/commit/8dc6feab9927c3fc03b8e0975909a96049a1cbd3
3
- # Should be in 0.8.1 or 0.9.0
4
-
5
- module OAuth2
6
- class AccessToken
7
-
8
- # Make a PATCH request with the Access Token
9
- #
10
- # @see AccessToken#request
11
- def patch(path, opts={}, &block)
12
- request(:patch, path, opts, &block)
13
- end
14
-
15
- end
16
- end