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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +82 -24
  3. data/lib/worochi/agent/#example.rb +6 -0
  4. data/lib/worochi/agent/dropbox.rb +6 -8
  5. data/lib/worochi/agent/github.rb +7 -2
  6. data/lib/worochi/agent/google_drive.rb +272 -0
  7. data/lib/worochi/agent.rb +23 -2
  8. data/lib/worochi/config/google_drive.yml +3 -1
  9. data/lib/worochi/item.rb +42 -1
  10. data/lib/worochi/oauth.rb +16 -8
  11. data/lib/worochi/version.rb +1 -1
  12. data/lib/worochi.rb +1 -0
  13. data/spec/cassettes/Worochi_Agent_GoogleDrive/_delete/deletes_a_file.yml +4248 -0
  14. data/spec/cassettes/Worochi_Agent_GoogleDrive/_delete/raises_error_on_bad_token.yml +7889 -0
  15. data/spec/cassettes/Worochi_Agent_GoogleDrive/_get_item_id/retrieves_the_item_ID.yml +4148 -0
  16. data/spec/cassettes/Worochi_Agent_GoogleDrive/_get_item_id/returns_the_root_ID.yml +3889 -0
  17. data/spec/cassettes/Worochi_Agent_GoogleDrive/_insert_file/creates_a_new_folder_to_root.yml +4753 -0
  18. data/spec/cassettes/Worochi_Agent_GoogleDrive/_insert_file/uploads_a_file.yml +4492 -0
  19. data/spec/cassettes/Worochi_Agent_GoogleDrive/_push_item/creates_new_directories_as_needed.yml +5961 -0
  20. data/spec/cassettes/Worochi_Agent_GoogleDrive/_push_item/pushes_a_single_item.yml +3887 -0
  21. data/spec/cassettes/Worochi_Agent_GoogleDrive/_push_item/raises_error_on_bad_token.yml +7833 -0
  22. data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_default_options/has_the_required_options.yml +3889 -0
  23. data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_files/accepts_a_different_relative_path.yml +4294 -0
  24. data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_files/contains_file1.yml +4236 -0
  25. data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_files/does_not_contain_folder1.yml +4236 -0
  26. data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_files/raises_error_on_invalid_path.yml +4236 -0
  27. data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_files_and_folders/contains_folder1_and_file1.yml +4583 -0
  28. 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
  29. data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_folders/accepts_a_different_relative_path.yml +4294 -0
  30. data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_folders/contains_folder1.yml +4236 -0
  31. data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_folders/does_not_contain_file1.yml +4236 -0
  32. data/spec/cassettes/Worochi_Agent_GoogleDrive/it_should_behave_like_a_service_agent/_init_client/returns_the_client.yml +7775 -0
  33. data/spec/cassettes/Worochi_Item/_content_type/detects_the_MIME_type.yml +105 -0
  34. data/spec/cassettes/Worochi_Item/_content_type/falls_back_to_file_name_when_ruby-filemagic_is_not_loaded.yml +105 -0
  35. data/spec/spec_helper.rb +5 -0
  36. data/spec/support/shared_exampes_for_agents.rb +2 -2
  37. data/spec/worochi/agent/github_spec.rb +6 -0
  38. data/spec/worochi/agent/google_drive_spec.rb +79 -0
  39. data/spec/worochi/agent_spec.rb +13 -1
  40. data/spec/worochi/item_spec.rb +18 -0
  41. data/spec/worochi/oauth_spec.rb +1 -1
  42. data/worochi.gemspec +4 -0
  43. 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 = { scope: scope }
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
- alias_method :get_token, :flow_end
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!(hash)
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 || ''
@@ -1,4 +1,4 @@
1
1
  class Worochi
2
2
  # Current version of the gem
3
- VERSION = '0.0.14'
3
+ VERSION = '0.0.15'
4
4
  end
data/lib/worochi.rb CHANGED
@@ -8,6 +8,7 @@ require 'worochi/item'
8
8
  require 'worochi/agent'
9
9
  require 'worochi/oauth'
10
10
  require 'worochi/helper'
11
+ require 'worochi/version'
11
12
 
12
13
  # The main class for the gem. This and the {Agent} class are the main
13
14
  # endpoints for interacting with the remote services.