spaceship 0.15.1 → 0.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a05323b6eb94cdb6d2e6cfd569a474b0b9d4458
4
- data.tar.gz: 1b7dfa2048823baf113f92c5f85dca8c3e01ff27
3
+ metadata.gz: 0331855014bef933ae72ac1c53a5393245b03987
4
+ data.tar.gz: 469b03b9cefb35064f74904f2cf12911b3ba2851
5
5
  SHA512:
6
- metadata.gz: 99c39230b509ed3e03be4bce69ba620f193c92b0646e7a64c095f00557fc9832f30c125ac8ac631de5ad7331087aacb4ca7641dfd0de4055a7371053e7d69336
7
- data.tar.gz: acf379e3595f63f345b5d7fad8a8612cdd0338e97ef3eff38a8023b49b979060cfc0511fad5847eef01a63baf2af181ffabd437d1bc708466ace4539892add08
6
+ metadata.gz: 0ae10f270d59a7979d8e47f6ff1cd3aabbec0c5bcb69ed33c65028d6a306a9006a7feec83402dded431dd6fc35211539a4676c0f2d4d1a41fe300182a7424efe
7
+ data.tar.gz: d0c5bb81700c156275b7feda876628dfe66355b4a6e5e70233005d391cb4efcca7e9e39b8cfad3572910d8c4cefd93779e62fb467702b7c55eac5f297d5032b8
@@ -1,6 +1,7 @@
1
1
  require 'faraday' # HTTP Client
2
2
  require 'logger'
3
3
  require 'faraday_middleware'
4
+ require 'faraday-cookie_jar'
4
5
  require 'spaceship/ui'
5
6
  require 'spaceship/helper/plist_middleware'
6
7
  require 'spaceship/helper/net_http_generic_request'
@@ -14,9 +15,9 @@ end
14
15
  module Spaceship
15
16
  class Client
16
17
  PROTOCOL_VERSION = "QH65B2"
18
+ USER_AGENT = "Spaceship #{Spaceship::VERSION}"
17
19
 
18
20
  attr_reader :client
19
- attr_accessor :cookie
20
21
 
21
22
  # The user that is currently logged in
22
23
  attr_accessor :user
@@ -67,6 +68,7 @@ module Spaceship
67
68
  c.response :json, content_type: /\bjson$/
68
69
  c.response :xml, content_type: /\bxml$/
69
70
  c.response :plist, content_type: /\bplist$/
71
+ c.use :cookie_jar
70
72
  c.adapter Faraday.default_adapter
71
73
 
72
74
  if ENV['DEBUG']
@@ -169,11 +171,6 @@ module Spaceship
169
171
  end
170
172
  end
171
173
 
172
- # @return (Bool) Do we have a valid session?
173
- def session?
174
- !!@cookie
175
- end
176
-
177
174
  def with_retry(tries = 5, &block)
178
175
  return block.call
179
176
  rescue Faraday::Error::TimeoutError, AppleTimeoutError => ex # New Faraday version: Faraday::TimeoutError => ex
@@ -204,11 +201,8 @@ module Spaceship
204
201
  end
205
202
 
206
203
  def request(method, url_or_path = nil, params = nil, headers = {}, &block)
207
- if session?
208
- headers.merge!({ 'Cookie' => cookie })
209
- headers.merge!(csrf_tokens)
210
- end
211
- headers.merge!({ 'User-Agent' => 'spaceship' })
204
+ headers.merge!(csrf_tokens)
205
+ headers.merge!({ 'User-Agent' => USER_AGENT })
212
206
 
213
207
  # Before encoding the parameters, log them
214
208
  log_request(method, url_or_path, params)
@@ -37,9 +37,11 @@ module Spaceship
37
37
  appIdKey: api_key
38
38
  })
39
39
 
40
- if response['Set-Cookie'] =~ /myacinfo=(\w+);/
41
- @cookie = "myacinfo=#{$1};"
42
- return @client
40
+ case response.status
41
+ when 302
42
+ return response
43
+ when 200
44
+ raise InvalidUserCredentialsError.new, "Invalid username and password combination. Used '#{user}' as the username."
43
45
  else
44
46
  # Something went wrong. Was it invalid credentials or server issue
45
47
  if (response.body || "").include?("Your Apple ID or password was entered incorrectly")
@@ -51,6 +53,8 @@ module Spaceship
51
53
  info = [response.body, response['Set-Cookie']]
52
54
  raise UnexpectedResponse.new, info.join("\n")
53
55
  end
56
+ info = [response.body, response['Set-Cookie']]
57
+ raise UnexpectedResponse.new, info.join("\n")
54
58
  end
