lib/spaceship/tunes/tunes_client.rb in spaceship-0.6.1 vs lib/spaceship/tunes/tunes_client.rb in spaceship-0.7.0
- old
+ new
@@ -4,10 +4,16 @@
# ITunesConnectError is only thrown when iTunes Connect raises an exception
class ITunesConnectError < StandardError
end
+ # ITunesConnectNoChangesError is thrown when the only error is that there were no changes
+ # usually those errors are irrelevant
+ class ITunesConnectNoChangesError < ITunesConnectError
+
+ end
+
#####################################################
# @!group Init and Login
#####################################################
def self.hostname
@@ -73,10 +79,12 @@
raise ITunesConnectError.new, info.join("\n")
end
end
end
+ # rubocop:disable Metrics/CyclomaticComplexity
+ # rubocop:disable Metrics/PerceivedComplexity
def handle_itc_response(raw)
return unless raw
return unless raw.kind_of? Hash
data = raw['data'] || raw # sometimes it's with data, sometimes it isn't
@@ -114,28 +122,50 @@
# e.g. {"warn"=>nil, "error"=>["operation_failed"], "info"=>nil}
different_error = raw.fetch('messages', {}).fetch('error', nil)
errors << different_error if different_error
if errors.count > 0 # they are separated by `.` by default
- raise ITunesConnectError.new, errors.join(' ')
+ if errors.count == 1 and errors.first == "You haven't made any changes."
+ # This is a special error for which we throw a separate exception
+ raise ITunesConnectNoChangesError.new, errors.first
+ else
+ raise ITunesConnectError.new, errors.join(' ')
+ end
end
puts data['sectionInfoKeys'] if data['sectionInfoKeys']
puts data['sectionWarningKeys'] if data['sectionWarningKeys']
return data
end
+ # rubocop:enable Metrics/CyclomaticComplexity
+ # rubocop:enable Metrics/PerceivedComplexity
#####################################################
# @!group Applications
#####################################################
def applications
- r = request(:get, 'ra/apps/manageyourapps/summary')
+ r = request(:get, 'ra/apps/manageyourapps/summary/v2')
parse_response(r, 'data')['summaries']
end
+ def app_details(app_id)
+ r = request(:get, "ra/apps/#{app_id}/details")
+ parse_response(r, 'data')
+ end
+
+ def update_app_details!(app_id, data)
+ r = request(:post) do |req|
+ req.url "ra/apps/#{app_id}/details"
+ req.body = data.to_json
+ req.headers['Content-Type'] = 'application/json'
+ end
+
+ handle_itc_response(r.body)
+ end
+
# Creates a new application on iTunes Connect
# @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
# App Store territory, the information from your primary language will be used instead.
@@ -144,25 +174,31 @@
# @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
# 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')
+ app_type = 'ios'
+ r = request(:get, "ra/apps/create/v2/?platformString=#{app_type}")
data = parse_response(r, 'data')
# Now fill in the values we have
- data['versionString']['value'] = version
- data['newApp']['name']['value'] = name
+ # some values are nil, that's why there is a hash
+ data['versionString'] = { value: version }
+ data['newApp']['name'] = { value: name }
data['newApp']['bundleId']['value'] = bundle_id
data['newApp']['primaryLanguage']['value'] = primary_language || 'English'
- data['newApp']['vendorId']['value'] = sku
+ data['newApp']['vendorId'] = {value: sku }
data['newApp']['bundleIdSuffix']['value'] = bundle_id_suffix
data['companyName']['value'] = company_name if company_name
+ data['newApp']['appType'] = app_type
+ data['initialPlatform'] = app_type
+ data['enabledPlatformsForCreation']['value'] = [app_type]
+
# Now send back the modified hash
r = request(:post) do |req|
- req.url 'ra/apps/create/?appType=ios'
+ req.url 'ra/apps/create/v2'
req.body = data.to_json
req.headers['Content-Type'] = 'application/json'
end
data = parse_response(r, 'data')
@@ -189,13 +225,21 @@
#####################################################
def app_version(app_id, is_live)
raise "app_id is required" unless app_id
- v_text = (is_live ? 'live' : nil)
+ # First we need to fetch the IDs for the edit / live version
+ r = request(:get, "ra/apps/#{app_id}/overview")
+ platforms = parse_response(r, 'data')['platforms']
- r = request(:get, "ra/apps/version/#{app_id}", {v: v_text})
+ platforms = platforms.first # That won't work for mac apps
+
+ version = platforms[(is_live ? 'deliverableVersion' : 'inFlightVersion')]
+ return nil unless version
+ version_id = version['id']
+
+ r = request(:get, "ra/apps/#{app_id}/platforms/ios/versions/#{version_id}")
parse_response(r, 'data')
end
def update_app_version!(app_id, is_live, data)
raise "app_id is required" unless app_id
@@ -213,21 +257,21 @@
#####################################################
# @!group Build Trains
#####################################################
- def build_trains(app_id)
+ # @param (testing_type) internal or external
+ def build_trains(app_id, testing_type)
raise "app_id is required" unless app_id
-
- r = request(:get, "ra/apps/#{app_id}/trains/")
+ r = request(:get, "ra/apps/#{app_id}/trains/?testingType=#{testing_type}")
parse_response(r, 'data')
end
- def update_build_trains!(app_id, data)
+ def update_build_trains!(app_id, testing_type, data)
raise "app_id is required" unless app_id
r = request(:post) do |req|
- req.url "ra/apps/#{app_id}/trains/"
+ req.url "ra/apps/#{app_id}/testingTypes/#{testing_type}/trains/"
req.body = data.to_json
req.headers['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)