Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KrauseFx committed Feb 18, 2016
2 parents 15358dc + 5a6018f commit 2cce37a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 39 deletions.
10 changes: 6 additions & 4 deletions lib/spaceship/tunes/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,11 @@ def update_build_information!(whats_new: nil,
# encryption: false
# }
def submit_for_beta_review!(metadata)
# First, enable beta testing for this train (per iTC requirement)
self.build_train.update_testing_status!(true, 'external')

parameters = {
app_id: self.build_train.application.apple_id,
train: self.build_train.version_string,
build_number: self.build_version,
platform: self.platform,

# Required Metadata:
changelog: "No changelog provided",
Expand All @@ -177,6 +175,9 @@ def submit_for_beta_review!(metadata)

client.submit_testflight_build_for_review!(parameters)

# Last, enable beta testing for this train (per iTC requirement). This will fail until the app has been approved for beta testing
self.build_train.update_testing_status!(true, 'external', self)

return parameters
end

Expand All @@ -200,7 +201,8 @@ def testing_status
def cancel_beta_review!
client.remove_testflight_build_from_review!(app_id: self.build_train.application.apple_id,
train: self.build_train.version_string,
build_number: self.build_version)
build_number: self.build_version,
platform: self.platform)
end
end
end
Expand Down
37 changes: 25 additions & 12 deletions lib/spaceship/tunes/build_train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,31 @@ def update_testing_status!(new_value, testing_type, build = nil)
data = client.build_trains(self.application.apple_id, testing_type)

build ||= latest_build if testing_type == 'external'

data['trains'].each do |train|
train["#{testing_type}Testing"]['value'] = false
train["#{testing_type}Testing"]['value'] = new_value if train['versionString'] == version_string

# find correct build
train['builds'].select! { |b| !b["#{testing_type}Testing"].nil? && !build.nil? && b['buildVersion'] == build.build_version }

# also update the build if it was found
train['builds'].each do |b|
b["#{testing_type}Testing"]['value'] = false
b["#{testing_type}Testing"]['value'] = new_value if b['trainVersion'] == version_string
testing_key = "#{testing_type}Testing"

# Delete the irrelevant trains and update the relevant one to enable testing
data['trains'].delete_if do |train|
if train['versionString'] != version_string
true
else
train[testing_key]['value'] = new_value

# also update the builds
train['builds'].delete_if do |b|
return true if b[testing_key].nil?

if build && b["buildVersion"] == build.build_version
b[testing_key]['value'] = new_value
false
elsif b[testing_key]['value'] == true
b[testing_key]['value'] = false
false
else
true
end
end

false
end
end

Expand Down
48 changes: 26 additions & 22 deletions lib/spaceship/tunes/tunes_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ def create_application!(name: nil, primary_language: nil, version: nil, sku: nil
handle_itc_response(data)
end

def create_version!(app_id, version_number)
def create_version!(app_id, version_number, platform = 'ios')
r = request(:post) do |req|
req.url "ra/apps/#{app_id}/platforms/ios/versions/create/"
req.url "ra/apps/#{app_id}/platforms/#{platform}/versions/create/"
req.body = {
version: {
value: version_number.to_s
Expand Down Expand Up @@ -526,9 +526,9 @@ def update_build_trains!(app_id, testing_type, data)
handle_itc_response(r.body)
end

def remove_testflight_build_from_review!(app_id: nil, train: nil, build_number: nil)
def remove_testflight_build_from_review!(app_id: nil, train: nil, build_number: nil, platform: 'ios')
r = request(:post) do |req|
req.url "ra/apps/#{app_id}/platforms/ios/trains/#{train}/builds/#{build_number}/reject"
req.url "ra/apps/#{app_id}/platforms/#{platform}/trains/#{train}/builds/#{build_number}/reject"
req.body = {}.to_json
req.headers['Content-Type'] = 'application/json'
end
Expand Down Expand Up @@ -567,7 +567,7 @@ def update_build_information!(app_id: nil,
handle_itc_response(r.body)
end

def submit_testflight_build_for_review!(app_id: nil, train: nil, build_number: nil,
def submit_testflight_build_for_review!(app_id: nil, train: nil, build_number: nil, platform: 'ios',
# Required Metadata:
changelog: nil,
description: nil,
Expand All @@ -585,29 +585,29 @@ def submit_testflight_build_for_review!(app_id: nil, train: nil, build_number: n
review_password: nil,
encryption: false)

build_info = get_build_info_for_review(app_id: app_id, train: train, build_number: build_number)
build_info = get_build_info_for_review(app_id: app_id, train: train, build_number: build_number, platform: platform)
# 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
current['marketingUrl']['value'] = marketing_url
current['privacyPolicyUrl']['value'] = privacy_policy_url
current['whatsNew']['value'] = changelog if changelog
current['description']['value'] = description if description
current['feedbackEmail']['value'] = feedback_email if feedback_email
current['marketingUrl']['value'] = marketing_url if marketing_url
current['privacyPolicyUrl']['value'] = privacy_policy_url if privacy_policy_url
current['pageLanguageValue'] = current['language'] # There is no valid reason why we need this, only iTC being iTC
end
build_info['significantChange'] ||= {}
build_info['significantChange']['value'] = significant_change
build_info['testInfo']['reviewFirstName']['value'] = first_name
build_info['testInfo']['reviewLastName']['value'] = last_name
build_info['testInfo']['reviewPhone']['value'] = phone_number
build_info['testInfo']['reviewEmail']['value'] = review_email
build_info['testInfo']['reviewUserName']['value'] = review_user_name
build_info['testInfo']['reviewPassword']['value'] = review_password
build_info['testInfo']['reviewFirstName']['value'] = first_name if first_name
build_info['testInfo']['reviewLastName']['value'] = last_name if last_name
build_info['testInfo']['reviewPhone']['value'] = phone_number if phone_number
build_info['testInfo']['reviewEmail']['value'] = review_email if review_email
build_info['testInfo']['reviewUserName']['value'] = review_user_name if review_user_name
build_info['testInfo']['reviewPassword']['value'] = review_password if review_password

r = request(:post) do |req| # same URL, but a POST request
req.url "ra/apps/#{app_id}/platforms/ios/trains/#{train}/builds/#{build_number}/submit/start"
req.url "ra/apps/#{app_id}/platforms/#{platform}/trains/#{train}/builds/#{build_number}/submit/start"

req.body = build_info.to_json
req.headers['Content-Type'] = 'application/json'
Expand All @@ -618,30 +618,34 @@ def submit_testflight_build_for_review!(app_id: nil, train: nil, build_number: n
update_encryption_compliance(app_id: app_id,
train: train,
build_number: build_number,
platform: platform,
encryption_info: encryption_info,
encryption: encryption)
end

def get_build_info_for_review(app_id: nil, train: nil, build_number: nil)
def get_build_info_for_review(app_id: nil, train: nil, build_number: nil, platform: 'ios')
r = request(:get) do |req|
req.url "ra/apps/#{app_id}/platforms/ios/trains/#{train}/builds/#{build_number}/submit/start"
req.url "ra/apps/#{app_id}/platforms/#{platform}/trains/#{train}/builds/#{build_number}/submit/start"
req.headers['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)

r.body['data']
end

def update_encryption_compliance(app_id: nil, train: nil, build_number: nil, encryption_info: nil, encryption: nil)
def update_encryption_compliance(app_id: nil, train: nil, build_number: nil, platform: 'ios', encryption_info: nil, encryption: nil, is_exempt: true, proprietary: false, third_party: false)
return unless encryption_info['exportComplianceRequired']
# only sometimes this is required

encryption_info['usesEncryption']['value'] = encryption
encryption_info['encryptionUpdated'] ||= {}
encryption_info['encryptionUpdated']['value'] = encryption
encryption_info['isExempt']['value'] = is_exempt
encryption_info['containsProprietaryCryptography']['value'] = proprietary
encryption_info['containsThirdPartyCryptography']['value'] = third_party

r = request(:post) do |req|
req.url "ra/apps/#{app_id}/platforms/ios/trains/#{train}/builds/#{build_number}/submit/complete"
req.url "ra/apps/#{app_id}/platforms/#{platform}/trains/#{train}/builds/#{build_number}/submit/complete"
req.body = encryption_info.to_json
req.headers['Content-Type'] = 'application/json'
end
Expand Down
2 changes: 1 addition & 1 deletion lib/spaceship/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Spaceship
VERSION = "0.19.4"
VERSION = "0.20.0"
end
1 change: 1 addition & 0 deletions spec/tunes/build_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
app_id: "898536088",
train: "1.0",
build_number: "10",
platform: "ios",
changelog: "Custom Changelog",
description: "No app description provided",
feedback_email: "contact@company.com",
Expand Down

0 comments on commit 2cce37a

Please sign in to comment.