55
59
  end
56
60
 
@@ -56,24 +56,16 @@ module Spaceship
56
56
  end
57
57
 
58
58
  # Set a new team ID which will be used from now on
59
- def team_id=(t_id)
60
- r = request(:post) do |req|
59
+ def team_id=(team_id)
60
+ response = request(:post) do |req|
61
61
  req.url "ra/v1/session/webSession"
62
- req.body = { contentProviderId: t_id }.to_json
62
+ req.body = { contentProviderId: team_id }.to_json
63
63
  req.headers['Content-Type'] = 'application/json'
64
64
  end
65
65
 
66
- unless r.headers['Set-Cookie'].to_s.include?("itctx")
67
- raise "Looks like your Apple ID is not enabled for iTunes Connect, make sure to be able to login online"
68
- end
69
-
70
- itctx_regex = /itctx=([^;]*)/
71
- new_itctx = r.headers['Set-Cookie'].match(itctx_regex).to_s
72
-
73
- @cookie = @cookie.gsub(itctx_regex, new_itctx)
74
- handle_itc_response(r.body)
66
+ handle_itc_response(response.body)
75
67
 
76
- @current_team_id = t_id
68
+ @current_team_id = team_id
77
69
  end
78
70
 
79
71
  # Shows a team selection for the user in the terminal. This should not be
@@ -120,32 +112,6 @@ module Spaceship
120
112
  end
121
113
  end
122
114
 
123
- # returns wosinst, wosid and itctx
124
- def login_overhead_cookies(myacinfo)
125
- return @login_overhead_cookies if @login_overhead_cookies
126
-
127
- response = request(:get, "route?noext") # for woinst and wosid
128
- cookies = {
129
- woinst: response['Set-Cookie'].match(/woinst=([^;]*)/)[1],
130
- wosid: response['Set-Cookie'].match(/wosid=([^;]*)/)[1],
131
- myacinfo: myacinfo
132
- }
133
-
134
- # The second request has to be after getting the woinst and wois
135
- woa = request(:get) do |req|
136
- req.url "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa"
137
- req.headers["Cookie"] = cookies.collect { |k, v| "#{k}=#{v}; " }.join("")
138
- end
139
-
140
- unless woa['Set-Cookie'].include?("itctx")
141
- raise "Looks like your Apple ID is not enabled for iTunes Connect, make sure to be able to login online"
142
- end
143
-
144
- cookies[:itctx] = woa['Set-Cookie'].match(/itctx=([^;]*)/)[1]
145
-
146
- return @login_overhead_cookies ||= cookies
147
- end
148
-
149
115
  def service_key
150
116
  return @service_key if @service_key
151
117
  # We need a service key from a JS file to properly auth
@@ -164,31 +130,27 @@ module Spaceship
164
130
  req.url "https://idmsa.apple.com/appleauth/auth/signin?widgetKey=#{service_key}"
165
131
  req.body = data.to_json
166
132
  req.headers['Content-Type'] = 'application/json'
133
+ req.headers['X-Requested-With'] = 'XMLHttpRequest'
134
+ req.headers['Accept'] = 'application/json, text/javascript'
167
135
  end
168
136
 
169
- if response['Set-Cookie'] =~ /myacinfo=(\w+);/
170
- # To use the session properly we'll need the following cookies:
171
- # - myacinfo
172
- # - woinst
173
- # - wosid
174
- # - itctx
175
- begin
176
- re = response['Set-Cookie']
177
- myacinfo = re.match(/myacinfo=([^;]*)/)[1]
178
- cookies = login_overhead_cookies(myacinfo)
179
-
180
- @cookie = cookies.collect { |k, v| "#{k}=#{v}; " }.join("")
181
- rescue
182
- raise ITunesConnectError.new, [response.body, response['Set-Cookie']].join("\n")
183
- end
137
+ # get woinst, wois, and itctx cookie values
138
+ request(:get, "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wa/route?noext")
139
+ request(:get, "https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa")
184
140
 
185
- return @client
141
+ case response.status
142
+ when 403, 401
143
+ raise InvalidUserCredentialsError.new, "Invalid username and password combination. Used '#{user}' as the username."
144
+ when 200
145
+ return response
186
146
  else
187
147
  if response["Location"] == "/auth" # redirect to 2 step auth page
188
148
  raise "spaceship / fastlane doesn't support 2 step enabled accounts yet. Please temporary disable 2 step verification until spaceship was updated."
189
149
  elsif (response.body || "").include?('invalid="true"')
190
150
  # User Credentials are wrong
191
151
  raise InvalidUserCredentialsError.new, "Invalid username and password combination. Used '#{user}' as the username."
