Module: Admin::Atreides::DropboxHelper

Includes:
Atreides::Extendable
Included in:
DropboxController, PhotosController
Defined in:
app/helpers/admin/atreides/dropbox_helper.rb

Instance Method Summary collapse

Instance Method Details

#basename(path) ⇒ Object



37
38
39
# File 'app/helpers/admin/atreides/dropbox_helper.rb', line 37

def basename(path)
  path.sub(@dropbox_path, '').sub(/^\//, '')
end


33
34
35
# File 'app/helpers/admin/atreides/dropbox_helper.rb', line 33

def dropbox_authorize_link
  dropbox_session.get_authorize_url(request.url)
end

#dropbox_clientObject



20
21
22
# File 'app/helpers/admin/atreides/dropbox_helper.rb', line 20

def dropbox_client
  DropboxClient.new(dropbox_session, :dropbox) if dropbox_session.authorized?
end

#dropbox_sessionObject



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/admin/atreides/dropbox_helper.rb', line 2

def dropbox_session
  @dropbox_session ||= begin
    previous = session[:dropbox_session] if session[:dropbox_session].present?
    if previous && previous.authorized?
      previous
    elsif previous && params[:oauth_token]
      puts "Trying to authorize an existing dropbox session..."
      previous.get_access_token
      session[:dropbox_session] = previous # re-serialize the authenticated session
    else
      puts "Creating a new Dropbox session..."
      new_dropbox_session.tap do |dropbox_session|
        session[:dropbox_session] = dropbox_session
      end
    end
  end
end

#new_dropbox_sessionObject



24
25
26
27
28
29
30
31
# File 'app/helpers/admin/atreides/dropbox_helper.rb', line 24

def new_dropbox_session
  DropboxSession.new(Settings.dropbox.key, Settings.dropbox.secret).tap do |dropbox_session|
    begin
      dropbox_session.get_request_token
    rescue
    end
  end
end