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



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fastlane/plugin/google_drive/helper/google_drive_helper.rb', line 50

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



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

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



22
23
24
25
26
27
28
# File 'lib/fastlane/plugin/google_drive/helper/google_drive_helper.rb', line 22

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

.file_by_title(root_folder:, title:) ⇒ Object



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

def self.file_by_title(root_folder:, title:)
  file = root_folder.file_by_title(title)
  file
rescue Exception => e
  UI.error(e.message)
  UI.user_error!("File with title '#{title}' not found in Google Drive")
end

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



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

def self.setup(keyfile: nil, key_json: nil, service_account: false)
  keyfile_or_io = keyfile || StringIO.new(key_json || '')

  if 
    ::GoogleDrive::Session.(keyfile_or_io)
  else
    ::GoogleDrive::Session.from_config(keyfile_or_io)
  end
rescue Exception => e
  UI.error(e.message)
  UI.user_error!('Invalid Google Drive credentials')
end

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



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/fastlane/plugin/google_drive/helper/google_drive_helper.rb', line 70

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



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

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