Class: CloudDoor::OneDrive

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

Constant Summary collapse

ROOT_ID =

user root file_id

'me/skydrive'
LOGIN_COMPONENTS =

onedrive login site components

{
  'account_text_name'  => 'login',
  'password_text_name' => 'passwd',
  'signin_button_id'   => 'idSIButton9',
  'accept_button_id'   => 'idBtn_Accept'
}
TIME_PROPERTY_PAT =
/_time$/
STORAGE_NAME =
'OneDrive'

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

Returns a new instance of OneDrive.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cloud_door/onedrive.rb', line 24

def initialize(session_id = nil)
  @config       = Config.new('onedrive')
  @account      = Account.new('onedrive', @config.data_path)
  @token        = Token.new('onedrive_token', @config.data_path, session_id)
  @file_list    = FileList.new('onedrive_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.



10
11
12
# File 'lib/cloud_door/onedrive.rb', line 10

def 
  @account
end

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/cloud_door/onedrive.rb', line 10

def config
  @config
end

#file_idObject

Returns the value of attribute file_id.



8
9
10
# File 'lib/cloud_door/onedrive.rb', line 8

def file_id
  @file_id
end

#file_listObject

Returns the value of attribute file_list.



8
9
10
# File 'lib/cloud_door/onedrive.rb', line 8

def file_list
  @file_list
end

#file_nameObject

Returns the value of attribute file_name.



8
9
10
# File 'lib/cloud_door/onedrive.rb', line 8

def file_name
  @file_name
end

#mkdir_nameObject

Returns the value of attribute mkdir_name.



8
9
10
# File 'lib/cloud_door/onedrive.rb', line 8

def mkdir_name
  @mkdir_name
end

#parent_idObject

Returns the value of attribute parent_id.



8
9
10
# File 'lib/cloud_door/onedrive.rb', line 8

def parent_id
  @parent_id
end

#tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/cloud_door/onedrive.rb', line 8

def token
  @token
end

#up_file_nameObject

Returns the value of attribute up_file_name.



8
9
10
# File 'lib/cloud_door/onedrive.rb', line 8

def up_file_name
  @up_file_name
end

Instance Method Details

#load_tokenObject



36
37
38
39
40
41
# File 'lib/cloud_door/onedrive.rb', line 36

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

#login(login_account, login_password) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/cloud_door/onedrive.rb', line 53

def (, )
  @account.  = 
  @account. = 
  url  = 
  info = request_get_token(url)
  raise NoDataException if info.nil?
  @session_id = reset_token(info)
  @client = OneDriveApi.new(@token.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

#refresh_tokenObject



43
44
45
46
47
48
49
50
51
# File 'lib/cloud_door/onedrive.rb', line 43

def refresh_token
  raise TokenClassException unless @token.is_a?(Token)
  info = request_refresh_token
  raise NoDataException if info.nil?
  @token.set_attributes(info)
  @token.write_token
rescue => e
  handle_exception(e)
end