Class: Ruboty::YMCrawl::DropboxManager
- Inherits:
-
Object
- Object
- Ruboty::YMCrawl::DropboxManager
- Defined in:
- lib/ruboty/ymcrawl/dropbox.rb
Instance Method Summary collapse
- #get_access_token(auth_code) ⇒ Object
- #get_auth_code_url ⇒ Object
- #get_share_link(path) ⇒ Object
-
#initialize(app_key, app_sec) ⇒ DropboxManager
constructor
A new instance of DropboxManager.
- #login(arg_access_token = nil) ⇒ Object
- #put(command) ⇒ Object
Constructor Details
#initialize(app_key, app_sec) ⇒ DropboxManager
Returns a new instance of DropboxManager.
7 8 9 10 11 12 |
# File 'lib/ruboty/ymcrawl/dropbox.rb', line 7 def initialize(app_key, app_sec) @app_key = app_key @app_sec = app_sec @client = nil @access_token = nil end |
Instance Method Details
#get_access_token(auth_code) ⇒ Object
39 40 41 |
# File 'lib/ruboty/ymcrawl/dropbox.rb', line 39 def get_access_token(auth_code) @web_auth.finish(auth_code)[0] end |
#get_auth_code_url ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/ruboty/ymcrawl/dropbox.rb', line 31 def get_auth_code_url puts "web_auth is nil!!!!" if @web_auth == nil puts "@app_key: #{@app_key}" puts "@app_sec: #{@app_sec}" @web_auth = DropboxOAuth2FlowNoRedirect.new(@app_key, @app_sec) = @web_auth.start() end |
#get_share_link(path) ⇒ Object
61 |
# File 'lib/ruboty/ymcrawl/dropbox.rb', line 61 def get_share_link(path) @client.shares(path) end |
#login(arg_access_token = nil) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruboty/ymcrawl/dropbox.rb', line 14 def login(arg_access_token = nil) if not @client.nil? puts "already logged in!" return @access_token end @access_token = arg_access_token begin @client = DropboxClient.new(@access_token) puts "account info: #{@client.account_info()}" return @access_token rescue DropboxError => ex puts "---- access token is invalid ----" return nil end end |
#put(command) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ruboty/ymcrawl/dropbox.rb', line 43 def put(command) fname = command[0] #If the user didn't specifiy the file name, just use the name of the file on disk if command[1] new_name = command[1] else new_name = File.basename(fname) end if fname && !fname.empty? && File.exists?(fname) && (File.ftype(fname) == 'file') && File.stat(fname).readable? #This is where we call the the Dropbox Client pp @client.put_file(new_name, open(fname)) else puts "couldn't find the file #{ fname }" end end |