Class: Fastlane::Helper::OvoGptdriverHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/ovo_gptdriver/helper/ovo_gptdriver_helper.rb

Constant Summary collapse

API_BASE_URL =
"https://api.mobileboost.io"

Class Method Summary collapse

Class Method Details

.upload_build(build_path:, organisation_key:, platform:, metadata:) ⇒ Object



13
14
15
16
17
18
19
20
21
22
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
# File 'lib/fastlane/plugin/ovo_gptdriver/helper/ovo_gptdriver_helper.rb', line 13

def self.upload_build(build_path:, organisation_key:, platform:, metadata:)
  UI.message("Starting upload of build '#{build_path}' to GTP Driver...")

  begin
    # Start request using RestClient
    response = RestClient.post(
      "#{API_BASE_URL}/uploadBuild/",
      {
        build: File.new(build_path, 'rb'),        # APK/ZIP/TAR.GZ file
        organisation_key: organisation_key,       # Organization key
        platform: platform,                       # Platform type
        metadata:                         # Metadata as JSON
      },
      { content_type: :multipart }                # Specify multipart/form-data
    )

    json_response = JSON.parse(response.body)
    build_id = json_response["buildId"]

    # If the request is successful (HTTP 2xx)
    UI.success("Build '#{build_path}' uploaded successfully to GPT Driver.\nBuild ID assigned: #{build_id}")

    # Return the build id
    return build_id
  rescue RestClient::ExceptionWithResponse => e
    # Server returned an HTTP error (e.g. 400, 401, 500)
    UI.error(
      "An error occurred while uploading the build '#{build_path}' to GTPDriver.\nStatus Code: #{e.http_code}\nBody: #{e.response}"
    )
    return nil
  rescue StandardError => e
    # Catch any other unexpected error
    UI.error("An unexpected error occurred: #{e.to_s}")
    return nil
  end
end