Class: Fastlane::Helper::RustoreHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/rustore/helper/rustore_helper.rb

Class Method Summary collapse

Class Method Details

.commit_version(token, draft_id, package_name) ⇒ Object



100
101
102
103
104
105
106
107
# File 'lib/fastlane/plugin/rustore/helper/rustore_helper.rb', line 100

def self.commit_version(token, draft_id, package_name)
  url = "/public/v1/application/#{package_name}/version/#{draft_id}/commit"
  response = connection.post(url) do |req|
    req.headers['Public-Token'] = token
  end

  UI.message("Debug: response #{response.body}")
end

.connectionObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fastlane/plugin/rustore/helper/rustore_helper.rb', line 17

def self.connection
  require 'faraday'
  require 'faraday_middleware'

  options = {
    url: "https://public-api.rustore.ru"
  }

  logger = Logger.new($stderr)
  logger.level = Logger::DEBUG

  Faraday.new(options) do |builder|
    builder.request(:multipart)
    builder.request(:json)
    builder.request(:url_encoded)
    builder.response(:json, content_type: /\bjson$/)
    builder.response(:logger, logger)
    builder.use(FaradayMiddleware::FollowRedirects)
    builder.adapter(:net_http)
  end
end

.create_draft(token, package_name, version_name) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fastlane/plugin/rustore/helper/rustore_helper.rb', line 58

def self.create_draft(token, package_name, version_name)
  url = "/public/v1/application/#{package_name}/version"
  response = connection.post(url) do |req|
    req.headers['Public-Token'] = token
    req.body = { appName: version_name }
  end

  UI.message("Debug: response #{response.body}")

  response.body["body"]
end

.delete_draft(token, draft_id, package_name) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/fastlane/plugin/rustore/helper/rustore_helper.rb', line 70

def self.delete_draft(token, draft_id, package_name)
  url = "/public/v1/application/#{package_name}/version/#{draft_id}"
  response = connection.delete(url) do |req|
    req.headers['Public-Token'] = token
  end

  UI.message("Debug: response #{response.body}")
end

.get_token(company_id:, private_key:) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/fastlane/plugin/rustore/helper/rustore_helper.rb', line 45

def self.get_token(company_id:, private_key:)
  timestamp = DateTime.now.iso8601(3)
  signature = rsa_sign(timestamp, company_id, private_key)
  url = "/public/auth/"
  response = connection.post(url) do |req|
    req.body = { companyId: company_id, timestamp: timestamp, signature: signature }
  end

  UI.message("Debug: response #{response.body}")

  response.body["body"]["jwe"]
end

.rsa_sign(timestamp, company_id, private_key) ⇒ Object



39
40
41
42
43
# File 'lib/fastlane/plugin/rustore/helper/rustore_helper.rb', line 39

def self.rsa_sign(timestamp, company_id, private_key)
  key = OpenSSL::PKey::RSA.new("-----BEGIN RSA PRIVATE KEY-----\n#{private_key}\n-----END RSA PRIVATE KEY-----")
  signature = key.sign(OpenSSL::Digest.new('SHA512'), company_id + timestamp)
  Base64.encode64(signature)
end

.show_messageObject

class methods that you define here become available in your action as ‘Helper::RustoreHelper.your_method`



13
14
15
# File 'lib/fastlane/plugin/rustore/helper/rustore_helper.rb', line 13

def self.show_message
  UI.message("Hello from the rustore plugin helper!")
end

.upload_apk(token, draft_id, is_hms, file_path, package_name) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fastlane/plugin/rustore/helper/rustore_helper.rb', line 79

def self.upload_apk(token, draft_id, is_hms, file_path, package_name)
  if is_hms
    apk_type = "HMS"
    is_main = false
  else
    apk_type = "Unknown"
    is_main = true
  end

  url = "/public/v1/application/#{package_name}/version/#{draft_id}/apk"
  payload = { servicesType: apk_type, isMainApk: is_main }
  payload[:file] = Faraday::Multipart::FilePart.new(file_path, 'application/vnd.android.package-archive')

  response = connection.post(url) do |req|
    req.headers['Public-Token'] = token
    req.body = payload
  end

  UI.message("Debug: response #{response.body}")
end