Class: Boar::Handlers::Downloads::GoogleDrive
- Defined in:
- app/models/boar/handlers/downloads/google_drive.rb
Instance Attribute Summary
Attributes inherited from Base
Attributes inherited from Generic
Instance Method Summary collapse
- #call(path, entry, skip_cache, _, _) ⇒ Object
-
#initialize(service, options) ⇒ GoogleDrive
constructor
A new instance of GoogleDrive.
Methods inherited from Base
#class_key, #credentials_params, #finalize_path, #load_credentials, #update_credentials
Methods included from Utils::Basic
#ensure_hash, #get_option, #interpolate
Constructor Details
#initialize(service, options) ⇒ GoogleDrive
Returns a new instance of GoogleDrive.
11 12 13 14 15 16 |
# File 'app/models/boar/handlers/downloads/google_drive.rb', line 11 def initialize(service, ) super(service, ) configuration = self.load_credentials @client = Boar::Providers::GoogleDrive.(configuration) @api = @client.discovered_api('drive', 'v2') end |
Instance Method Details
#call(path, entry, skip_cache, _, _) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/boar/handlers/downloads/google_drive.rb', line 18 def call(path, entry, skip_cache, _, _) # Read the URL from Redis key = @configuration.backend_key("downloads:google_drive[#{path}]", self, @service.controller.request) url = @configuration.backend.get(key) if skip_cache || url.blank? then begin # Get the file result = @client.execute(api_method: @api.files.get, parameters: {"fileId" => entry[:id]}) raise Boar::Exceptions::NotFound if result.status == 404 # Get the share link file = result.data url = file.web_content_link || file.alternate_link url = file.alternate_link if entry["disposition"] == "inline" raise Boar::Exceptions::NotFound if url.blank? # Save the URL @configuration.backend.set(key, url) if url.present? rescue => e raise Boar::Exceptions::ServerError.new("[#{e.class}] #{e.}") end end # Redirect to the final URL @service.controller.redirect_to(url) end |