Class: Boar::Handlers::Downloads::SkyDrive

Inherits:
Base
  • Object
show all
Defined in:
app/models/boar/handlers/downloads/sky_drive.rb

Instance Attribute Summary

Attributes inherited from Base

#options, #provider_options

Attributes inherited from Generic

#configuration, #service

Instance Method Summary collapse

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) ⇒ SkyDrive

Returns a new instance of SkyDrive.



11
12
13
14
15
# File 'app/models/boar/handlers/downloads/sky_drive.rb', line 11

def initialize(service, options)
  super(service, options)

  @client = Boar::Providers::SkyDrive.authorized_client(self.load_credentials, self.credentials_params)
end

Instance Method Details

#call(path, entry, skip_cache, _, _) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/boar/handlers/downloads/sky_drive.rb', line 17

def call(path, entry, skip_cache, _, _)
  # Read the URL from Redis
  key = @configuration.backend_key("downloads:sky_drive[#{path}]", self, @service.controller.request)
  url = @configuration.backend.get(key)

  if skip_cache || url.blank? then
    begin
      # Get the file
      file = @client.get("/" + entry[:id]) rescue nil
      raise Boar::Exceptions::NotFound if file.blank?

      url = entry["disposition"] == "inline" ? file.link : file.download_link
      raise Boar::Exceptions::NotFound if url.blank?

      # Save the URL
      @configuration.backend.set(key, url) if url.present?
    rescue => e
      raise e
      raise Boar::Exceptions::ServerError.new("[#{e.class}] #{e.message}")
    end
  end

  # Redirect to the final URL
  @service.controller.redirect_to(url)
end