Class: Fastlane::Helper::GoogleDriveHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/google_drive/helper/google_drive_helper.rb

Class Method Summary collapse

Class Method Details

.create_public_url(file) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/fastlane/plugin/google_drive/helper/google_drive_helper.rb', line 39

def self.create_public_url(file)
  raise "Not Google Drive file" unless file.kind_of?(::GoogleDrive::File)

  begin
    file.acl.push(type: "anyone", role: "reader")
    file.
    file.human_url
  rescue Exception => e
    UI.error(e.message)
    UI.user_error!("Create public link for '#{file.resource_id}' failed")
  end
end

.create_subcollection(root_folder:, title:) ⇒ Object



52
53
54
55
56
57
# File 'lib/fastlane/plugin/google_drive/helper/google_drive_helper.rb', line 52

def self.create_subcollection(root_folder:, title:)
  root_folder.create_subcollection(title)
rescue Exception => e
  UI.error(e.message)
  UI.user_error!("Create '#{title}' failed")
end

.file_by_id(session: nil, fid: nil) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/fastlane/plugin/google_drive/helper/google_drive_helper.rb', line 19

def self.file_by_id(session: nil, fid: nil)
  file = session.file_by_id(fid)
  file
rescue Exception => e
  UI.error(e.message)
  UI.user_error!("File with id '#{fid}' not found in Google Drive")
end

.setup(keyfile: nil, service_account: false) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/fastlane/plugin/google_drive/helper/google_drive_helper.rb', line 8

def self.setup(keyfile: nil, service_account: false)
  if 
    ::GoogleDrive::Session.(keyfile)
  else
    ::GoogleDrive::Session.from_config(keyfile)
  end
rescue Exception => e
  UI.error(e.message)
  UI.user_error!('Invalid Google Drive credentials')
end

.update_file(file: nil, file_name: nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fastlane/plugin/google_drive/helper/google_drive_helper.rb', line 59

def self.update_file(file: nil, file_name: nil)
  raise "Not a Google Drive file" unless file.kind_of?(::GoogleDrive::File)

  begin
    file = file.update_from_file(file_name)
    file
  rescue Exception => e
    UI.error(e.message)
    UI.user_error!("Upload '#{file_name}' failed")
  end
end

.upload_file(file: nil, file_name: nil, title: nil) ⇒ Object



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

def self.upload_file(file: nil, file_name: nil, title: nil)
  raise "Not Google Drive file" unless file.kind_of?(::GoogleDrive::File)

  begin
    file = file.upload_from_file(file_name, title, convert: false)
    file
  rescue Exception => e
    UI.error(e.message)
    UI.user_error!("Upload '#{file_name}' failed")
  end
end