Class: Fastlane::Helper::TestingbotHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::TestingbotHelper
- Defined in:
- lib/fastlane/plugin/testingbot/helper/testingbot_helper.rb
Constant Summary collapse
- API_BASE_URL =
'https://api.testingbot.com'.freeze
- UPLOAD_TIMEOUT =
App binaries can be large; mirror the official TestingBot Ruby client's generous read timeout.
600- OPEN_TIMEOUT =
30
Class Method Summary collapse
- .error_reason(response) ⇒ Object
- .parse_json(raw) ⇒ Object
- .parse_success(response) ⇒ Object
-
.upload(key, secret, path, file_path: nil, remote_url: nil) ⇒ Hash
Uploads (or replaces) an app on TestingBot Storage.
Class Method Details
.error_reason(response) ⇒ Object
55 56 57 58 59 |
# File 'lib/fastlane/plugin/testingbot/helper/testingbot_helper.rb', line 55 def self.error_reason(response) body = response ? parse_json(response.body) : nil = body.is_a?(Hash) && (body['error'] || body['message']) || (response && "HTTP #{response.code}") || 'unknown error' end |
.parse_json(raw) ⇒ Object
61 62 63 64 65 |
# File 'lib/fastlane/plugin/testingbot/helper/testingbot_helper.rb', line 61 def self.parse_json(raw) JSON.parse(raw.to_s) rescue JSON::ParserError nil end |
.parse_success(response) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/fastlane/plugin/testingbot/helper/testingbot_helper.rb', line 48 def self.parse_success(response) body = parse_json(response.body) UI.user_error!('App upload to TestingBot failed: could not parse the server response') unless body.is_a?(Hash) body end |
.upload(key, secret, path, file_path: nil, remote_url: nil) ⇒ Hash
Uploads (or replaces) an app on TestingBot Storage.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/fastlane/plugin/testingbot/helper/testingbot_helper.rb', line 24 def self.upload(key, secret, path, file_path: nil, remote_url: nil) file = file_path ? File.new(file_path, 'rb') : nil payload = file ? { multipart: true, file: file } : { url: remote_url } response = RestClient::Request.execute( method: :post, url: "#{API_BASE_URL}#{path}", user: key, password: secret, payload: payload, headers: { 'User-Agent' => "fastlane-plugin-testingbot/#{Fastlane::Testingbot::VERSION}" }, timeout: UPLOAD_TIMEOUT, open_timeout: OPEN_TIMEOUT ) parse_success(response) rescue RestClient::ExceptionWithResponse => e UI.user_error!("App upload to TestingBot failed: #{error_reason(e.response)}") rescue StandardError => e UI.user_error!("App upload to TestingBot failed: #{e.}") ensure file&.close end |