phone_gap-build 0.6.0 → 0.6.1

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: c6a3bfa7b5f905953982154c7819b908426a7c20
4
- data.tar.gz: eed8c96e1abdbe2fd72271ee5dd1f748563b22ae
3
+ metadata.gz: 8e834b89c2ec819e1fd0c2b884aadd4ed469a61d
4
+ data.tar.gz: a1660bada277a57f7693419ca0cc06eabc7383db
5
5
  SHA512:
6
- metadata.gz: f42ab955ad35a889ad6d04dab15d986cc52ad4ef228d397c3e606bd443c06c7769e16eb8bbed2f4e7fd14cd604bfbd2f6b229847886c6a2d678eb01b2b57f679
7
- data.tar.gz: dbaadd0913db4e23f8ae394251770620ef7c436873209d874d57fc446d5914bd29bbf4eb23d04314a4142272edf4b659dbec07457a3a383aa6281311460f83e3
6
+ metadata.gz: 219404a7e7d4cedeb7868d667ece7e80ac39ec2ae91cf0b2431cbf0d9ed2bc5eb04440ee77ac34db1272cd0c4c23f2eb8dda32bea81cbf7694c8494580de906a
7
+ data.tar.gz: bf67eac9281fe2fa4ef18e329bcc750a2d101d39cdc1dc89eca9753375be80c0cc443fc49706c7086fe27991bf26461f1874d35dac3be5b3d6f2e51bdd7bb7d7
data/README.md CHANGED
@@ -56,6 +56,9 @@ Or install it yourself as:
56
56
  # check if the build is complete
57
57
  app.build_complete?
58
58
 
59
+ # download all build platform's packages
60
+ app.download
61
+
59
62
  # delete it!
60
63
  app.destroy
61
64
 
@@ -49,20 +49,10 @@ module PhoneGap
49
49
  complete
50
50
  end
51
51
 
52
- #@TODO another hacky method. Come on Seb :-)
53
52
  def download(params = {})
54
53
  platforms_to_download = params[:platforms] ? params[:platforms] : built_platforms
55
54
  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
55
+ PhoneGap::Build::PackageDownloader.new.download(id, platform, params[:save_to])
66
56
  end
67
57
  end
68
58
 
@@ -72,9 +62,6 @@ module PhoneGap
72
62
  status.delete_if { |package, build_status| build_status != 'complete' }.keys
73
63
  end
74
64
 
75
- def file_name_from_uri(uri)
76
- uri.match(/\/([^\/]*)$/)[0]
77
- end
78
65
  end
79
66
 
80
67
  class BuildError < Exception ; end
@@ -0,0 +1,39 @@
1
+ module PhoneGap
2
+ module Build
3
+ class PackageDownloader
4
+
5
+ attr_reader :id, :platform, :target_dir, :http_response
6
+
7
+ def download(id, platform, target_dir = '/tmp')
8
+ @id, @platform, @target_dir = id, platform, target_dir
9
+ @http_response = PhoneGap::Build::ApiRequest.new.get("/apps/#{id}/#{platform}")
10
+ save_file if http_response.success?
11
+ end
12
+
13
+ private
14
+
15
+ def save_file
16
+ FileUtils.mkdir_p(platform_output_dir)
17
+ puts "Saving to #{file_path}"
18
+ File.open(file_path, 'w+') { |f| f.write(http_response.body) }
19
+ puts 'Download complete'
20
+ end
21
+
22
+ def platform_output_dir
23
+ File.join(target_dir, platform.to_s)
24
+ end
25
+
26
+ def file_path
27
+ File.join(platform_output_dir, file_name)
28
+ end
29
+
30
+ def file_name
31
+ file_name_from_uri(http_response.request.instance_variable_get(:@last_uri).request_uri)
32
+ end
33
+
34
+ def file_name_from_uri(uri)
35
+ uri.match(/\/([^\/]*)$/)[0]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,5 +1,5 @@
1
1
  module PhoneGap
2
2
  module Build
3
- VERSION = '0.6.0'
3
+ VERSION = '0.6.1'
4
4
  end
5
5
  end
@@ -7,6 +7,7 @@ require 'phone_gap/build/api_request'
7
7
  require 'phone_gap/build/rest_resource'
8
8
  require 'phone_gap/build/creatable'
9
9
  require 'phone_gap/build/error'
10
+ require 'phone_gap/build/package_downloader'
10
11
 
11
12
  require 'httparty'
12
13
 
@@ -176,9 +176,11 @@ describe PhoneGap::Build::App do
176
176
  describe '#download' do
177
177
 
178
178
  let(:http_response) { double('http response', success?: false) }
179
+ let(:package_downloader) { double('PhoneGap::Build::PackageDownloader') }
179
180
 
180
181
  before do
181
182
  api_request.stub(:get).and_return http_response
183
+ PhoneGap::Build::PackageDownloader.stub(:new).and_return package_downloader
182
184
  end
183
185
 
184
186
  context 'when there are builds that are complete' do
@@ -187,68 +189,35 @@ describe PhoneGap::Build::App do
187
189
  subject.instance_variable_set('@status', { android: 'complete', ios: 'complete', winphone: 'complete' })
