phone_gap-build 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e0c5f823e46d6457be86cb5297cd24b461aa5fc
4
- data.tar.gz: 792c13d4c77551350b495716467a691c6850aabb
3
+ metadata.gz: c6a3bfa7b5f905953982154c7819b908426a7c20
4
+ data.tar.gz: eed8c96e1abdbe2fd72271ee5dd1f748563b22ae
5
5
  SHA512:
6
- metadata.gz: 619c405c7655213e187d098711b087b272981d3896a9741fbdef2a99db832cefe4124ec6d17e65023da43c4b358f08bf783f3587d70726ffaed8da079d13c1d3
7
- data.tar.gz: 6c6661f1685aa071b3858fda80a482c74525496662e11fca7cdd68ea35142108b6c4fbc50581698c58897f6af0c23632a82ca1ce73a900153d871373debfcade
6
+ metadata.gz: f42ab955ad35a889ad6d04dab15d986cc52ad4ef228d397c3e606bd443c06c7769e16eb8bbed2f4e7fd14cd604bfbd2f6b229847886c6a2d678eb01b2b57f679
7
+ data.tar.gz: dbaadd0913db4e23f8ae394251770620ef7c436873209d874d57fc446d5914bd29bbf4eb23d04314a4142272edf4b659dbec07457a3a383aa6281311460f83e3
@@ -8,7 +8,7 @@ module PhoneGap
8
8
  PATH = '/apps'
9
9
 
10
10
  attr_accessor :title, :create_method, :package, :version, :description, :debug, :keys, :private,
11
- :phonegap_version, :hydrates, :file
11
+ :phonegap_version, :hydrates, :file, :status
12
12
 
13
13
  attr_creatable :title, :create_method, :package, :version, :description, :debug, :keys, :private,
14
14
  :phonegap_version, :hydrates, :file
@@ -45,8 +45,36 @@ module PhoneGap
45
45
  end
46
46
  raise BuildError.new('An error occurred building at least one of the apps.') if error
47
47
  raise BuildError.new('Builds did not complete within the allotted time.') if !error && !complete
48
+ populate_from_json(json_object)
48
49
  complete
49
50
  end
51
+
52
+ #@TODO another hacky method. Come on Seb :-)
53
+ def download(params = {})
54
+ platforms_to_download = params[:platforms] ? params[:platforms] : built_platforms
55
+ platforms_to_download.each do |platform|
56
+ response = ApiRequest.new.get("#{PATH}/#{id}/#{platform}")
57
+ if response.success?
58
+ file_name = file_name_from_uri(response.request.instance_variable_get(:@last_uri).request_uri)
59
+ dir = File.join((params[:save_to] ? params[:save_to] : '/tmp'), platform.to_s)
60
+ file_path = File.join(dir, file_name)
61
+ FileUtils.mkdir_p(dir)
62
+ puts "Saving to #{file_path}"
63
+ File.open(file_path, 'w+') { |f| f.write(response.body) }
64
+ puts 'Download complete'
65
+ end
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def built_platforms
72
+ status.delete_if { |package, build_status| build_status != 'complete' }.keys
73
+ end
74
+
75
+ def file_name_from_uri(uri)
76
+ uri.match(/\/([^\/]*)$/)[0]
77
+ end
50
78
  end
51
79
 
52
80
  class BuildError < Exception ; end
File without changes
@@ -1,5 +1,5 @@
1
1
  module PhoneGap
2
2
  module Build
3
- VERSION = '0.5.1'
3
+ VERSION = '0.6.0'
4
4
  end
5
5
  end
@@ -143,6 +143,7 @@ describe PhoneGap::Build::App do
143
143
  end
144
144
 
145
145
  end
146
+
146
147
  context 'when the build is complete' do
147
148
 
148
149
  let(:http_response) { double('http response', success?: true, body: response_body_for('get-app') ) }
@@ -170,10 +171,86 @@ describe PhoneGap::Build::App do
170
171
  end
