Class: Fastlane::Helper::GoogledriveSpquytHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/googledrive_spquyt/helper/googledrive_spquyt_helper.rb

Class Method Summary collapse

Class Method Details

.create_public_url(file) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fastlane/plugin/googledrive_spquyt/helper/googledrive_spquyt_helper.rb', line 40

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



53
54
55
56
57
58
# File 'lib/fastlane/plugin/googledrive_spquyt/helper/googledrive_spquyt_helper.rb', line 53

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



20
21
22
23
24
25
26
# File 'lib/fastlane/plugin/googledrive_spquyt/helper/googledrive_spquyt_helper.rb', line 20

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



9
10
11
12
13
14
15
16
17
18
# File 'lib/fastlane/plugin/googledrive_spquyt/helper/googledrive_spquyt_helper.rb', line 9

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



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fastlane/plugin/googledrive_spquyt/helper/googledrive_spquyt_helper.rb', line 60

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



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fastlane/plugin/googledrive_spquyt/helper/googledrive_spquyt_helper.rb', line 28

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