152
+ elsif (response['Set-Cookie'] || "").include?("itctx")
153
+ raise "Looks like your Apple ID is not enabled for iTunes Connect, make sure to be able to login online"
192
154
  else
193
155
  info = [response.body, response['Set-Cookie']]
194
156
  raise ITunesConnectError.new, info.join("\n")
@@ -598,11 +560,7 @@ module Spaceship
598
560
  handle_itc_response(r.body)
599
561
  end
600
562
 
601
- def submit_testflight_build_for_review!( # Required:
602
- app_id: nil,
603
- train: nil,
604
- build_number: nil,
605
-
563
+ def submit_testflight_build_for_review!(app_id: nil, train: nil, build_number: nil,
606
564
  # Required Metadata:
607
565
  changelog: nil,
608
566
  description: nil,
@@ -620,14 +578,7 @@ module Spaceship
620
578
  review_password: nil,
621
579
  encryption: false)
622
580
 
623
- start_url = "ra/apps/#{app_id}/trains/#{train}/builds/#{build_number}/submit/start"
624
- r = request(:get) do |req|
625
- req.url start_url
626
- req.headers['Content-Type'] = 'application/json'
627
- end
628
- handle_itc_response(r.body)
629
-
630
- build_info = r.body['data']
581
+ build_info = get_build_info_for_review(app_id: app_id, train: train, build_number: build_number)
631
582
  # Now fill in the values provided by the user
632
583
 
633
584
  # First the localised values:
@@ -648,27 +599,45 @@ module Spaceship
648
599
  build_info['testInfo']['reviewPassword']['value'] = review_password
649
600
 
650
601
  r = request(:post) do |req| # same URL, but a POST request
651
- req.url start_url
602
+ req.url "ra/apps/#{app_id}/trains/#{train}/builds/#{build_number}/submit/start"
603
+
652
604
  req.body = build_info.to_json
653
605
  req.headers['Content-Type'] = 'application/json'
654
606
  end
655
607
  handle_itc_response(r.body)
656
608
 
657
609
  encryption_info = r.body['data']
658
- if encryption_info['exportComplianceRequired']
659
- # only sometimes this is required
610
+ update_encryption_compliance(app_id: app_id,
611
+ train: train,
612
+ build_number: build_number,
613
+ encryption_info: encryption_info,
614
+ encryption: encryption)
615
+ end
660
616
 
661
- encryption_info['usesEncryption']['value'] = encryption
662
- encryption_info['encryptionUpdated']['value'] = encryption
617
+ def get_build_info_for_review(app_id: nil, train: nil, build_number: nil)
618
+ r = request(:get) do |req|
619
+ req.url "ra/apps/#{app_id}/trains/#{train}/builds/#{build_number}/submit/start"
620
+ req.headers['Content-Type'] = 'application/json'
621
+ end
622
+ handle_itc_response(r.body)
663
623
 
664
- r = request(:post) do |req|
665
- req.url "ra/apps/#{app_id}/trains/#{train}/builds/#{build_number}/submit/complete"
666
- req.body = encryption_info.to_json
667
- req.headers['Content-Type'] = 'application/json'
668
- end
624
+ r.body['data']
625
+ end
626
+
627
+ def update_encryption_compliance(app_id: nil, train: nil, build_number: nil, encryption_info: nil, encryption: nil)
628
+ return unless encryption_info['exportComplianceRequired']
629
+ # only sometimes this is required
630
+
631
+ encryption_info['usesEncryption']['value'] = encryption
632
+ encryption_info['encryptionUpdated']['value'] = encryption
669
633
 
670
- handle_itc_response(r.body)
634
+ r = request(:post) do |req|
635
+ req.url "ra/apps/#{app_id}/trains/#{train}/builds/#{build_number}/submit/complete"
636
+ req.body = encryption_info.to_json
637
+ req.headers['Content-Type'] = 'application/json'
671
638
  end
639
+
640
+ handle_itc_response(r.body)
672
641
  end
673
642
 
674
643
  #####################################################
@@ -1,3 +1,3 @@
1
1
  module Spaceship
2
- VERSION = "0.15.1"
2
+ VERSION = "0.15.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spaceship
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Krause
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-03 00:00:00.000000000 Z
12
+ date: 2015-12-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: credentials_manager
@@ -81,6 +81,20 @@ dependencies:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '0.9'
84
+ - !ruby/object:Gem::Dependency
85
+ name: faraday-cookie_jar
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 0.0.6
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 0.0.6
84
98
  - !ruby/object:Gem::Dependency
85
99
  name: fastimage
86
100
  requirement: !ruby/object:Gem::Requirement