Module: EasyDrive::Files
- Included in:
- Client
- Defined in:
- lib/easy_drive/files.rb
Instance Method Summary collapse
-
#copy(file_id, folder_id, options = {}) ⇒ Google::APIClient::Schema::Drive::V2::File
Creates a copy of the specified file.
-
#get(file_id) ⇒ Google::APIClient::Schema::Drive::V2::File
Gets a file’s metadata by ID.
-
#insert(file_name, folder_id, options = {}) ⇒ Google::APIClient::Schema::Drive::V2::File
(also: #upload)
Insert(Upload) a new file.
Instance Method Details
#copy(file_id, folder_id, options = {}) ⇒ Google::APIClient::Schema::Drive::V2::File
Creates a copy of the specified file
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/easy_drive/files.rb', line 76 def copy(file_id, folder_id, = {}) client = self.client drive = self.drive file = drive.files.copy.request_schema.new({ 'title' => [:title], 'parents' => [{:id => folder_id}] }) result = client.execute( :api_method => drive.files.copy, :body_object => file, :parameters => { 'fileId' => file_id, 'alt' => 'json'}) if result.status == 200 result.data else puts "An error occurred: #{result.data['error']['message']}" end end |
#get(file_id) ⇒ Google::APIClient::Schema::Drive::V2::File
Gets a file’s metadata by ID
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/easy_drive/files.rb', line 9 def get(file_id) client = self.client drive = self.drive result = client.execute( :api_method => drive.files.get, :parameters => { 'fileId' => file_id, 'alt' => 'json'}) if result.status == 200 result.data else puts "An error occurred: #{result.data['error']['message']}" end end |
#insert(file_name, folder_id, options = {}) ⇒ Google::APIClient::Schema::Drive::V2::File Also known as: upload
Insert(Upload) a new file
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/easy_drive/files.rb', line 38 def insert(file_name, folder_id, = {}) client = self.client drive = self.drive file = drive.files.insert.request_schema.new({ 'title' => [:title], 'description' => [:description], 'mimeType' => [:mime_type], 'parents' => [{:id => folder_id}] }) media = Google::APIClient::UploadIO.new(file_name, [:mime_type]) result = client.execute( :api_method => drive.files.insert, :body_object => file, :media => media, :parameters => { 'uploadType' => 'multipart', 'alt' => 'json'}) if result.status == 200 return result.data else puts "An error occurred: #{result.data['error']['message']}" end end |