lib/spaceship/tunes/tunes_client.rb in spaceship-0.3.4 vs lib/spaceship/tunes/tunes_client.rb in spaceship-0.4.0
- old
+ new
@@ -15,11 +15,11 @@
# Fetches the latest login URL from iTunes Connect
def login_url
cache_path = "/tmp/spaceship_itc_login_url.txt"
begin
- cached = File.read(cache_path)
+ cached = File.read(cache_path)
rescue Errno::ENOENT
end
return cached if cached
host = "https://itunesconnect.apple.com"
@@ -59,52 +59,52 @@
@cookie = to_use.join(';')
rescue => ex
# User Credentials are wrong
raise InvalidUserCredentialsError.new(response)
end
-
+
return @client
else
# User Credentials are wrong
raise InvalidUserCredentialsError.new(response)
end
end
def handle_itc_response(raw)
return unless raw
- return unless raw.kind_of?Hash
+ return unless raw.kind_of? Hash
data = raw['data'] || raw # sometimes it's with data, sometimes it isn't
-
+
if data.fetch('sectionErrorKeys', []).count == 0 and
- data.fetch('sectionInfoKeys', []).count == 0 and
+ data.fetch('sectionInfoKeys', []).count == 0 and
data.fetch('sectionWarningKeys', []).count == 0
-
+
logger.debug("Request was successful")
end
- def handle_response_hash(hash)
+ handle_response_hash = lambda do |hash|
errors = []
- if hash.kind_of?Hash
+ if hash.kind_of? Hash
hash.each do |key, value|
- errors = errors + handle_response_hash(value)
+ errors = errors + handle_response_hash.call(value)
- if key == 'errorKeys' and value.kind_of?Array and value.count > 0
+ if key == 'errorKeys' and value.kind_of? Array and value.count > 0
errors = errors + value
end
end
- elsif hash.kind_of?Array
+ elsif hash.kind_of? Array
hash.each do |value|
- errors = errors + handle_response_hash(value)
+ errors = errors + handle_response_hash.call(value)
end
else
# We don't care about simple values
end
return errors
end
- errors = handle_response_hash(data)
+ errors = handle_response_hash.call(data)
errors = errors + data.fetch('sectionErrorKeys') if data['sectionErrorKeys']
# Sometimes there is a different kind of error in the JSON response
# e.g. {"warn"=>nil, "error"=>["operation_failed"], "info"=>nil}
different_error = raw.fetch('messages', {}).fetch('error', nil)
@@ -118,29 +118,28 @@
puts data['sectionWarningKeys'] if data['sectionWarningKeys']
return data
end
-
#####################################################
# @!group Applications
#####################################################
def applications
r = request(:get, 'ra/apps/manageyourapps/summary')
parse_response(r, 'data')['summaries']
end
# Creates a new application on iTunes Connect
- # @param name (String): The name of your app as it will appear on the App Store.
+ # @param name (String): The name of your app as it will appear on the App Store.
# This can't be longer than 255 characters.
- # @param primary_language (String): If localized app information isn't available in an
+ # @param primary_language (String): If localized app information isn't available in an
# App Store territory, the information from your primary language will be used instead.
- # @param version (String): The version number is shown on the App Store and should
+ # @param version (String): The version number is shown on the App Store and should
# match the one you used in Xcode.
# @param sku (String): A unique ID for your app that is not visible on the App Store.
- # @param bundle_id (String): The bundle ID must match the one you used in Xcode. It
+ # @param bundle_id (String): The bundle ID must match the one you used in Xcode. It
# can't be changed after you submit your first build.
def create_application!(name: nil, primary_language: nil, version: nil, sku: nil, bundle_id: nil, bundle_id_suffix: nil, company_name: nil)
# First, we need to fetch the data from Apple, which we then modify with the user's values
r = request(:get, 'ra/apps/create/?appType=ios')
data = parse_response(r, 'data')
@@ -158,11 +157,11 @@
r = request(:post) do |req|
req.url 'ra/apps/create/?appType=ios'
req.body = data.to_json
req.headers['Content-Type'] = 'application/json'
end
-
+
data = parse_response(r, 'data')
handle_itc_response(data)
end
def create_version!(app_id, version_number)
@@ -201,11 +200,11 @@
r = request(:post) do |req|
req.url "ra/apps/version/save/#{app_id}?v=#{v_text}"
req.body = data.to_json
req.headers['Content-Type'] = 'application/json'
end
-
+
handle_itc_response(r.body)
end
#####################################################
# @!group Build Trains
@@ -237,14 +236,14 @@
req.headers['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)
end
- def submit_testflight_build_for_review!(# Required:
- app_id: nil,
- train: nil,
- build_number: nil,
+ def submit_testflight_build_for_review!( # Required:
+ app_id: nil,
+ train: nil,
+ build_number: nil,
cancel_other_submissions: false,
# Required Metadata:
changelog: nil,
description: nil,
@@ -269,11 +268,11 @@
end
handle_itc_response(r.body)
build_info = r.body['data']
# Now fill in the values provided by the user
-
+
# First the localised values:
build_info['testInfo']['details'].each do |current|
current['whatsNew']['value'] = changelog
current['description']['value'] = description
current['feedbackEmail']['value'] = feedback_email
@@ -308,24 +307,24 @@
end
handle_itc_response(r.body)
end
end
-
+
#####################################################
# @!group Submit for Review
#####################################################
-
+
def send_app_submission(app_id, data, stage)
raise "app_id is required" unless app_id
r = request(:post) do |req|
req.url "ra/apps/#{app_id}/version/submit/#{stage}"
req.body = data.to_json
req.headers['Content-Type'] = 'application/json'
end
-
+
handle_itc_response(r.body)
parse_response(r, 'data')
end
#####################################################
@@ -335,24 +334,24 @@
url = tester.url[:index]
r = request(:get, url)
parse_response(r, 'data')['testers']
end
- def testers_by_app(tester, app_id)
+ def testers_by_app(tester, app_id)
url = tester.url(app_id)[:index_by_app]
r = request(:get, url)
parse_response(r, 'data')['users']
end
- def create_tester!(tester: nil, email: nil, first_name: nil, last_name: nil)
+ def create_tester!(tester: nil, email: nil, first_name: nil, last_name: nil)
url = tester.url[:create]
raise "Action not provided for this tester type." unless url
tester_data = {
emailAddress: {
value: email
- },
+ },
firstName: {
value: first_name
},
lastName: {
value: last_name
@@ -380,11 +379,11 @@
data = [
{
emailAddress: {
value: tester.email
- },
+ },
firstName: {
value: tester.first_name
},
lastName: {
value: tester.last_name
@@ -413,38 +412,39 @@
def remove_tester_from_app!(tester, app_id)
update_tester_from_app!(tester, app_id, false)
end
- private
- def update_tester_from_app!(tester, app_id, testing)
- url = tester.class.url(app_id)[:update_by_app]
- data = {
- users: [
- {
- emailAddress: {
- value: tester.email
- },
- firstName: {
- value: tester.first_name
- },
- lastName: {
- value: tester.last_name
- },
- testing: {
- value: testing
- }
+ private
+
+ def update_tester_from_app!(tester, app_id, testing)
+ url = tester.class.url(app_id)[:update_by_app]
+ data = {
+ users: [
+ {
+ emailAddress: {
+ value: tester.email
+ },
+ firstName: {
+ value: tester.first_name
+ },
+ lastName: {
+ value: tester.last_name
+ },
+ testing: {
+ value: testing
}
- ]
- }
+ }
+ ]
+ }
- r = request(:post) do |req|
- req.url url
- req.body = data.to_json
- req.headers['Content-Type'] = 'application/json'
- end
-
- data = parse_response(r, 'data')
- handle_itc_response(data)
+ r = request(:post) do |req|
+ req.url url
+ req.body = data.to_json
+ req.headers['Content-Type'] = 'application/json'
end
+
+ data = parse_response(r, 'data')
+ handle_itc_response(data)
+ end
end
-end
\ No newline at end of file
+end