browse-everything 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +105 -30
  3. data/.gitignore +4 -2
  4. data/.rubocop.yml +54 -34
  5. data/.rubocop_todo.yml +0 -5
  6. data/.tool-versions +2 -0
  7. data/CONTRIBUTING.md +22 -0
  8. data/Gemfile +41 -33
  9. data/README.md +66 -31
  10. data/Rakefile +9 -1
  11. data/app/assets/javascripts/browse_everything/behavior.js +45 -31
  12. data/app/assets/javascripts/browse_everything.js +1 -1
  13. data/app/assets/javascripts/treetable.webpack.js +687 -0
  14. data/app/controllers/browse_everything_controller.rb +60 -60
  15. data/app/helpers/browse_everything_helper.rb +4 -0
  16. data/app/views/browse_everything/_files.html.erb +3 -2
  17. data/bin/rails +14 -0
  18. data/browse-everything.gemspec +13 -12
  19. data/lib/browse_everything/auth/google/credentials.rb +5 -5
  20. data/lib/browse_everything/auth/google/request_parameters.rb +38 -38
  21. data/lib/browse_everything/driver/base.rb +15 -14
  22. data/lib/browse_everything/driver/box.rb +56 -56
  23. data/lib/browse_everything/driver/dropbox.rb +44 -41
  24. data/lib/browse_everything/driver/file_system.rb +31 -18
  25. data/lib/browse_everything/driver/google_drive.rb +38 -38
  26. data/lib/browse_everything/driver/s3.rb +61 -61
  27. data/lib/browse_everything/engine.rb +10 -3
  28. data/lib/browse_everything/file_entry.rb +1 -1
  29. data/lib/browse_everything/retriever.rb +69 -69
  30. data/lib/browse_everything/version.rb +1 -1
  31. data/lib/browse_everything.rb +1 -1
  32. data/spec/dummy_test_app/Rakefile +6 -0
  33. data/spec/dummy_test_app/app/assets/config/manifest.js +3 -0
  34. data/spec/dummy_test_app/app/assets/images/.keep +0 -0
  35. data/spec/dummy_test_app/app/assets/javascripts/application.js +25 -0
  36. data/spec/dummy_test_app/app/assets/javascripts/cable.js +13 -0
  37. data/spec/dummy_test_app/app/assets/javascripts/channels/.keep +0 -0
  38. data/spec/dummy_test_app/app/assets/stylesheets/application.scss +18 -0
  39. data/spec/dummy_test_app/app/channels/application_cable/channel.rb +4 -0
  40. data/spec/dummy_test_app/app/channels/application_cable/connection.rb +4 -0
  41. data/spec/dummy_test_app/app/controllers/application_controller.rb +3 -0
  42. data/spec/dummy_test_app/app/controllers/concerns/.keep +0 -0
  43. data/spec/{support → dummy_test_app}/app/controllers/file_handler_controller.rb +0 -0
  44. data/spec/dummy_test_app/app/helpers/application_helper.rb +2 -0
  45. data/spec/dummy_test_app/app/jobs/application_job.rb +2 -0
  46. data/spec/dummy_test_app/app/mailers/application_mailer.rb +4 -0
  47. data/spec/dummy_test_app/app/models/application_record.rb +3 -0
  48. data/spec/dummy_test_app/app/models/concerns/.keep +0 -0
  49. data/spec/dummy_test_app/app/views/file_handler/index.html.erb +10 -0
  50. data/spec/{support → dummy_test_app}/app/views/file_handler/main.html.erb +6 -3
  51. data/spec/dummy_test_app/app/views/layouts/application.html.erb +14 -0
  52. data/spec/dummy_test_app/app/views/layouts/mailer.html.erb +13 -0
  53. data/spec/dummy_test_app/app/views/layouts/mailer.text.erb +1 -0
  54. data/spec/dummy_test_app/bin/bundle +3 -0
  55. data/spec/dummy_test_app/bin/rails +4 -0
  56. data/spec/dummy_test_app/bin/rake +4 -0
  57. data/spec/dummy_test_app/bin/setup +38 -0
  58. data/spec/dummy_test_app/bin/update +29 -0
  59. data/spec/dummy_test_app/bin/yarn +11 -0
  60. data/spec/dummy_test_app/config/application.rb +27 -0
  61. data/spec/dummy_test_app/config/boot.rb +5 -0
  62. data/spec/dummy_test_app/config/browse_everything_providers.yml +25 -0
  63. data/spec/dummy_test_app/config/cable.yml +10 -0
  64. data/spec/dummy_test_app/config/database.yml +25 -0
  65. data/spec/dummy_test_app/config/environment.rb +5 -0
  66. data/spec/dummy_test_app/config/environments/development.rb +54 -0
  67. data/spec/dummy_test_app/config/environments/production.rb +91 -0
  68. data/spec/dummy_test_app/config/environments/test.rb +42 -0
  69. data/spec/dummy_test_app/config/initializers/application_controller_renderer.rb +8 -0
  70. data/spec/dummy_test_app/config/initializers/assets.rb +14 -0
  71. data/spec/dummy_test_app/config/initializers/backtrace_silencers.rb +7 -0
  72. data/spec/dummy_test_app/config/initializers/cookies_serializer.rb +5 -0
  73. data/spec/dummy_test_app/config/initializers/filter_parameter_logging.rb +4 -0
  74. data/spec/dummy_test_app/config/initializers/inflections.rb +16 -0
  75. data/spec/dummy_test_app/config/initializers/mime_types.rb +4 -0
  76. data/spec/dummy_test_app/config/initializers/wrap_parameters.rb +14 -0
  77. data/spec/dummy_test_app/config/locales/en.yml +33 -0
  78. data/spec/dummy_test_app/config/puma.rb +56 -0
  79. data/spec/dummy_test_app/config/routes.rb +9 -0
  80. data/spec/dummy_test_app/config/secrets.yml +32 -0
  81. data/spec/dummy_test_app/config/spring.rb +6 -0
  82. data/spec/dummy_test_app/config.ru +5 -0
  83. data/spec/dummy_test_app/lib/assets/.keep +0 -0
  84. data/spec/dummy_test_app/log/.keep +0 -0
  85. data/spec/dummy_test_app/package.json +5 -0
  86. data/spec/dummy_test_app/public/404.html +67 -0
  87. data/spec/dummy_test_app/public/422.html +67 -0
  88. data/spec/dummy_test_app/public/500.html +66 -0
  89. data/spec/dummy_test_app/public/apple-touch-icon-precomposed.png +0 -0
  90. data/spec/dummy_test_app/public/apple-touch-icon.png +0 -0
  91. data/spec/dummy_test_app/public/favicon.ico +0 -0
  92. data/spec/dummy_test_app/tmp/.gitkeep +0 -0
  93. data/spec/features/select_files_spec.rb +1 -0
  94. data/spec/features/test_compiling_stylesheets_spec.rb +1 -1
  95. data/spec/lib/browse_everything/driver_spec.rb +43 -3
  96. data/spec/spec_helper.rb +3 -28
  97. data/tasks/ci.rake +1 -1
  98. metadata +180 -94
  99. data/karma.conf.js +0 -71
  100. data/spec/javascripts/behavior_spec.js +0 -7
  101. data/spec/javascripts/helpers/jasmine-jquery.js +0 -838
  102. data/spec/javascripts/helpers/jquery.js +0 -11008
  103. data/spec/javascripts/karma_spec.rb +0 -16
  104. data/spec/support/app/views/file_handler/index.html.erb +0 -6
  105. data/spec/test_app_templates/Gemfile.extra +0 -9
  106. data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -61
