Module: UploadService

Defined in:
lib/fastlane/plugin/appcircle_enterprise_app_store/helper/upload_service.rb

Class Method Summary collapse

Class Method Details

.getAppVersions(auth_token:, entProfileId:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/helper/upload_service.rb', line 30

def self.getAppVersions(auth_token:, entProfileId:)
  url = "#{BASE_URL}/store/v2/profiles/#{entProfileId}/app-versions"

  # Set up the headers with authentication
  headers = {
    Authorization: "Bearer #{auth_token}",
    accept: 'application/json'
  }

  begin
    response = RestClient.get(url, headers)
    parsed_response = JSON.parse(response.body)

    parsed_response
  rescue RestClient::ExceptionWithResponse => e
    raise e
  rescue StandardError => e
    raise e
  end
end

.getEntProfiles(authToken:) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/helper/upload_service.rb', line 85

def self.getEntProfiles(authToken:)
  url = "#{BASE_URL}/store/v2/profiles?Sort=desc"
  headers = {
    Authorization: "Bearer #{authToken}",
    accept: 'application/json'
  }

  begin
    response = RestClient.get(url, headers)
    parsed_response = JSON.parse(response.body)

    parsed_response
  rescue RestClient::ExceptionWithResponse => e
    raise e
  rescue StandardError => e
    raise e
  end
end

.getProfileId(authToken:) ⇒ Object



104
105
106
107
108
109
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/helper/upload_service.rb', line 104

def self.getProfileId(authToken:)
  profiles = self.getEntProfiles(authToken: authToken)
  sortedProfiles = profiles.sort_by { |profile| DateTime.parse(profile["lastBinaryReceivedDate"]) }.reverse

  return sortedProfiles[0]['id']
end

.getVersionId(versionList:) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/helper/upload_service.rb', line 51

def self.getVersionId(versionList:)
  begin
    if versionList.is_a?(Array) && !versionList.empty?
      return versionList[0]["id"]
    else
      return nil
    end
  rescue => e
    puts "An error occurred while getting app versions: #{e.message}"
    raise e
  end
end

.publishVersion(options) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/helper/upload_service.rb', line 64

def self.publishVersion(options)
  endpoint = "store/v2/profiles/#{options[:ent_profile_id]}/app-versions/#{options[:ent_version_id]}?action=publish"
  url = "#{BASE_URL}/#{endpoint}"

  payload = {
    summary: options[:summary],
    releaseNotes: options[:release_notes],
    publishType: options[:publish_type]
  }

  headers = {
    'Content-Type': 'application/json',
    'Authorization': "Bearer #{options[:auth_token]}"
  }

  response = RestClient.patch(url, payload.to_json, headers)
  JSON.parse(response.body)
rescue RestClient::ExceptionWithResponse => e
  raise e
end

.upload_artifact(token:, app:) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fastlane/plugin/appcircle_enterprise_app_store/helper/upload_service.rb', line 10

def self.upload_artifact(token:, app:)
  url = "https://api.appcircle.io/store/v2/profiles/app-versions"
  headers = {
    Authorization: "Bearer #{token}",
    content_type: :multipart
  }
  payload = {
    File: File.new(app, 'rb')
  }

  begin
    response = RestClient.post(url, payload, headers)
    JSON.parse(response.body) rescue response.body
  rescue RestClient::ExceptionWithResponse => e
    raise e
  rescue StandardError => e
    raise e
  end
end