171
172
  end
172
173
  end
174
+ end
175
+
176
+ describe '#download' do
177
+
178
+ let(:http_response) { double('http response', success?: false) }
179
+
180
+ before do
181
+ api_request.stub(:get).and_return http_response
182
+ end
183
+
184
+ context 'when there are builds that are complete' do
185
+
186
+ before do
187
+ subject.instance_variable_set('@status', { android: 'complete', ios: 'complete', winphone: 'complete' })
188
+ end
189
+
190
+ context 'when no specific platforms are specified' do
191
+
192
+ let(:platforms) { %w(android ios winphone) }
193
+
194
+ it 'downloads each platform\'s package' do
195
+ platforms.each do |platform|
196
+ expect(api_request).to receive(:get).with("/apps/#{id}/#{platform}")
197
+ end
198
+ subject.download
199
+ end
200
+ end
201
+
202
+ context 'when specific packages are specified' do
203
+
204
+ let(:platforms) { %w(ios android) }
173
205
 
174
- it 'sends a POST request to build the app' do
175
- expect(api_request).to receive(:post).with("/apps/#{subject.id}/build")
176
- subject.build
206
+ it 'downloads the specific packages' do
207
+ platforms.each do |platform|
208
+ expect(api_request).to receive(:get).with("/apps/#{id}/#{platform}")
209
+ end
210
+ subject.download(platforms: platforms)
211
+ end
212
+ end
213
+
214
+ context 'when the download response is successful' do
215
+
216
+ let(:file_name) { 'Something.ipa' }
217
+ let(:uri) { double('uri', request_uri: "/ios.phonegap/slicehost-production/apps/894786/#{file_name}" ) }
218
+ let(:request) { double('request') }
219
+ let(:http_response) { double('http response', success?: true, request: request, body: 'file content') }
220
+
221
+ before do
222
+ api_request.stub(:get).and_return http_response
223
+ request.stub(:instance_variable_get).with(:@last_uri).and_return uri
224
+ FileUtils.stub(:mkdir_p)
225
+ end
226
+
227
+ it 'creates a directory to store the file' do
228
+ expect(FileUtils).to receive(:mkdir_p)
229
+ subject.download
230
+ end
231
+
232
+ context 'and given a directory to save to' do
233
+
234
+ let(:target_dir) { '/save/me/here' }
235
+
236
+ it 'saves each package to the given folder' do
237
+ expect(File).to receive(:open).with("#{target_dir}/ios/#{file_name}", anything)
238
+ expect(File).to receive(:open).with("#{target_dir}/android/#{file_name}", anything)
239
+ expect(File).to receive(:open).with("#{target_dir}/winphone/#{file_name}", anything)
240
+ subject.download(save_to: target_dir)
241
+ end
242
+ end
243
+
244
+ context 'and not given a directory to save to' do
245
+
246
+ it 'saves the package to the tmp folder' do
247
+ expect(File).to receive(:open).with("/tmp/ios/#{file_name}", anything)
248
+ expect(File).to receive(:open).with("/tmp/android/#{file_name}", anything)
249
+ expect(File).to receive(:open).with("/tmp/winphone/#{file_name}", anything)
250
+ subject.download
251
+ end
252
+ end
253
+ end
177
254
  end
178
255
  end
179
256
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phone_gap-build
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seb Glazebrook
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-28 00:00:00.000000000 Z
11
+ date: 2014-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httmultiparty
@@ -101,6 +101,7 @@ files:
101
101
  - lib/phone_gap/build/creatable.rb
102
102
  - lib/phone_gap/build/credentials.rb
103
103
  - lib/phone_gap/build/error.rb
104
+ - lib/phone_gap/build/package_downloader.rb
104
105
  - lib/phone_gap/build/rest_resource.rb
105
106
  - lib/phone_gap/build/version.rb
106
107
  - phone_gap-build.gemspec