worochi 0.0.13 → 0.0.14

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10d262c628a03073fc9acaeed754af4c9cd65508
4
- data.tar.gz: c2627ca0440adea26112bff91dab7ab4062f8419
3
+ metadata.gz: a16bf51d367b8b62f009a425dd929ed96d38f376
4
+ data.tar.gz: 9e24cbc3ebee89c808a6f1c9e5622ab78b67680f
5
5
  SHA512:
6
- metadata.gz: 69db7642802200e9139ddcd003b877d064ed3c4f765d16b98383311c65801c5b4d4814b061f9d53adf56fee0c5986f7370afbf6bd7cb3b0f91e0589712d32aed
7
- data.tar.gz: 2dfc7077f6b7a3b581549fc1a271e3563eb732a63f8ba3394297044424079b4fbee57e73dac6e13b024d087cbfda772df3a8b22ed272870433e61b96d04d2194
6
+ metadata.gz: 2cbfcb2ba4fc6d306bedfde432eae0f8cc66586a84f7a06b3b156235cf8762ada3da0ef09ee56d9dea665755b10ccea8d572bda49f76e5f8b336186b9709a8e3
7
+ data.tar.gz: d28e49ee2f24e2eae8d982d3706407c4f76019d51f80f118c771e8833829d0bfa7e1dd2cab9effa292bd07563e4180e0bc57c92d006bfb2c230f2bf0241c4911
@@ -0,0 +1,11 @@
1
+ id: 3
2
+
3
+ display_name: Google Drive
4
+ dir: /
5
+ oauth:
6
+ id_env: GOOGLE_ID
7
+ secret_env: GOOGLE_SECRET
8
+ token_url: /1/oauth2/token
9
+ authorize_url: /o/oauth2/auth
10
+ site: https://accounts.google.com
11
+ scope: https://www.googleapis.com/auth/drive
@@ -36,7 +36,8 @@ class Worochi
36
36
  @services = files.map do |file|
37
37
  File.basename(file, '.yml').to_sym
38
38
  end
39
- @services
39
+ @all_services = @services.clone.freeze
40
+ @services.freeze
40
41
  end
41
42
 
42
43
  # Array of service meta information.
@@ -52,6 +53,24 @@ class Worochi
52
53
  end
53
54
  end
54
55
 
56
+ # Only enable the list of services specified instead of all supported
57
+ # services.
58
+ #
59
+ # @return [Array<Symbol>] enabled services
60
+ def enable_services(list)
61
+ @all_services || services
62
+ @services = @all_services.reject { |service| !list.include?(service) }
63
+ @services.freeze
64
+ end
65
+
66
+ # Re-enable all supported services.
67
+ #
68
+ # @return [Array<Symbol>] enabled services
69
+ def reset_services
70
+ @services || services
71
+ @services = @all_services.clone
72
+ end
73
+
55
74
  # Returns display name for the service.
56
75
  #
57
76
  # @overload service_display_name(service)
data/lib/worochi/oauth.rb CHANGED
@@ -43,12 +43,24 @@ class Worochi
43
43
  client.site = options.token_site || options.site
44
44
  opts = {}
45
45
  opts[:redirect_uri] = options.redirect_uri if options.redirect_uri
46
- token = client.auth_code.get_token(code, opts)
47
- Hashie::Mash.new(token.to_hash)
46
+ Hashie::Mash.new(client.auth_code.get_token(code, opts).to_hash)
48
47
  end
49
48
 
50
49
  alias_method :get_token, :flow_end
51
50
 
51
+ # Refreshes the access token using the refresh token.
52
+ #
53
+ # @param hash [Hash] stored hash for the token
54
+ # @return [Hashie::Mash] Updated OAuth2 token
55
+ def refresh!(hash)
56
+ token = OAuth2::AccessToken.from_hash(@client, hash)
57
+ begin
58
+ token.refresh!
59
+ rescue OAuth2::Error
60
+ end
61
+ Hashie::Mash.new(token.to_hash)
62
+ end
63
+
52
64
  private
53
65
  # @return [String] scope
54
66
  def scope
@@ -1,4 +1,4 @@
1
1
  class Worochi
2
2
  # Current version of the gem
