Class: CloudDoor::Dropbox

Inherits:
CloudStorage show all
Defined in:
lib/cloud_door/dropbox.rb

Constant Summary collapse

LOGIN_COMPONENTS =

dropbox login site components

{
  'account_text_name'   => 'login_email',
  'password_text_name'  => 'login_password',
  'signin_button_class' => 'login-button',
  'accept_button_name'  => 'allow_access',
  'auth_code_id'        => 'auth-code'
}
TIME_PROPERTIES =
%w(client_mtime modified)
CONTENTS_KEY =
'contents'
ROOT_ID =
'/'
STORAGE_NAME =
'Dropbox'

Constants inherited from CloudStorage

CloudStorage::ABSTRACT_METHODS, CloudStorage::PARENT_DIR_PAT, CloudStorage::PICK_METHODS

Instance Attribute Summary collapse

Attributes inherited from CloudStorage

#root_id, #storage_name

Instance Method Summary collapse

Methods inherited from CloudStorage

#assign_upload_file_name, #change_directory, #configuration_init?, #delete_file, #download_file, #file?, #file_exist?, #has_file?, #isset_account?, #make_directory, #method_missing, #reset_token, #show_account, #show_configuration, #show_current_directory, #show_files, #show_property, #show_storage_name, #show_user, #update_account, #update_configuration, #upload_file

Constructor Details

#initialize(session_id = nil) ⇒ Dropbox

Returns a new instance of Dropbox.



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cloud_door/dropbox.rb', line 27

def initialize(session_id = nil)
  @config       = Config.new('dropbox')
  @account      = Account.new('dropbox', @config.data_path)
  @token        = Token.new('dropbox_token', @config.data_path, session_id)
  @file_list    = FileList.new('dropbox_list', @config.data_path, session_id)
  @file_id      = nil
  @root_id      = ROOT_ID
  @storage_name = STORAGE_NAME
  @session_id   = session_id
  @client       = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class CloudDoor::CloudStorage

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



11
12
13
# File 'lib/cloud_door/dropbox.rb', line 11

def 
  @account
end

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/cloud_door/dropbox.rb', line 11

def config
  @config
end

#file_idObject

Returns the value of attribute file_id.



9
10
11
# File 'lib/cloud_door/dropbox.rb', line 9

def file_id
  @file_id
end

#file_listObject

Returns the value of attribute file_list.



9
10
11
# File 'lib/cloud_door/dropbox.rb', line 9

def file_list
  @file_list
end

#file_nameObject

Returns the value of attribute file_name.



9
10
11
# File 'lib/cloud_door/dropbox.rb', line 9

def file_name
  @file_name
end

#mkdir_nameObject

Returns the value of attribute mkdir_name.



9
10
11
# File 'lib/cloud_door/dropbox.rb', line 9

def mkdir_name
  @mkdir_name
end

#parent_idObject

Returns the value of attribute parent_id.



9
10
11
# File 'lib/cloud_door/dropbox.rb', line 9

def parent_id
  @parent_id
end

#tokenObject

Returns the value of attribute token.



9
10
11
# File 'lib/cloud_door/dropbox.rb', line 9

def token
  @token
end

#up_file_nameObject

Returns the value of attribute up_file_name.



9
10
11
# File 'lib/cloud_door/dropbox.rb', line 9

def up_file_name
  @up_file_name
end

Instance Method Details

#load_tokenObject



39
40
41
42
43
44
45
# File 'lib/cloud_door/dropbox.rb', line 39

def load_token
  token_file = File.basename(@token.token_file)
  @token     = Token.load_token(token_file, @config.data_path, @session_id)
  @client    = DropboxBridge.new(@token.access_token)
  # @client    = DropboxClient.new(@token.access_token)
  @token
end

#login(login_account, login_password) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cloud_door/dropbox.rb', line 47

def (, )
  @account.  = 
  @account. = 
  flow = DropboxOAuth2FlowNoRedirect.new(@config.client_id, @config.client_secret)
  code = (flow.start())
  access_token, user_id = flow.finish(code)
  raise NoDataException if access_token.nil?
  @session_id = reset_token({'access_token' => access_token})
  @client = DropboxBridge.new(access_token)
  # @client = DropboxClient.new(access_token)
  items = pull_files
  @file_list.delete_file
  @file_list.write_file_list(items)
  if @config.session_use?
    @session_id
  else
    true
  end
rescue => e
  handle_exception(e)
end