Class: Dropbox::Archive::Authorization

Inherits:
Object
  • Object
show all
Defined in:
lib/dropbox/archive/authorization.rb

Instance Method Summary collapse

Constructor Details

#initializeAuthorization

Returns a new instance of Authorization.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dropbox/archive/authorization.rb', line 7

def initialize
  DropboxOAuth2FlowNoRedirect.new(
    Dropbox::Archive.config.get("dropbox_app_key"),
    Dropbox::Archive.config.get("dropbox_app_secret")
  ).tap do |flow|
    authorize_url = flow.start

    puts "Please authorize this application at: #{authorize_url}"
    puts "Enter authorization code:"
    authorization_code = $stdin.gets.chomp

    access_token, user_id = flow.finish(authorization_code)
    Dropbox::Archive.config.set("dropbox_access_token", access_token)
  end

  puts "Welcome, #{Dropbox::Archive.client.['display_name']}!"
  Dropbox::Archive.client
end