worochi 0.0.14 → 0.0.15
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 +4 -4
- data/README.md +82 -24
- data/lib/worochi/agent/#example.rb +6 -0
- data/lib/worochi/agent/dropbox.rb +6 -8
- data/lib/worochi/agent/github.rb +7 -2
- data/lib/worochi/agent/google_drive.rb +272 -0
- data/lib/worochi/agent.rb +23 -2
- data/lib/worochi/config/google_drive.yml +3 -1
- data/lib/worochi/item.rb +42 -1
- data/lib/worochi/oauth.rb +16 -8
- data/lib/worochi/version.rb +1 -1
- data/lib/worochi.rb +1 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/_delete/deletes_a_file.yml +4248 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/_delete/raises_error_on_bad_token.yml +7889 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/_get_item_id/retrieves_the_item_ID.yml +4148 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/_get_item_id/returns_the_root_ID.yml +3889 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/_insert_file/creates_a_new_folder_to_root.yml +4753 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/_insert_file/uploads_a_file.yml +4492 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/_push_item/creates_new_directories_as_needed.yml +5961 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/_push_item/pushes_a_single_item.yml +3887 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/_push_item/raises_error_on_bad_token.yml +7833 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_default_options/has_the_required_options.yml +3889 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_files/accepts_a_different_relative_path.yml +4294 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_files/contains_file1.yml +4236 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_files/does_not_contain_folder1.yml +4236 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_files/raises_error_on_invalid_path.yml +4236 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_files_and_folders/contains_folder1_and_file1.yml +4583 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_files_and_folders/shows_detailed_listing_including_the_required_fields.yml +4236 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_folders/accepts_a_different_relative_path.yml +4294 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_folders/contains_folder1.yml +4236 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_folders/does_not_contain_file1.yml +4236 -0
- data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_init_client/returns_the_client.yml +7775 -0
- data/spec/cassettes/Worochi_Item/_content_type/detects_the_MIME_type.yml +105 -0
- data/spec/cassettes/Worochi_Item/_content_type/falls_back_to_file_name_when_ruby-filemagic_is_not_loaded.yml +105 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/support/shared_exampes_for_agents.rb +2 -2
- data/spec/worochi/agent/github_spec.rb +6 -0
- data/spec/worochi/agent/google_drive_spec.rb +79 -0
- data/spec/worochi/agent_spec.rb +13 -1
- data/spec/worochi/item_spec.rb +18 -0
- data/spec/worochi/oauth_spec.rb +1 -1
- data/worochi.gemspec +4 -0
- metadata +104 -1
data/lib/worochi/oauth.rb
CHANGED
@@ -3,6 +3,10 @@ require 'oauth2'
|
|
3
3
|
class Worochi
|
4
4
|
# Implements OAuth2 authorization code flow for obtaining user tokens.
|
5
5
|
class OAuth
|
6
|
+
# List of options that should not be sent with HTTP requests.
|
7
|
+
INTERNAL_OPTS = [:id_env, :secret_env, :token_url, :authorize_url, :site,
|
8
|
+
:token_site, :service]
|
9
|
+
|
6
10
|
# OAuth2 options.
|
7
11
|
# @return [Hashie::Mash]
|
8
12
|
attr_accessor :options
|
@@ -29,9 +33,8 @@ class Worochi
|
|
29
33
|
# @return [String] URL to begin flow
|
30
34
|
def flow_start(state=nil)
|
31
35
|
client.site = options.site
|
32
|
-
opts =
|
36
|
+
opts = params
|
33
37
|
opts[:state] = state if state
|
34
|
-
opts[:redirect_uri] = options.redirect_uri if options.redirect_uri
|
35
38
|
client.auth_code.authorize_url(opts)
|
36
39
|
end
|
37
40
|
|
@@ -46,22 +49,27 @@ class Worochi
|
|
46
49
|
Hashie::Mash.new(client.auth_code.get_token(code, opts).to_hash)
|
47
50
|
end
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
# Refreshes the access token using the refresh token.
|
52
|
+
# Refreshes an existing access token using the refresh token.
|
52
53
|
#
|
53
54
|
# @param hash [Hash] stored hash for the token
|
54
55
|
# @return [Hashie::Mash] Updated OAuth2 token
|
55
|
-
def refresh
|
56
|
+
def refresh(hash)
|
56
57
|
token = OAuth2::AccessToken.from_hash(@client, hash)
|
57
58
|
begin
|
58
|
-
token.refresh
|
59
|
+
Hashie::Mash.new(token.refresh!.to_hash)
|
59
60
|
rescue OAuth2::Error
|
61
|
+
raise Worochi::Error, 'Invalid refresh token'
|
60
62
|
end
|
61
|
-
Hashie::Mash.new(token.to_hash)
|
62
63
|
end
|
63
64
|
|
65
|
+
alias_method :get_token, :flow_end
|
66
|
+
|
64
67
|
private
|
68
|
+
# @return [Hash] returns only the options that are meant to be sent.
|
69
|
+
def params
|
70
|
+
options.reject { |k, v| INTERNAL_OPTS.include?(k.to_sym) }
|
71
|
+
end
|
72
|
+
|
65
73
|
# @return [String] scope
|
66
74
|
def scope
|
67
75
|
options.scope || ''
|
data/lib/worochi/version.rb
CHANGED
data/lib/worochi.rb
CHANGED