Class: Fastlane::Helper::RustoreDeveloperHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::RustoreDeveloperHelper
- Defined in:
- lib/fastlane/plugin/rustore_developer/helper/rustore_developer_helper.rb
Constant Summary collapse
- BASE_URL =
'https://public-api.rustore.ru'
Class Method Summary collapse
- .commitVersion(token, package_name, version_id, priority_update = 0) ⇒ Object
- .createVersion(token, package_name, publish_type = 'INSTANTLY', app_type = 'MAIN', whats_new) ⇒ Object
- .deleteDraft(token, package_name, version_id) ⇒ Object
- .getAccessToken(company_id, key_path) ⇒ Object
- .getSignatureEncoded(company_id, timestamp, key_path) ⇒ Object
- .getStatus(token, package_name, version_id, page = 0, size = 10) ⇒ Object
- .getStatusAll(token, package_name, page = 0, size = 100) ⇒ Object
- .getTimestamp ⇒ Object
- .publishVersion(token, package_name, version_id) ⇒ Object
- .uploadAPK(token, package_name, version_id, apk_path, is_main = true, service_type = 'Unknown') ⇒ Object
Class Method Details
.commitVersion(token, package_name, version_id, priority_update = 0) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/fastlane/plugin/rustore_developer/helper/rustore_developer_helper.rb', line 156 def self.commitVersion(token, package_name, version_id, priority_update = 0) UI.important("Committing version #{version_id} ...") uri = URI(BASE_URL + "/public/v1/application/#{package_name}/version/#{version_id}/commit?priorityUpdate=#{priority_update}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Post.new(uri.path) req["Public-Token"] = token puts req.body res = http.request(req) puts res.body result_json = JSON.parse(res.body) if result_json['code'] != 'OK' UI.error("#{result_json['message']}") return false else UI.success "Successfully committed" return true end end |
.createVersion(token, package_name, publish_type = 'INSTANTLY', app_type = 'MAIN', whats_new) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/fastlane/plugin/rustore_developer/helper/rustore_developer_helper.rb', line 50 def self.createVersion(token, package_name, publish_type = 'INSTANTLY', app_type = 'MAIN', whats_new) UI.important("Creating draft version of '#{package_name}' ...") uri = URI(BASE_URL + "/public/v1/application/#{package_name}/version") p uri http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Post.new(uri.path) req["Content-Type"] = "application/json" req["Public-Token"] = token data = {'publishType': publish_type, 'appType': app_type, 'whatsNew': whats_new} req.body = data.to_json # puts req.body res = http.request(req) # puts res.body result_json = JSON.parse(res.body) version = result_json['body'] if result_json['code'] == 'OK' if version.nil? UI.error("#{result_json['message']}") else UI.success "Created new version: #{version}" end return version end |
.deleteDraft(token, package_name, version_id) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fastlane/plugin/rustore_developer/helper/rustore_developer_helper.rb', line 74 def self.deleteDraft(token, package_name, version_id) UI.important("Deleting draft version #{version_id} ...") uri = URI(BASE_URL + "/public/v1/application/#{package_name}/version/#{version_id}") p uri http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Delete.new(uri.path) req["Public-Token"] = token req["Content-Type"] = "application/json" res = http.request(req) result_json = JSON.parse(res.body) if result_json['code'] != 'OK' UI.error("#{result_json['message']}") return false else UI.success "Successfully deleted" return true end end |
.getAccessToken(company_id, key_path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fastlane/plugin/rustore_developer/helper/rustore_developer_helper.rb', line 25 def self.getAccessToken(company_id, key_path) UI.important("Getting access token ...") = getTimestamp() sign = getSignatureEncoded(company_id, , key_path) uri = URI(BASE_URL + '/public/auth/') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Post.new(uri.path) req["Content-Type"] = "application/json" data = {'companyId': company_id, 'timestamp': , 'signature': sign} req.body = data.to_json res = http.request(req) result_json = JSON.parse(res.body) token = result_json['body']['jwe'] if result_json['code'] == 'OK' if token.nil? UI.error("Cannot retrieve access token, please check your credentials.\n#{result_json['message']}") else UI.success 'Got access token' # UI.message token end return token end |
.getSignatureEncoded(company_id, timestamp, key_path) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/fastlane/plugin/rustore_developer/helper/rustore_developer_helper.rb', line 17 def self.getSignatureEncoded(company_id, , key_path) private_key = OpenSSL::PKey.read(File.read(key_path)) data = company_id + signature = private_key.sign("SHA512", data) encoded = Base64.strict_encode64(signature) return encoded end |
.getStatus(token, package_name, version_id, page = 0, size = 10) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/fastlane/plugin/rustore_developer/helper/rustore_developer_helper.rb', line 94 def self.getStatus(token, package_name, version_id, page = 0, size = 10) # METHOD_URL = BASE_URL + "/public/v1/application/#{package_name}/version" if version_id.nil? UI.important("Getting status of \'#{package_name}\' versions on page #{page} ...") uri = URI(BASE_URL + "/public/v1/application/#{package_name}/version?page=#{page}&size=#{size}") else UI.important("Getting status of \'#{package_name}\' version #{version_id} ...") uri = URI(BASE_URL + "/public/v1/application/#{package_name}/version?id=#{version_id}") end p uri http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Get.new(uri.path) req["Public-Token"] = token req["Content-Type"] = "application/json" res = http.request(req) result_json = JSON.parse(res.body) if result_json['code'] == 'OK' content = result_json['body']['content'] totalVersions = result_json['body']['totalElements'] totalPages = result_json['body']['totalPages'] end if content.nil? UI.error("#{result_json['message']}") else if version_id.nil? UI.success "Got #{totalVersions} versions in #{totalPages} pages" else UI.success "Got version info" end end return content end |
.getStatusAll(token, package_name, page = 0, size = 100) ⇒ Object
130 131 132 |
# File 'lib/fastlane/plugin/rustore_developer/helper/rustore_developer_helper.rb', line 130 def self.getStatusAll(token, package_name, page = 0, size = 100) self.getStatus(token, package_name, nil, page, size) end |
.getTimestamp ⇒ Object
12 13 14 15 |
# File 'lib/fastlane/plugin/rustore_developer/helper/rustore_developer_helper.rb', line 12 def self.getTimestamp() return DateTime.now.to_s() # return '2023-08-23T09:00:32.939+03:00' end |
.publishVersion(token, package_name, version_id) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/fastlane/plugin/rustore_developer/helper/rustore_developer_helper.rb', line 176 def self.publishVersion(token, package_name, version_id) UI.important("Publishing version #{version_id} ...") uri = URI(BASE_URL + "/public/v1/application/#{package_name}/version/#{version_id}/publish") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Post.new(uri.path) req["Public-Token"] = token puts req.body res = http.request(req) puts res.body result_json = JSON.parse(res.body) if result_json['code'] != 'OK' return false UI.error("#{result_json['message']}") else UI.success "Successfully published" return true end end |
.uploadAPK(token, package_name, version_id, apk_path, is_main = true, service_type = 'Unknown') ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/fastlane/plugin/rustore_developer/helper/rustore_developer_helper.rb', line 134 def self.uploadAPK(token, package_name, version_id, apk_path, is_main = true, service_type = 'Unknown') UI.important("Uploading APK #{apk_path} ...") # uri = URI(BASE_URL + "/public/v1/application/#{package_name}/version/#{version_id}/apk?isMainApk=#{is_main}&servicesType=#{service_type}") uri = URI(BASE_URL + "/public/v1/application/#{package_name}/version/#{version_id}/apk") p uri http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true req = Net::HTTP::Post.new(uri.path) req["Public-Token"] = token req.set_content_type("multipart/form-data") req.set_form([['file', File.open(apk_path)],['isMainApk', is_main.to_s],['servicesType', service_type]], 'multipart/form-data') res = http.request(req) result_json = JSON.parse(res.body) if result_json['code'] != 'OK' UI.error("#{result_json['message']}") return false else UI.success "APK uploaded" return true end end |