Class: Fastlane::Helper::GalaxyStoreDeveloperHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/galaxy_store_developer/helper/galaxy_store_developer_helper.rb

Constant Summary collapse

BASE_URL =
'https://devapi.samsungapps.com'

Class Method Summary collapse

Class Method Details

.create_upload_session(service_account_id, access_token) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/fastlane/plugin/galaxy_store_developer/helper/galaxy_store_developer_helper.rb', line 101

def self.create_upload_session(, access_token)
  UI.message("Creating upload session ...")


  uri = URI(BASE_URL + '/seller/createUploadSessionId')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  req = Net::HTTP::Post.new(uri.path)
  req['Authorization'] = "Bearer #{access_token}"
  req['service-account-id'] = "#{}"
  res = http.request(req)

  result_json = JSON.parse(res.body)
  session_id = result_json['sessionId']
  UI.error("Failed") if session_id.nil?

  return session_id

end

.get_access_token(service_account_id, scope, key_path) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fastlane/plugin/galaxy_store_developer/helper/galaxy_store_developer_helper.rb', line 32

def self.get_access_token(, scope, key_path)
  jwt = generate_jwt(scope, key_path, )
  UI.important("Getting access token ...")

  uri = URI(BASE_URL + '/auth/accessToken')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  req = Net::HTTP::Post.new(uri.path, {'Authorization' => "Bearer #{jwt}"})
  res = http.request(req)

  result_json = JSON.parse(res.body)
  token = result_json['createdItem']['accessToken']
  if token.nil?
    UI.error("Cannot retrieve access token, please check your credentials")
  else
    UI.success 'Access token generated'
    # UI.message token
  end
  return token

end

.get_app_info(service_account_id, access_token, content_id) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/fastlane/plugin/galaxy_store_developer/helper/galaxy_store_developer_helper.rb', line 84

def self.get_app_info(, access_token, content_id)
  UI.message("Getting info of the app ...")

  uri = URI(BASE_URL + '/seller/contentInfo')
  params = {:contentId => content_id}
  uri.query = URI.encode_www_form(params)
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  req = Net::HTTP::Get.new(uri)
  req["Authorization"] = "Bearer #{access_token}"
  req["service-account-id"] = 
  res = http.request(req)

  result_json = JSON.parse(res.body)
  return result_json
end

.get_apps_list(service_account_id, access_token) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/fastlane/plugin/galaxy_store_developer/helper/galaxy_store_developer_helper.rb', line 69

def self.get_apps_list(, access_token)
  UI.message("Listing all apps on the account ...")

  uri = URI(BASE_URL + '/seller/contentList')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  req = Net::HTTP::Get.new(uri.path)
  req["Authorization"] = "Bearer #{access_token}"
  req["service-account-id"] = 
  res = http.request(req)
  UI.success 'Listing done' if res.code == '200'
  result_json = JSON.parse(res.body)
  return result_json
end

.is_token_valid?(service_account_id, access_token) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/fastlane/plugin/galaxy_store_developer/helper/galaxy_store_developer_helper.rb', line 54

def self.is_token_valid?(, access_token)
  UI.message("Validating access token ...")

  uri = URI(BASE_URL + '/auth/checkAccessToken')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  req = Net::HTTP::Get.new(uri.path)
  req["Authorization"] = "Bearer #{access_token}"
  req["service-account-id"] = 
  res = http.request(req)

  result_json = JSON.parse(res.body)
  return result_json['ok']
end

.modify_app(service_account_id, access_token, json_body) ⇒ Object

register binary



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/fastlane/plugin/galaxy_store_developer/helper/galaxy_store_developer_helper.rb', line 150

def self.modify_app(, access_token, json_body)
  UI.message("Modifying app ...")

  uri = URI(BASE_URL + '/seller/contentUpdate')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  req = Net::HTTP::Post.new(uri.path)
  req['Authorization'] = "Bearer #{access_token}"
  req['service-account-id'] = "#{}"
  req.set_content_type("application/json")
  req.body = json_body
  res = http.request(req)
  result_json = JSON.parse(res.body)
  if result_json['contentStatus'] == 'REGISTERING'
    UI.success 'App modified'
  else
    UI.error("Modification failed")
    UI.error(result_json['errorCode'])
    UI.error(result_json['errorMsg'])
  end

end

.submit_app(service_account_id, access_token, content_id) ⇒ Object

Apps must be in the REGISTERING state before they can be submitted.



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/fastlane/plugin/galaxy_store_developer/helper/galaxy_store_developer_helper.rb', line 174

def self.submit_app(, access_token, content_id)
  UI.important("Submitting app for review ...")

  uri = URI(BASE_URL + '/seller/contentSubmit')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  req = Net::HTTP::Post.new(uri.path)
  req['Authorization'] = "Bearer #{access_token}"
  req['service-account-id'] = "#{}"
  req.set_content_type("application/json")
  req.body = {contentId: "#{content_id}"}.to_json
  res = http.request(req)
  if res.code == '204'
    UI.success "App submitted"
  else
    UI.error 'App submission failed'
  end

end

.upload_file(service_account_id, access_token, session_id, file_path) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/fastlane/plugin/galaxy_store_developer/helper/galaxy_store_developer_helper.rb', line 122

def self.upload_file(, access_token, session_id, file_path)
  UI.message("Uploading file ...")

  uri = URI('https://seller.samsungapps.com/galaxyapi/fileUpload')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  req = Net::HTTP::Post.new(uri.path)
  req['Authorization'] = "Bearer #{access_token}"
  req['service-account-id'] = "#{}"
  req.set_content_type("multipart/form-data")
  req.set_form([['file', File.open(file_path)], ['sessionId', session_id]], 'multipart/form-data')
  res = http.request(req)
  result_json = JSON.parse(res.body)

  file_key = result_json['fileKey']
  if file_key.nil?
    UI.error("Upload failed")
    UI.error(result_json['errorCode'])
    UI.error(result_json['errorMsg'])
  else
    UI.success 'File uploaded'
  end

  return file_key

end