google-api 0.0.1.beta → 0.0.1.rc1
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/CHANGELOG.md +4 -0
- data/README.md +5 -4
- data/google-api.gemspec +1 -1
- data/lib/google-api/active_record_inclusions.rb +3 -3
- data/lib/google-api/api.rb +1 -1
- data/lib/google-api.rb +10 -2
- data/spec/google-api/api_spec.rb +1 -0
- data/spec/google-api/client_spec.rb +1 -0
- data/spec/google-api_spec.rb +46 -1
- metadata +3 -3
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -32,7 +32,8 @@ This gem couldn't be easier to set up. Once you have a Client ID and Secret from
|
|
32
32
|
```ruby
|
33
33
|
GoogleAPI.configure do |config|
|
34
34
|
config.client_id = '[CLIENT ID]'
|
35
|
-
config.client_secret = '[
|
35
|
+
config.client_secret = '[CLIENT SECRET]'
|
36
|
+
config.encryption_key = '[ENCRYPTION KEY]'
|
36
37
|
end
|
37
38
|
```
|
38
39
|
|
@@ -65,14 +66,14 @@ user.google.drive.files.list
|
|
65
66
|
|
66
67
|
This will fetch all files and folders in the user's Google Drive and return them in an array of hashes.
|
67
68
|
|
68
|
-
## What Google APIs
|
69
|
+
## What Google APIs has this gem be tested against?
|
69
70
|
|
70
71
|
* Calendar
|
71
72
|
* Drive
|
72
73
|
|
73
|
-
## I need to use an API that is not yet
|
74
|
+
## I need to use an API that is not yet tested
|
74
75
|
|
75
|
-
Open an issue, and we will do our best to
|
76
|
+
Open an issue, and we will do our best to fully test the API you need. Or, you can submit a pull request with any necessary updates!
|
76
77
|
|
77
78
|
## Contributing
|
78
79
|
|
data/google-api.gemspec
CHANGED
@@ -11,7 +11,7 @@ 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.0.1.
|
14
|
+
gem.version = "0.0.1.rc1"
|
15
15
|
|
16
16
|
gem.add_runtime_dependency 'mime-types', '~> 1.0'
|
17
17
|
gem.add_runtime_dependency 'oauth2', '~> 0.8.0'
|
@@ -14,14 +14,14 @@ module GoogleAPI
|
|
14
14
|
def oauthable
|
15
15
|
define_method :oauth_hash do
|
16
16
|
{
|
17
|
-
access_token: oauth_access_token,
|
18
|
-
refresh_token: oauth_refresh_token,
|
17
|
+
access_token: GoogleAPI.decrypt!(oauth_access_token),
|
18
|
+
refresh_token: GoogleAPI.decrypt!(oauth_refresh_token),
|
19
19
|
expires_at: oauth_access_token_expires_at
|
20
20
|
}
|
21
21
|
end
|
22
22
|
|
23
23
|
define_method :update_access_token! do |access_token|
|
24
|
-
self.oauth_access_token = access_token
|
24
|
+
self.oauth_access_token = GoogleAPI.encrypt!(access_token)
|
25
25
|
self.oauth_access_token_expires_at = 59.minutes.from_now
|
26
26
|
self.save
|
27
27
|
end
|
data/lib/google-api/api.rb
CHANGED
data/lib/google-api.rb
CHANGED
@@ -17,7 +17,7 @@ module GoogleAPI
|
|
17
17
|
# https://github.com/sferik/twitter/blob/v3.6.0/lib/twitter/configurable.rb
|
18
18
|
class << self
|
19
19
|
|
20
|
-
attr_accessor :client_id, :client_secret, :development_mode, :logger
|
20
|
+
attr_accessor :client_id, :client_secret, :encryption_key, :development_mode, :logger
|
21
21
|
|
22
22
|
# Configuration options:
|
23
23
|
#
|
@@ -26,7 +26,7 @@ module GoogleAPI
|
|
26
26
|
def configure
|
27
27
|
yield self
|
28
28
|
|
29
|
-
raise ArgumentError, "GoogleAPI requires both a :client_id and :client_secret configuration option to be set." unless [client_id, client_secret].all?
|
29
|
+
raise ArgumentError, "GoogleAPI requires both a :client_id and :client_secret configuration option to be set." unless [client_id, client_secret, encryption_key].all?
|
30
30
|
|
31
31
|
@development_mode ||= false
|
32
32
|
@logger ||= defined?(::Rails) ? Rails.logger : stdout_logger
|
@@ -56,6 +56,14 @@ module GoogleAPI
|
|
56
56
|
@discovered_apis = {}
|
57
57
|
end
|
58
58
|
|
59
|
+
def encrypt!(string)
|
60
|
+
Base64.encode64("#{string}#{encryption_key}")
|
61
|
+
end
|
62
|
+
|
63
|
+
def decrypt!(string)
|
64
|
+
Base64.decode64(string).sub(/#{Regexp.escape(encryption_key)}$/, '')
|
65
|
+
end
|
66
|
+
|
59
67
|
end
|
60
68
|
|
61
69
|
end
|
data/spec/google-api/api_spec.rb
CHANGED
data/spec/google-api_spec.rb
CHANGED
@@ -9,6 +9,7 @@ describe GoogleAPI do
|
|
9
9
|
GoogleAPI.configure do |config|
|
10
10
|
config.client_id = nil
|
11
11
|
config.client_secret = 'test secret'
|
12
|
+
config.encryption_key = 'encryption key'
|
12
13
|
end
|
13
14
|
}.to raise_error(ArgumentError)
|
14
15
|
end
|
@@ -18,15 +19,27 @@ describe GoogleAPI do
|
|
18
19
|
GoogleAPI.configure do |config|
|
19
20
|
config.client_id = 'test id'
|
20
21
|
config.client_secret = nil
|
22
|
+
config.encryption_key = 'encryption key'
|
21
23
|
end
|
22
24
|
}.to raise_error(ArgumentError)
|
23
25
|
end
|
24
26
|
|
25
|
-
it "should raise an error when
|
27
|
+
it "should raise an error when the ENCRYPTION KEY is blank" do
|
28
|
+
expect {
|
29
|
+
GoogleAPI.configure do |config|
|
30
|
+
config.client_id = 'test id'
|
31
|
+
config.client_secret = 'test secret'
|
32
|
+
config.encryption_key = nil
|
33
|
+
end
|
34
|
+
}.to raise_error(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should raise an error when CLIENT ID, CLIENT SECRET, and ENCRYPTION KEY are blank" do
|
26
38
|
expect {
|
27
39
|
GoogleAPI.configure do |config|
|
28
40
|
config.client_id = nil
|
29
41
|
config.client_secret = nil
|
42
|
+
config.encryption_key = nil
|
30
43
|
end
|
31
44
|
}.to raise_error(ArgumentError)
|
32
45
|
end
|
@@ -35,6 +48,7 @@ describe GoogleAPI do
|
|
35
48
|
GoogleAPI.configure do |config|
|
36
49
|
config.client_id = 'test id'
|
37
50
|
config.client_secret = 'test secret'
|
51
|
+
config.encryption_key = 'encryption key'
|
38
52
|
end
|
39
53
|
|
40
54
|
GoogleAPI.development_mode.should be_false
|
@@ -44,6 +58,7 @@ describe GoogleAPI do
|
|
44
58
|
GoogleAPI.configure do |config|
|
45
59
|
config.client_id = 'test id'
|
46
60
|
config.client_secret = 'test secret'
|
61
|
+
config.encryption_key = 'encryption key'
|
47
62
|
config.development_mode = true
|
48
63
|
end
|
49
64
|
|
@@ -59,6 +74,7 @@ describe GoogleAPI do
|
|
59
74
|
GoogleAPI.configure do |config|
|
60
75
|
config.client_id = 'test id'
|
61
76
|
config.client_secret = 'test secret'
|
77
|
+
config.encryption_key = 'encryption key'
|
62
78
|
end
|
63
79
|
|
64
80
|
end
|
@@ -69,6 +85,7 @@ describe GoogleAPI do
|
|
69
85
|
GoogleAPI.configure do |config|
|
70
86
|
config.client_id = 'test id'
|
71
87
|
config.client_secret = 'test secret'
|
88
|
+
config.encryption_key = 'encryption key'
|
72
89
|
end
|
73
90
|
end
|
74
91
|
|
@@ -99,4 +116,32 @@ describe GoogleAPI do
|
|
99
116
|
|
100
117
|
end
|
101
118
|
|
119
|
+
describe "#encrypt!" do
|
120
|
+
|
121
|
+
it "should return an encrypted version of the string" do
|
122
|
+
GoogleAPI.configure do |config|
|
123
|
+
config.client_id = 'test id'
|
124
|
+
config.client_secret = 'test secret'
|
125
|
+
config.encryption_key = 'encryption key'
|
126
|
+
end
|
127
|
+
|
128
|
+
GoogleAPI.encrypt!('test').should == "dGVzdGVuY3J5cHRpb24ga2V5\n"
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "#decrypt!" do
|
134
|
+
|
135
|
+
it "should return an decrypted version of the string" do
|
136
|
+
GoogleAPI.configure do |config|
|
137
|
+
config.client_id = 'test id'
|
138
|
+
config.client_secret = 'test secret'
|
139
|
+
config.encryption_key = 'encryption key'
|
140
|
+
end
|
141
|
+
|
142
|
+
GoogleAPI.decrypt!("dGVzdGVuY3J5cHRpb24ga2V5\n").should == 'test'
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
102
147
|
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.0.1.
|
4
|
+
version: 0.0.1.rc1
|
5
5
|
prerelease: 6
|
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-09-
|
12
|
+
date: 2012-09-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mime-types
|
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
segments:
|
157
157
|
- 0
|
158
|
-
hash: -
|
158
|
+
hash: -4437608343180398710
|
159
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
160
|
none: false
|
161
161
|
requirements:
|