188
190
  end
189
191
 
190
- context 'when no specific platforms are specified' do
192
+ context 'and no specific platforms are specified' do
191
193
 
192
- let(:platforms) { %w(android ios winphone) }
194
+ let(:platforms) { %i(android ios winphone) }
193
195
 
194
196
  it 'downloads each platform\'s package' do
195
197
  platforms.each do |platform|
196
- expect(api_request).to receive(:get).with("/apps/#{id}/#{platform}")
198
+ expect(package_downloader).to receive(:download).with(id, platform, anything)
197
199
  end
198
200
  subject.download
199
201
  end
200
- end
201
-
202
- context 'when specific packages are specified' do
203
202
 
204
- let(:platforms) { %w(ios android) }
203
+ context 'and the package is to be saved in a specific directory' do
205
204
 
206
- it 'downloads the specific packages' do
207
- platforms.each do |platform|
208
- expect(api_request).to receive(:get).with("/apps/#{id}/#{platform}")
205
+ it 'passes on the target directory to the package downloader' do
206
+ expect(package_downloader).to receive(:download).with(id, anything, 'my special directory').exactly(3).times
207
+ subject.download(save_to: 'my special directory')
209
208
  end
210
- subject.download(platforms: platforms)
211
209
  end
212
210
  end
213
211
 
214
- context 'when the download response is successful' do
212
+ context 'and specific packages are set to be downloaded' do
215
213
 
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
214
+ let(:platforms) { %w(ios android) }
245
215
 
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
216
+ it 'downloads the specific packages' do
217
+ platforms.each do |platform|
218
+ expect(package_downloader).to receive(:download).with(id, platform, anything)
251
219
  end
220
+ subject.download(platforms: platforms)
252
221
  end
253
222
  end
254
223
  end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe PhoneGap::Build::PackageDownloader do
4
+
5
+ let(:api_request) { double('PhoneGap::Build::ApiRequest') }
6
+
7
+ before do
8
+ PhoneGap::Build::ApiRequest.stub(:new).and_return api_request
9
+ end
10
+
11
+ context 'when given a package' do
12
+
13
+ let(:platform) { 'some platform' }
14
+
15
+ context 'and an app id' do
16
+
17
+ let(:id) { 'id' }
18
+ let(:http_response) { double('response', :success? => false, body: '{"key":"value"}') }
19
+
20
+ it 'makes an api call to download the package' do
21
+ expect(api_request).to receive(:get).with("/apps/#{id}/#{platform}").and_return http_response
22
+ subject.download(id, platform)
23
+ end
24
+
25
+ context 'when the api call is successful' do
26
+
27
+ let(:file_name) { 'Something.ipa' }
28
+ let(:uri) { double('uri', request_uri: "/ios.phonegap/slicehost-production/apps/894786/#{file_name}" ) }
29
+ let(:request) { double('request') }
30
+ let(:http_response) { double('http response', success?: true, request: request, body: 'file content') }
31
+
32
+ before do
33
+ api_request.stub(:get).and_return http_response
34
+ request.stub(:instance_variable_get).with(:@last_uri).and_return uri
35
+ FileUtils.stub(:mkdir_p)
36
+ File.stub(:open)
37
+ end
38
+
39
+ it 'creates a directory to store the file' do
40
+ expect(FileUtils).to receive(:mkdir_p)
41
+ subject.download(id, platform)
42
+ end
43
+
44
+ context 'and given a directory to save to' do
45
+
46
+ let(:target_dir) { '/save/me/here' }
47
+
48
+ it 'saves each package to the given folder' do
49
+ expect(File).to receive(:open).with("#{target_dir}/#{platform}/#{file_name}", anything)
50
+ subject.download(id, platform, target_dir)
51
+ end
52
+ end
53
+
54
+ context 'and not given a directory to save to' do
55
+
56
+ it 'saves the package to the tmp folder' do
57
+ expect(File).to receive(:open).with("/tmp/#{platform}/#{file_name}", anything)
58
+ subject.download(id, platform)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ 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.6.0
4
+ version: 0.6.1
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-29 00:00:00.000000000 Z
11
+ date: 2014-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httmultiparty
@@ -112,6 +112,7 @@ files:
112
112
  - spec/phone_gap/build/api_request_spec.rb
113
113
  - spec/phone_gap/build/app_spec.rb
114
114
  - spec/phone_gap/build/credentials_spec.rb
115
+ - spec/phone_gap/build/package_downloader_spec.rb
115
116
  - spec/phone_gap/build/rest_resource_spec.rb
116
117
  - spec/phone_gap/build_spec.rb
117
118
  - spec/spec_helper.rb
@@ -148,6 +149,7 @@ test_files:
148
149
  - spec/phone_gap/build/api_request_spec.rb
149
150
  - spec/phone_gap/build/app_spec.rb
150
151
  - spec/phone_gap/build/credentials_spec.rb
152
+ - spec/phone_gap/build/package_downloader_spec.rb
151
153
  - spec/phone_gap/build/rest_resource_spec.rb
152
154
  - spec/phone_gap/build_spec.rb
153
155
  - spec/spec_helper.rb