@@ -2,7 +2,7 @@
2
2
 
3
3
  require File.expand_path('../helpers/browse_everything_helper', __dir__)
4
4
 
5
- class BrowseEverythingController < ActionController::Base
5
+ class BrowseEverythingController < ApplicationController
6
6
  layout 'browse_everything'
7
7
  helper BrowseEverythingHelper
8
8
 
@@ -61,72 +61,72 @@ class BrowseEverythingController < ActionController::Base
61
61
 
62
62
  private
63
63
 
64
- # Constructs or accesses an existing session manager Object
65
- # @return [BrowseEverythingSession::ProviderSession] the session manager
66
- def provider_session
67
- BrowseEverythingSession::ProviderSession.new(session: session, name: provider_name)
68
- end
64
+ # Constructs or accesses an existing session manager Object
65
+ # @return [BrowseEverythingSession::ProviderSession] the session manager
66
+ def provider_session
67
+ BrowseEverythingSession::ProviderSession.new(session: session, name: provider_name)
68
+ end
69
69
 
70
- # Clears all authentication tokens, codes, and other data from the Rails session
71
- def reset_provider_session!
72
- return unless @provider_session
73
- @provider_session.token = nil
74
- @provider_session.code = nil
75
- @provider_session.data = nil
76
- @provider_session = nil
77
- end
70
+ # Clears all authentication tokens, codes, and other data from the Rails session
71
+ def reset_provider_session!
72
+ return unless @provider_session
73
+ @provider_session.token = nil
74
+ @provider_session.code = nil
75
+ @provider_session.data = nil
76
+ @provider_session = nil
77
+ end
78
78
 
79
- def connector_response_url_options
80
- { protocol: request.protocol, host: request.host, port: request.port }
81
- end
79
+ def connector_response_url_options
80
+ { protocol: request.protocol, host: request.host, port: request.port }
81
+ end
82
82
 
83
- # Generates the authentication link for a given provider service
84
- # @return [String] the authentication link
85
- def auth_link
86
- @auth_link ||= if provider.present?
87
- link, data = provider.auth_link(connector_response_url_options)
88
- provider_session.data = data
89
- link = "#{link}&state=#{provider.key}" unless link.to_s.include?('state')
90
- link
91
- end
92
- end
83
+ # Generates the authentication link for a given provider service
84
+ # @return [String] the authentication link
85
+ def auth_link
86
+ @auth_link ||= if provider.present?
87
+ link, data = provider.auth_link(connector_response_url_options)
88
+ provider_session.data = data
89
+ link = "#{link}&state=#{provider.key}" unless link.to_s.include?('state')
90
+ link
91
+ end
92
+ end
93
93
 
94
- # Accesses the relative path for browsing from the Rails session
95
- # @return [String]
96
- def browse_path
97
- params[:path] || ''
98
- end
94
+ # Accesses the relative path for browsing from the Rails session
95
+ # @return [String]
96
+ def browse_path
97
+ params[:path] || ''
98
+ end
99
99
 
100
- # Generate the provider name from the Rails session state value
101
- # @return [String]
102
- def provider_name_from_state
103
- params[:state].to_s.split(/\|/).last
104
- end
100
+ # Generate the provider name from the Rails session state value
101
+ # @return [String]
102
+ def provider_name_from_state
103
+ params[:state].to_s.split(/\|/).last
104
+ end
105
105
 
106
- # Generates the name of the provider using Rails session values
107
- # @return [String]
108
- def provider_name
109
- params[:provider] || provider_name_from_state || browser.providers.each_key.to_a.first
110
- end
106
+ # Generates the name of the provider using Rails session values
107
+ # @return [String]
108
+ def provider_name
109
+ params[:provider] || provider_name_from_state || browser.providers.each_key.to_a.first
110
+ end
111
111
 
112
- # Retrieve the Driver for each request
113
- # @return [BrowseEverything::Driver::Base]
114
- def provider
115
- browser.providers[provider_name.to_sym] || browser.first_provider
116
- end
112
+ # Retrieve the Driver for each request
113
+ # @return [BrowseEverything::Driver::Base]
114
+ def provider
115
+ browser.providers[provider_name.to_sym] || browser.first_provider
116
+ end
117
117
 
118
- # Constructs a browser manager Object
119
- # Browser state cannot persist between requests to the Controller
120
- # Hence, a Browser must be reinstantiated for each request using the state provided in the Rails session
121
- # @return [BrowseEverything::Browser]
122
- def browser
123
- BrowserFactory.build(session: session, url_options: url_options)
124
- end
118
+ # Constructs a browser manager Object
119
+ # Browser state cannot persist between requests to the Controller
120
+ # Hence, a Browser must be reinstantiated for each request using the state provided in the Rails session
121
+ # @return [BrowseEverything::Browser]
122
+ def browser
123
+ BrowserFactory.build(session: session, url_options: url_options)
124
+ end
125
125
 
126
- helper_method :auth_link
127
- helper_method :browser
128
- helper_method :browse_path
129
- helper_method :provider
130
- helper_method :provider_name
131
- helper_method :provider_contents
126
+ helper_method :auth_link
127
+ helper_method :browser
128
+ helper_method :browse_path
129
+ helper_method :provider
130
+ helper_method :provider_name
131
+ helper_method :provider_contents
132
132
  end
@@ -20,4 +20,8 @@ module BrowseEverythingHelper
20
20
  acceptable_types << 'application/x-directory'
21
21
  acceptable_types.any? { |type| mime_match?(file.type, type) }
22
22
  end
23
+
24
+ def file_size_to_human_size(file_size)
25
+ "#{file_size} bytes"
26
+ end
23
27
  end
@@ -16,6 +16,7 @@
16
16
  <% disabled = false %>
17
17
  <% else %>
18
18
  <% max_size = provider.config[:max_upload_file_size].to_i %>
19
+ <% max_human_size = file_size_to_human_size(max_size) %>
19
20
  <% disabled = file.size > max_size %>
20
21
  <% end %>
21
22
 
@@ -28,7 +29,7 @@
28
29
 
29
30
  <td role="gridcell" title="<%= file.name %>" class="<%=file.container? ? 'ev-container' : 'ev-file'%> ev-file-name">
30
31
  <% if disabled %>
31
- <span title="<%= t('browse_everything.size_disabled', max_size: number_to_human_size(max_size)) %>"
32
+ <span title="<%= t('browse_everything.size_disabled', max_size: max_human_size) %>"
32
33
  class="<%=file.container? ? 'folder' : 'file'%>" aria-hidden="true">
33
34
  <%= file.name %>
34
35
  </span>
@@ -53,7 +54,7 @@
53
54
 
54
55
  <% if file.size %>
55
56
  <td role="gridcell" class="ev-file-size">
56
- <%= number_to_human_size(file.size).sub(/Bytes/,'bytes') %>
57
+ <%= file_size_to_human_size(file.size) %>
57
58
  </td>
58
59
  <% else %>
59
60
  <td role="gridcell" class="ev-file-size">Unknown</td>
data/bin/rails ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+
5
+ ENGINE_ROOT = File.expand_path('..', __dir__)
6
+ ENGINE_PATH = File.expand_path('../lib/browse_everything/engine', __dir__)
7
+ APP_PATH = File.expand_path('../spec/dummy_test_app/config/application', __dir__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
11
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
12
+
13
+ require 'rails/all'
14
+ require 'rails/engine/commands'
@@ -15,30 +15,30 @@ Gem::Specification.new do |spec|
15
15
  spec.license = 'Apache 2'
16
16
 
17
17
  spec.files = `git ls-files -z`.split(/\000/)
18
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
19
  spec.require_paths = ['lib']
21
20
 
22
21
  spec.add_dependency 'addressable', '~> 2.5'
23
22
  spec.add_dependency 'aws-sdk-s3'
24
- spec.add_dependency 'dropbox_api', '>= 0.1.10'
25
- spec.add_dependency 'google-api-client', '~> 0.23'
26
- spec.add_dependency 'google_drive', '>= 2.1', "< 4"
27
- spec.add_dependency 'googleauth', '>= 0.6.6', '< 1.0'
28
- spec.add_dependency 'rails', '>= 4.2', '< 6.0'
23
+ spec.add_dependency 'dropbox_api', '>= 0.1.20'
24
+ spec.add_dependency 'google-apis-drive_v3'
25
+ spec.add_dependency 'googleauth', '>= 0.6.6', '< 2.0'
26
+ spec.add_dependency 'rails', '>= 4.2', '< 7.1'
29
27
  spec.add_dependency 'ruby-box'
30
28
  spec.add_dependency 'signet', '~> 0.8'
31
- spec.add_dependency 'sprockets', '~> 3.7'
32
29
  spec.add_dependency 'typhoeus'
33
30
 
34
- spec.add_development_dependency 'bixby', '>= 1.0'
31
+ # Development dependencies include dependencies necessary for running
32
+ # the dummy test app at ./spec/dummy_test_app
33
+
34
+ spec.add_development_dependency 'bixby', '~> 5.0'
35
+ spec.add_development_dependency 'bootstrap', "~> 4.0" # we do not support bootstrap 5
35
36
  spec.add_development_dependency 'bundler', '>= 1.3'
36
37
  spec.add_development_dependency 'capybara'
37
- spec.add_development_dependency 'coveralls'
38
- spec.add_development_dependency 'engine_cart', '~> 2.0'
39
38
  spec.add_development_dependency 'factory_bot_rails'
40
- spec.add_development_dependency 'jasmine', '~> 2.3'
39
+ spec.add_development_dependency 'jquery-rails'
41
40
  spec.add_development_dependency 'pry-byebug'
41
+ spec.add_development_dependency 'puma'
42
42
  spec.add_development_dependency 'rails-controller-testing'
43
43
  spec.add_development_dependency 'rake'
44
44
  spec.add_development_dependency 'rspec', '~> 3.0'
@@ -46,9 +46,10 @@ Gem::Specification.new do |spec|
46
46
  spec.add_development_dependency 'rspec-rails'
47
47
  spec.add_development_dependency 'rspec_junit_formatter'
48
48
  spec.add_development_dependency 'rubocop-rspec'
49
+ spec.add_development_dependency 'sass-rails'
49
50
  spec.add_development_dependency 'selenium-webdriver'
50
- spec.add_development_dependency 'simplecov'
51
51
  spec.add_development_dependency 'sqlite3'
52
+ spec.add_development_dependency 'turbolinks'
52
53
  spec.add_development_dependency 'webdrivers'
53
54
  spec.add_development_dependency 'webmock'
54
55
  end
@@ -17,11 +17,11 @@ module BrowseEverything
17
17
 
18
18
  private
19
19
 
20
- # Structure a hash from existing access token values (usually cached within a Cookie)
21
- # @return [Hash]
22
- def build_token_hash
23
- { 'access_token' => access_token }
24
- end
20
+ # Structure a hash from existing access token values (usually cached within a Cookie)
21
+ # @return [Hash]
22
+ def build_token_hash
23
+ { 'access_token' => access_token }
24
+ end
25
25
  end
26
26
  end
27
27
  end
@@ -14,47 +14,47 @@ module BrowseEverything
14
14
 
15
15
  private
16
16
 
17
- # The default query parameters for the Google Drive API
18
- # @return [Hash]
19
- def default_params
20
- {
21
- q: default_query,
22
- order_by: 'modifiedTime desc,folder,name',
23
- fields: 'nextPageToken,files(name,id,mimeType,size,modifiedTime,parents,web_content_link)',
24
- supports_team_drives: true,
25
- include_team_drive_items: true,
26
- corpora: 'user,allTeamDrives',
27
- page_size: 1000
28
- }
29
- end
17
+ # The default query parameters for the Google Drive API
18
+ # @return [Hash]
19
+ def default_params
20
+ {
21
+ q: default_query,
22
+ order_by: 'modifiedTime desc,folder,name',
23
+ fields: 'nextPageToken,files(name,id,mimeType,size,modifiedTime,parents,web_content_link)',
24
+ supports_team_drives: true,
25
+ include_team_drive_items: true,
26
+ corpora: 'user,allTeamDrives',
27
+ page_size: 1000
28
+ }
29
+ end
30
30
 
31
- def default_query
32
- field_queries = []
33
- contraints.each_pair do |field, constraints|
34
- field_constraint = constraints.join(" and #{field} ")
35
- field_queries << "#{field} #{field_constraint}"
36
- end
37
- field_queries.join(' ')
31
+ def default_query
32
+ field_queries = []
33
+ contraints.each_pair do |field, constraints|
34
+ field_constraint = constraints.join(" and #{field} ")
35
+ field_queries << "#{field} #{field_constraint}"
38
36
  end
37
+ field_queries.join(' ')
38
+ end
39
39
 
40
- def contraints
41
- {
42
- 'mimeType' => [
43
- '!= \'application/vnd.google-apps.audio\'',
44
- '!= \'application/vnd.google-apps.document\'',
45
- '!= \'application/vnd.google-apps.drawing\'',
46
- '!= \'application/vnd.google-apps.form\'',
47
- '!= \'application/vnd.google-apps.fusiontable\'',
48
- '!= \'application/vnd.google-apps.map\'',
49
- '!= \'application/vnd.google-apps.photo\'',
50
- '!= \'application/vnd.google-apps.presentation\'',
51
- '!= \'application/vnd.google-apps.script\'',
52
- '!= \'application/vnd.google-apps.site\'',
53
- '!= \'application/vnd.google-apps.spreadsheet\'',
54
- '!= \'application/vnd.google-apps.video\''
55
- ]
56
- }
57
- end
40
+ def contraints
41
+ {
42
+ 'mimeType' => [
43
+ '!= \'application/vnd.google-apps.audio\'',
44
+ '!= \'application/vnd.google-apps.document\'',
45
+ '!= \'application/vnd.google-apps.drawing\'',
46
+ '!= \'application/vnd.google-apps.form\'',
47
+ '!= \'application/vnd.google-apps.fusiontable\'',
48
+ '!= \'application/vnd.google-apps.map\'',
49
+ '!= \'application/vnd.google-apps.photo\'',
50
+ '!= \'application/vnd.google-apps.presentation\'',
51
+ '!= \'application/vnd.google-apps.script\'',
52
+ '!= \'application/vnd.google-apps.site\'',
53
+ '!= \'application/vnd.google-apps.spreadsheet\'',
54
+ '!= \'application/vnd.google-apps.video\''
55
+ ]
56
+ }
57
+ end
58
58
  end
59
59
  end
60
60
  end
@@ -32,6 +32,7 @@ module BrowseEverything
32
32
  # @param subclass [Class] the class inheriting from BrowseEverything::Driver::Base
33
33
  def inherited(subclass)
34
34
  subclass.sorter = sorter
35
+ super
35
36
  end
36
37
  end
37
38
 
@@ -100,21 +101,21 @@ module BrowseEverything
100
101
 
101
102
  private
102
103
 
103
- # Generate the options for the Rails URL generation for API callbacks
104
- # remove the script_name parameter from the url_options since that is causing issues
105
- # with the route not containing the engine path in rails 4.2.0
106
- # @return [Hash]
107
- def callback_options
108
- options = config.to_hash
109
- options.deep_symbolize_keys!
110
- options[:url_options].reject { |k, _v| k == :script_name }
111
- end
104
+ # Generate the options for the Rails URL generation for API callbacks
105
+ # remove the script_name parameter from the url_options since that is causing issues
106
+ # with the route not containing the engine path in rails 4.2.0
107
+ # @return [Hash]
108
+ def callback_options
109
+ options = config.to_hash
110
+ options.deep_symbolize_keys!
111
+ options[:url_options].reject { |k, _v| k == :script_name }
112
+ end
112
113
 
113
- # Generate the URL for the API callback
114
- # @return [String]
115
- def callback
116
- connector_response_url(callback_options)
117
- end
114
+ # Generate the URL for the API callback
115
+ # @return [String]
116
+ def callback
117
+ connector_response_url(callback_options)
118
+ end
118
119
  end
119
120
  end
120
121
  end
@@ -77,72 +77,72 @@ module BrowseEverything
77
77
 
78
78
  private
79
79
 
80
- def token_expired?
81
- return true if expiration_time.nil?
82
- Time.now.to_i > expiration_time
83
- end
80
+ def token_expired?
81
+ return true if expiration_time.nil?
82
+ Time.now.to_i > expiration_time
83
+ end
84
84
 
85
- def box_client
86
- if token_expired?
87
- session = box_session
88
- register_access_token(session.refresh_token(box_refresh_token))
89
- end
90
- RubyBox::Client.new(box_session)
85
+ def box_client
86
+ if token_expired?
87
+ session = box_session
88
+ register_access_token(session.refresh_token(box_refresh_token))
91
89
  end
90
+ RubyBox::Client.new(box_session)
91
+ end
92
92
 
93
- def session
94
- AuthenticationFactory.new(
95
- self.class.authentication_klass,
96
- client_id: config[:client_id],
97
- client_secret: config[:client_secret],
98
- access_token: box_token,
99
- refresh_token: box_refresh_token
100
- )
101
- end
93
+ def session
94
+ AuthenticationFactory.new(
95
+ self.class.authentication_klass,
96
+ client_id: config[:client_id],
97
+ client_secret: config[:client_secret],
98
+ access_token: box_token,
99
+ refresh_token: box_refresh_token
100
+ )
101
+ end
102
102
 
103
- def authenticate
104
- session.authenticate
105
- end
103
+ def authenticate
104
+ session.authenticate
105
+ end
106
106
 
107
- def box_session
108
- authenticate
109
- end
107
+ def box_session
108
+ authenticate
109
+ end
110
110
 
111
- # If there is an active session, {@token} will be set by {BrowseEverythingController} using data stored in the
112
- # session. However, if there is no prior session, or the token has expired, we reset it here using # a new
113
- # access_token received from {#box_session}.
114
- #
115
- # @param [OAuth2::AccessToken] access_token
116
- def register_access_token(access_token)
117
- @token = {
118
- 'token' => access_token.token,
119
- 'refresh_token' => access_token.refresh_token,
120
- 'expires_at' => access_token.expires_at
121
- }
122
- end
111
+ # If there is an active session, {@token} will be set by {BrowseEverythingController} using data stored in the
112
+ # session. However, if there is no prior session, or the token has expired, we reset it here using # a new
113
+ # access_token received from {#box_session}.
114
+ #
115
+ # @param [OAuth2::AccessToken] access_token
116
+ def register_access_token(access_token)
117
+ @token = {
118
+ 'token' => access_token.token,
119
+ 'refresh_token' => access_token.refresh_token,
120
+ 'expires_at' => access_token.expires_at
121
+ }
122
+ end
123
123
 
124
- def box_token
125
- return unless @token
126
- @token.fetch('token', nil)
127
- end
124
+ def box_token
125
+ return unless @token
126
+ @token.fetch('token', nil)
127
+ end
128
128
 
129
- def box_refresh_token
130
- return unless @token
131
- @token.fetch('refresh_token', nil)
132
- end
129
+ def box_refresh_token
130
+ return unless @token
131
+ @token.fetch('refresh_token', nil)
132
+ end
133
133
 
134
- def expiration_time
135
- return unless @token
136
- @token.fetch('expires_at', nil).to_i
137
- end
134
+ def expiration_time
135
+ return unless @token
136
+ @token.fetch('expires_at', nil).to_i
137
+ end
138
138
 
139
- # Constructs a BrowseEverything::FileEntry object for a Box file
140
- # resource
141
- # @param file [String] ID to the file resource
142
- # @return [BrowseEverything::File]
143
- def directory_entry(file)
144
- BrowseEverything::FileEntry.new(file.id, "#{key}:#{file.id}", file.name, file.size, file.created_at, file.type == 'folder')
145
- end
139
+ # Constructs a BrowseEverything::FileEntry object for a Box file
140
+ # resource
141
+ # @param file [String] ID to the file resource
142
+ # @return [BrowseEverything::File]
143
+ def directory_entry(file)
144
+ BrowseEverything::FileEntry.new(file.id, "#{key}:#{file.id}", file.name, file.size, file.created_at, file.type == 'folder')
145
+ end
146
146
  end
147
147
  end
148
148
  end
@@ -16,14 +16,14 @@ module BrowseEverything
16
16
  class << self
17
17
  private
18
18
 
19
- def klass_for(metadata)
20
- case metadata
21
- when DropboxApi::Metadata::File
22
- FileFactory
23
- else
24
- ResourceFactory
25
- end
19
+ def klass_for(metadata)
20
+ case metadata
21
+ when DropboxApi::Metadata::File
22
+ FileFactory
23
+ else
24
+ ResourceFactory
26
25
  end
26
+ end
27
27
  end
28
28
  end
29
29
 
@@ -124,11 +124,14 @@ module BrowseEverything
124
124
  end
125
125
 
126
126
  def auth_link(url_options)
127
- authenticator.authorize_url redirect_uri: redirect_uri(url_options)
127
+ authenticator.auth_code.authorize_url redirect_uri: redirect_uri(url_options)
128
128
  end
129
129
 
130
130
  def connect(params, _data, url_options)
131
- auth_bearer = authenticator.get_token params[:code], redirect_uri: redirect_uri(url_options)
131
+ built_redirect_uri = redirect_uri(url_options)
132
+ token_code = params[:code]
133
+
134
+ auth_bearer = authenticator.auth_code.get_token(token_code, redirect_uri: built_redirect_uri)
132
135
  self.token = auth_bearer.token
133
136
  end
134
137
 
@@ -138,44 +141,44 @@ module BrowseEverything
138
141
 
139
142
  private
140
143
 
141
- def session
142
- AuthenticationFactory.new(
143
- self.class.authentication_klass,
144
- config[:client_id],
145
- config[:client_secret]
146
- )
147
- end
144
+ def session
145
+ AuthenticationFactory.new(
146
+ self.class.authentication_klass,
147
+ config[:client_id],
148
+ config[:client_secret]
149
+ )
150
+ end
148
151
 
149
- def authenticate
150
- session.authenticate
151
- end
152
+ def authenticate
153
+ session.authenticate
154
+ end
152
155
 
153
- def authenticator
154
- @authenticator ||= authenticate
155
- end
156
+ def authenticator
157
+ @authenticator ||= authenticate
158
+ end
156
159
 
157
- def client
158
- DropboxApi::Client.new(token)
159
- end
160
+ def client
161
+ DropboxApi::Client.new(token)
162
+ end
160
163
 
161
- def redirect_uri(url_options)
162
- connector_response_url(**url_options)
163
- end
164
+ def redirect_uri(url_options)
165
+ connector_response_url(**url_options)
166
+ end
164
167
 
165
- # Ensures that the "tmp" directory is used if there is no default download
166
- # directory specified in the configuration
167
- # @return [String]
168
- def default_download_directory
169
- Rails.root.join('tmp')
170
- end
168
+ # Ensures that the "tmp" directory is used if there is no default download
169
+ # directory specified in the configuration
170
+ # @return [String]
171
+ def default_download_directory
172
+ Rails.root.join('tmp')
173
+ end
171
174
 
172
- # Retrieves the directory path for downloads used when retrieving the
173
- # resource from Dropbox
174
- # @return [String]
175
- def download_directory_path
176
- dir_path = config[:download_directory] || default_download_directory
177
- File.expand_path(dir_path)
178
- end
175
+ # Retrieves the directory path for downloads used when retrieving the
176
+ # resource from Dropbox
177
+ # @return [String]
178
+ def download_directory_path
179
+ dir_path = config[:download_directory] || default_download_directory
180
+ File.expand_path(dir_path)
181
+ end
179
182
  end
180
183
  end
181
184
  end