lib/spaceship/tunes/tunes_client.rb in spaceship-0.13.1 vs lib/spaceship/tunes/tunes_client.rb in spaceship-0.14.0
- old
+ new
@@ -36,55 +36,56 @@
def self.hostname
"https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/"
end
- # 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)
- rescue Errno::ENOENT
- end
- return cached if cached
+ # returns wosinst, wosid and itctx
+ def login_overhead_cookies(myacinfo)
+ return @login_overhead_cookies if @login_overhead_cookies
- host = "https://itunesconnect.apple.com"
- begin
- url = host + request(:get, self.class.hostname).body.match(%r{action="(/WebObjects/iTunesConnect.woa/wo/.*)"})[1]
- raise "" unless url.length > 0
+ response = request(:get, "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wa/route?noext") # for woinst and wosid
+ cookies = {
+ woinst: response['Set-Cookie'].match(/woinst=([^;]*)/)[1],
+ wosid: response['Set-Cookie'].match(/wosid=([^;]*)/)[1],
+ myacinfo: myacinfo
+ }
- File.write(cache_path, url)
- return url
- rescue => ex
- puts ex
- raise "Could not fetch the login URL from iTunes Connect, the server might be down"
+ # The second request has to be after getting the woinst and wois
+ woa = request(:get) do |req|
+ req.url "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa"
+ req.headers["Cookie"] = cookies.collect { |k, v| "#{k}=#{v}; " }.join("")
end
+ cookies[:itctx] = woa['Set-Cookie'].match(/itctx=([^;]*)/)[1]
+
+ return @login_overhead_cookies ||= cookies
end
def send_login_request(user, password)
- response = request(:post, login_url, {
- theAccountName: user,
- theAccountPW: password
- })
+ data = {
+ accountName: user,
+ password: password,
+ rememberMe: true
+ }
+ response = request(:post) do |req|
+ req.url "https://idmsa.apple.com/appleauth/auth/signin"
+ req.body = data.to_json
+ req.headers['Content-Type'] = 'application/json'
+ end
+
if response['Set-Cookie'] =~ /myacinfo=(\w+);/
# To use the session properly we'll need the following cookies:
# - myacinfo
# - woinst
# - wosid
# - itctx
begin
re = response['Set-Cookie']
+ myacinfo = re.match(/myacinfo=([^;]*)/)[1]
+ cookies = login_overhead_cookies(myacinfo)
- to_use = [
- "myacinfo=" + re.match(/myacinfo=([^;]*)/)[1],
- "woinst=" + re.match(/woinst=([^;]*)/)[1],
- "itctx=" + re.match(/itctx=([^;]*)/)[1],
- "wosid=" + re.match(/wosid=([^;]*)/)[1]
- ]
-
- @cookie = to_use.join(';')
+ @cookie = cookies.collect { |k, v| "#{k}=#{v}; " }.join("")
rescue
raise ITunesConnectError.new, [response.body, response['Set-Cookie']].join("\n")
end
return @client
@@ -497,11 +498,10 @@
req.headers['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)
end
- # rubocop:disable Metrics/AbcSize
def submit_testflight_build_for_review!( # Required:
app_id: nil,
train: nil,
build_number: nil,
@@ -512,10 +512,11 @@
marketing_url: nil,
first_name: nil,
last_name: nil,
review_email: nil,
phone_number: nil,
+ significant_change: false,
# Optional Metadata:
privacy_policy_url: nil,
review_user_name: nil,
review_password: nil,
@@ -538,10 +539,11 @@
current['feedbackEmail']['value'] = feedback_email
current['marketingUrl']['value'] = marketing_url
current['privacyPolicyUrl']['value'] = privacy_policy_url
current['pageLanguageValue'] = current['language'] # There is no valid reason why we need this, only iTC being iTC
end
+ 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
@@ -557,20 +559,20 @@
encryption_info = r.body['data']
if encryption_info['exportComplianceRequired']
# only sometimes this is required
encryption_info['usesEncryption']['value'] = encryption
+ encryption_info['encryptionUpdated']['value'] = encryption
r = request(:post) do |req|
req.url "ra/apps/#{app_id}/trains/#{train}/builds/#{build_number}/submit/complete"
req.body = encryption_info.to_json
req.headers['Content-Type'] = 'application/json'
end
handle_itc_response(r.body)
end
end
- # rubocop:enable Metrics/AbcSize
#####################################################
# @!group Submit for Review
#####################################################