Class: BrowseEverythingController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- BrowseEverythingController
- Defined in:
- app/controllers/browse_everything_controller.rb
Instance Method Summary collapse
-
#auth ⇒ Object
Action for the OAuth2 callback Authenticate against the API and store the token in the session.
- #index ⇒ Object
- #provider_contents ⇒ Object
- #resolve ⇒ Object
-
#show ⇒ Object
Either render the link to authorization or render the files provider#show method is invoked here.
Instance Method Details
#auth ⇒ Object
Action for the OAuth2 callback Authenticate against the API and store the token in the session
40 41 42 43 |
# File 'app/controllers/browse_everything_controller.rb', line 40 def auth # params contains the access code with with the key :code provider_session.token = provider.connect(params, provider_session.data, ) end |
#index ⇒ Object
22 23 24 |
# File 'app/controllers/browse_everything_controller.rb', line 22 def index render layout: !request.xhr? end |
#provider_contents ⇒ Object
15 16 17 18 19 20 |
# File 'app/controllers/browse_everything_controller.rb', line 15 def provider_contents raise BrowseEverything::NotImplementedError, 'No provider supported' if provider.nil? raise BrowseEverything::NotAuthorizedError, 'Not authorized' unless provider. provider.contents(browse_path) end |
#resolve ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/browse_everything_controller.rb', line 45 def resolve selected_files = params[:selected_files] || [] selected_links = selected_files.collect do |file| provider_key_value, uri = file.split(/:/) provider_key = provider_key_value.to_sym (url, extra) = browser.providers[provider_key].link_for(uri) result = { url: url } result.merge!(extra) unless extra.nil? result end respond_to do |format| format.html { render layout: false } format.json { render json: selected_links } end end |
#show ⇒ Object
Either render the link to authorization or render the files provider#show method is invoked here
28 29 30 31 32 33 34 35 36 |
# File 'app/controllers/browse_everything_controller.rb', line 28 def show render partial: 'files', layout: !request.xhr? rescue StandardError => error reset_provider_session! # Should an error be raised, log the error and redirect the use to reauthenticate logger.warn "Failed to retrieve the hosted files: #{error}" render partial: 'auth', layout: !request.xhr? end |