3
- VERSION = '0.0.13'
3
+ VERSION = '0.0.14'
4
4
  end
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://github.com/login/oauth/access_token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: client_id=<GITHUB_ID>&client_secret=<GITHUB_SECRET>&grant_type=refresh_token&refresh_token=bbbbb
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ Content-Type:
13
+ - application/x-www-form-urlencoded
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - '*/*'
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - GitHub.com
25
+ Date:
26
+ - Mon, 19 Aug 2013 18:24:37 GMT
27
+ Content-Type:
28
+ - application/x-www-form-urlencoded; charset=utf-8
29
+ Connection:
30
+ - keep-alive
31
+ Status:
32
+ - 200 OK
33
+ Cache-Control:
34
+ - private, max-age=0, must-revalidate
35
+ Strict-Transport-Security:
36
+ - max-age=2592000
37
+ X-Frame-Options:
38
+ - deny
39
+ Set-Cookie:
40
+ - dotcom_user=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT
41
+ - logged_in=no; domain=.github.com; path=/; expires=Fri, 19-Aug-2033 18:24:37
42
+ GMT; secure; HttpOnly
43
+ X-Runtime:
44
+ - '8'
45
+ Etag:
46
+ - '"ed2cf91250498a9276e3b4fa6de2c2b6"'
47
+ Content-Length:
48
+ - '27'
49
+ Vary:
50
+ - Accept-Encoding
51
+ body:
52
+ encoding: UTF-8
53
+ string: error=bad_verification_code
54
+ http_version:
55
+ recorded_at: Mon, 19 Aug 2013 18:24:37 GMT
56
+ recorded_with: VCR 2.5.0
@@ -7,6 +7,10 @@ class Worochi
7
7
  expect(Config.services.class).to be(Array)
8
8
  expect(Config.services.first.class).to be(Symbol)
9
9
  end
10
+ it 'is frozen' do
11
+ list = Config.services
12
+ expect{list << :test}.to raise_error(RuntimeError)
13
+ end
10
14
  end
11
15
 
12
16
  describe '.list_services' do
@@ -18,6 +22,26 @@ class Worochi
18
22
  end
19
23
  end
20
24
 
25
+ describe '.enable_services' do
26
+ it 'disables all services not in the given list' do
27
+ all_services = Config.services
28
+ Config.enable_services([all_services.first])
29
+ expect(Config.services).not_to eq(all_services)
30
+ expect(Config.services).to include(all_services.first)
31
+ Config.enable_services(all_services)
32
+ expect(Config.services).to eq(all_services)
33
+ end
34
+ end
35
+
36
+ describe '.reset_services' do
37
+ it 'enables all supported services' do
38
+ all_services = Config.services
39
+ Config.enable_services([all_services.first])
40
+ Config.reset_services
41
+ expect(Config.services).to eq(all_services)
42
+ end
43
+ end
44
+
21
45
  describe '.service_display_name' do
22
46
  it 'returns display name given an ID' do
23
47
  expect(Config.service_display_name(1)).to eq('GitHub')
@@ -30,4 +30,16 @@ describe Worochi::OAuth do
30
30
  expect{auth.flow_end('abc')}.to raise_error(OAuth2::Error)
31
31
  end
32
32
  end
33
+
34
+ describe '#refresh', :vcr do
35
+ it 'tries to refresh the access token' do
36
+ token = {
37
+ token_type: "bearer",
38
+ access_token: "aaaaa",
39
+ refresh_token: "bbbbb",
40
+ expires_at: 1376702712
41
+ }
42
+ expect(auth.refresh!(token)).to include(:refresh_token)
43
+ end
44
+ end
33
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worochi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raven Jiang
@@ -217,6 +217,7 @@ files:
217
217
  - lib/worochi/version.rb
218
218
  - lib/worochi/configurator.rb
219
219
  - lib/worochi.rb
220
+ - lib/worochi/config/google_drive.yml
220
221
  - lib/worochi/config/box.yml
221
222
  - lib/worochi/config/github.yml
222
223
  - lib/worochi/config/dropbox.yml
@@ -281,6 +282,7 @@ files:
281
282
  - spec/cassettes/Worochi_Item/_open/opens_a_single_file/with_String_parameter.yml
282
283
  - spec/cassettes/Worochi_Item/_open/opens_a_single_file/with_Hash_parameter.yml
283
284
  - spec/cassettes/Worochi_OAuth/_flow_end/rejects_bad_code.yml
285
+ - spec/cassettes/Worochi_OAuth/_refresh/tries_to_refresh_the_access_token.yml
284
286
  homepage: https://github.com/Pixelapse/worochi
285
287
  licenses:
286
288
  - MIT
@@ -366,4 +368,5 @@ test_files:
366
368
  - spec/cassettes/Worochi_Item/_open/opens_a_single_file/with_String_parameter.yml
367
369
  - spec/cassettes/Worochi_Item/_open/opens_a_single_file/with_Hash_parameter.yml
368
370
  - spec/cassettes/Worochi_OAuth/_flow_end/rejects_bad_code.yml
371
+ - spec/cassettes/Worochi_OAuth/_refresh/tries_to_refresh_the_access_token.yml
369
372
  has_rdoc: