Class: Boar::Handlers::Downloads::Dropbox
- Defined in:
- app/models/boar/handlers/downloads/dropbox.rb
Instance Attribute Summary
Attributes inherited from Base
Attributes inherited from Generic
Instance Method Summary collapse
- #call(path, entry, skip_cache, _, _) ⇒ Object
- #direct_shares(path) ⇒ Object
-
#initialize(service, options) ⇒ Dropbox
constructor
A new instance of Dropbox.
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) ⇒ Dropbox
Returns a new instance of Dropbox.
11 12 13 14 15 16 17 |
# File 'app/models/boar/handlers/downloads/dropbox.rb', line 11 def initialize(service, ) super(service, ) @session = ::DropboxSession.deserialize(load_credentials[:session]) @root = @provider_options.fetch(:root, "dropbox").to_sym @client = ::DropboxClient.new(@session, @root) end |
Instance Method Details
#call(path, entry, skip_cache, _, _) ⇒ Object
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 45 46 47 48 49 |
# File 'app/models/boar/handlers/downloads/dropbox.rb', line 19 def call(path, entry, skip_cache, _, _) # Read the URL from Redis key = @configuration.backend_key("downloads:dropbox[#{path}]", self, @service.controller.request) url = @configuration.backend.get(key) if skip_cache || url.blank? then begin = entry[:disposition] != "inline" share = ? self.direct_shares(entry[:path]) : @client.shares(entry[:path]) url = share["url"] + ( ? "?dl=1" : "") expire = DateTime.parse(share["expires"], "%a, %d %b %Y %T %Z") # Save the URL if url.present? then @configuration.backend.set(key, url) @configuration.backend.expire(key, expire.to_i) end rescue => e if e. =~ /Path .+ not found/ then raise Boar::Exceptions::NotFound.new(path) else raise e raise Boar::Exceptions::ServerError.new("[#{e.class}] #{e.}") end end end # Redirect to the final URL @service.controller.redirect_to(url) end |
#direct_shares(path) ⇒ Object
51 52 53 54 55 |
# File 'app/models/boar/handlers/downloads/dropbox.rb', line 51 def direct_shares(path) # Get the public URL - We don't use Dropbox shares method directly because we have to pass a parameter response = @session.do_get@client.build_url("/shares/#{@root}#{@client.format_path(path)}?short_url=false") @client.parse_response(response) end |