Class: Worochi::Agent::GoogleDrive
- Inherits:
-
Worochi::Agent
- Object
- Worochi::Agent
- Worochi::Agent::GoogleDrive
- Defined in:
- lib/worochi/agent/google_drive.rb
Overview
The Worochi::Agent for Google Drive API.
Instance Attribute Summary
Attributes inherited from Worochi::Agent
Instance Method Summary collapse
-
#clear_cache ⇒ Object
Clears the internal resource ID cache.
-
#delete(path) ⇒ Boolean
Deletes the file at ‘path` from Google Drive.
-
#init_client ⇒ ApiClient
Initializes the Google Drive API client.
-
#list(path = nil) ⇒ Array<Hash>
Returns a list of files and subdirectories at the remote path specified by ‘options`.
-
#push_item(item) ⇒ String
Pushes an individual item to Google Drive.
Methods inherited from Worochi::Agent
#files, #files_and_folders, #folders, #initialize, #name, new, #push, #push_items, #remove, #set_dir, #set_options, #type
Constructor Details
This class inherits a constructor from Worochi::Agent
Instance Method Details
#clear_cache ⇒ Object
Clears the internal resource ID cache
72 73 74 |
# File 'lib/worochi/agent/google_drive.rb', line 72 def clear_cache @id_cache = {} end |
#delete(path) ⇒ Boolean
Deletes the file at ‘path` from Google Drive.
64 65 66 67 68 69 |
# File 'lib/worochi/agent/google_drive.rb', line 64 def delete(path) abs_path = full_path(path) item_id = get_item_id(abs_path) return false if item_id.nil? delete_by_id(item_id) end |
#init_client ⇒ ApiClient
Initializes the Google Drive API client.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/worochi/agent/google_drive.rb', line 13 def init_client clear_cache disable_write @client = Google::APIClient.new( application_name: 'Worochi', application_version: Worochi::VERSION) @client..access_token = [:token] @drive = @client.discovered_api('drive', 'v2') @client end |
#list(path = nil) ⇒ Array<Hash>
Returns a list of files and subdirectories at the remote path specified by ‘options`.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/worochi/agent/google_drive.rb', line 41 def list(path=nil) remote_path = list_path(path) result, folder_id = navigate_to(remote_path) result.map do |elem| if elem.mimeType == 'application/vnd.google-apps.folder' file_type = 'folder' else file_type = 'file' end { name: elem.title, path: File.join(remote_path, elem.title), type: file_type, id: elem.id, parent_id: folder_id } end end |
#push_item(item) ⇒ String
Pushes an individual item to Google Drive.
27 28 29 30 31 32 33 34 |
# File 'lib/worochi/agent/google_drive.rb', line 27 def push_item(item) enable_write abs_path = full_path(item.path) parent_id = get_parent_id(abs_path) id = insert_file(item, parent_id) disable_write id end |