Class: CloudDoor::GoogleDrive

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

Constant Summary collapse

LOGIN_COMPONENTS =

google drive login site components

{
  'account_text_id'  => 'Email',
  'password_text_id' => 'Passwd',
  'signin_button_id' => 'signIn',
  'accept_button_id' => 'submit_approve_access',
  'auth_code_id'     => 'code'
}
TIME_PROPERTY_PAT =
/Date$/
CONTENTS_KEY =
'contents'
ROOT_ID =
'/'
STORAGE_NAME =
'Google Drive'
OAUTH_SCOPE =
'https://www.googleapis.com/auth/drive'

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



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

def initialize(session_id = nil)
  @config       = Config.new('googledrive')
  @account      = Account.new('googledrive', @config.data_path)
  @token        = Token.new('googledrive_token', @config.data_path, session_id)
  @file_list    = FileList.new('googledrive_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/google_drive.rb', line 10

def 
  @account
end

#configObject (readonly)

Returns the value of attribute config.



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

def config
  @config
end

#file_idObject

Returns the value of attribute file_id.



8
9
10
# File 'lib/cloud_door/google_drive.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/google_drive.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/google_drive.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/google_drive.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/google_drive.rb', line 8

def parent_id
  @parent_id
end

#tokenObject

Returns the value of attribute token.



8
9
10
# File 'lib/cloud_door/google_drive.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/google_drive.rb', line 8

def up_file_name
  @up_file_name
end

Instance Method Details

#create_login_clientObject



71
72
73
74
75
76
77
78
# File 'lib/cloud_door/google_drive.rb', line 71

def 
  client = Google::APIClient.new
  client.authorization.client_id = @config.client_id
  client.authorization.client_secret = @config.client_secret
  client.authorization.scope = OAUTH_SCOPE
  client.authorization.redirect_uri = @config.redirect_url
  client
end

#load_tokenObject



39
40
41
42
43
44
45
# File 'lib/cloud_door/google_drive.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    = GoogleDriveBridge.new(Marshal.load(@token.credentials))
  @root_id   = request_root_id
  @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
68
69
# File 'lib/cloud_door/google_drive.rb', line 47

def (, )
  @account.  = 
  @account. = 
  client = 
  code   = (client.authorization.authorization_uri.to_s)
  client.authorization.code = code
  client.authorization.fetch_access_token!
  credentials = client.authorization
  raise NoDataException if credentials.nil?
  @session_id = reset_token({'credentials' => Marshal.dump(credentials)})
  @client     = GoogleDriveBridge.new(credentials)
  @root_id    = request_root_id
  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