Class: Fastlane::Helper::BrowserstackHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/browserstack/helper/browserstack_helper.rb

Class Method Summary collapse

Class Method Details

.show_messageObject

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


12
13
14
# File 'lib/fastlane/plugin/browserstack/helper/browserstack_helper.rb', line 12

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

.upload_file(browserstack_username, browserstack_access_key, file_path, url, custom_id = nil) ⇒ Object

Uploads file to BrowserStack Params :

browserstack_username

BrowserStack's username.

browserstack_access_key

BrowserStack's access key.

custom_id

Custom id for app upload.

file_path

Path to the file to be uploaded.

url

BrowserStack's app upload endpoint.


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fastlane/plugin/browserstack/helper/browserstack_helper.rb', line 23

def self.upload_file(browserstack_username, browserstack_access_key, file_path, url, custom_id = nil)
  payload = {
    multipart: true,
    file: File.new(file_path, 'rb')
  }

  unless custom_id.nil?
    payload[:data] = '{ "custom_id": "' + custom_id + '" }'
  end

  headers = {
    "User-Agent" => "browserstack_fastlane_plugin"
  }
  begin
    response = RestClient::Request.execute(
      method: :post,
      url: url,
      user: browserstack_username,
      password: browserstack_access_key,
      payload: payload,
      headers: headers
    )

    response_json = JSON.parse(response.to_s)

    if !response_json["custom_id"].nil?
      return response_json["custom_id"]
    else
      return response_json["app_url"]
    end
  rescue RestClient::ExceptionWithResponse => err
    begin
      error_response = JSON.parse(err.response.to_s)["error"]
    rescue
      error_response = "Internal server error"
    end
    # Give error if upload failed.
    UI.user_error!("App upload failed!!! Reason : #{error_response}")
  rescue StandardError => error
    UI.user_error!("App upload failed!!! Reason : #{error.message}")
  end
end