Class: CloudDoor::GoogleDrive
- Inherits:
-
CloudStorage
- Object
- CloudStorage
- CloudDoor::GoogleDrive
- 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
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#file_id ⇒ Object
Returns the value of attribute file_id.
-
#file_list ⇒ Object
Returns the value of attribute file_list.
-
#file_name ⇒ Object
Returns the value of attribute file_name.
-
#mkdir_name ⇒ Object
Returns the value of attribute mkdir_name.
-
#parent_id ⇒ Object
Returns the value of attribute parent_id.
-
#token ⇒ Object
Returns the value of attribute token.
-
#up_file_name ⇒ Object
Returns the value of attribute up_file_name.
Attributes inherited from CloudStorage
Instance Method Summary collapse
- #create_login_client ⇒ Object
-
#initialize(session_id = nil) ⇒ GoogleDrive
constructor
A new instance of GoogleDrive.
- #load_token ⇒ Object
- #login(login_account, login_password) ⇒ Object
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
#account ⇒ Object (readonly)
Returns the value of attribute account.
10 11 12 |
# File 'lib/cloud_door/google_drive.rb', line 10 def account @account end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/cloud_door/google_drive.rb', line 10 def config @config end |
#file_id ⇒ Object
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_list ⇒ Object
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_name ⇒ Object
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_name ⇒ Object
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_id ⇒ Object
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 |
#token ⇒ Object
Returns the value of attribute token.
8 9 10 |
# File 'lib/cloud_door/google_drive.rb', line 8 def token @token end |
#up_file_name ⇒ Object
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_client ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/cloud_door/google_drive.rb', line 71 def create_login_client client = Google::APIClient.new client..client_id = @config.client_id client..client_secret = @config.client_secret client..scope = OAUTH_SCOPE client..redirect_uri = @config.redirect_url client end |
#load_token ⇒ Object
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 login(login_account, login_password) @account.login_account = login_account @account.login_password = login_password client = create_login_client code = login_browser(client...to_s) client..code = code client..fetch_access_token! credentials = client. 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 |