phone_gap-build 0.4.0 → 0.5.0
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 +4 -4
- data/README.md +10 -0
- data/lib/phone_gap/build/app.rb +21 -1
- data/lib/phone_gap/build/rest_resource.rb +21 -1
- data/lib/phone_gap/build/version.rb +1 -1
- data/spec/fixtures/api_responses/get-app.json +52 -0
- data/spec/phone_gap/build/app_spec.rb +91 -7
- data/spec/phone_gap/build/rest_resource_spec.rb +28 -5
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12844dadae8e2b81b176ddcf2d7b3f28d18403b9
|
4
|
+
data.tar.gz: 0593bbe7132d9c502057e7d2a5bdbc046f8d68c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7baeb0e1accd202d53dd2f1f143fffc27b27801a38f7df9d9e81fabf731141f1e54702fb6afbe59edd547cde74594c628c7220fab186a95310bf0ded95e00e9f
|
7
|
+
data.tar.gz: b66b04811b0acbd665c740b60ec5048e8027349d0d72ef6c7eaf8617c269c5d31a38d9ebbd278bc9878db918f78fe5041f83f6c1dc97a46da61ae483a10e95c3
|
data/README.md
CHANGED
@@ -26,8 +26,12 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
require 'phone_gap/build'
|
28
28
|
|
29
|
+
# manually set your api credentials
|
29
30
|
PhoneGap::Build.credentials(token: 'my_api_token')
|
30
31
|
|
32
|
+
# credentials are autoloaded from config/phonegap.yml if it exists
|
33
|
+
|
34
|
+
# set what apps you got
|
31
35
|
apps = PhoneGap::Build.apps
|
32
36
|
|
33
37
|
# update an existing app
|
@@ -46,6 +50,12 @@ Or install it yourself as:
|
|
46
50
|
# save/create the app
|
47
51
|
app.save
|
48
52
|
|
53
|
+
# build the app
|
54
|
+
app.build
|
55
|
+
|
56
|
+
# check if the build is complete
|
57
|
+
app.build_complete?
|
58
|
+
|
49
59
|
# delete it!
|
50
60
|
app.destroy
|
51
61
|
|
data/lib/phone_gap/build/app.rb
CHANGED
@@ -27,6 +27,26 @@ module PhoneGap
|
|
27
27
|
def build
|
28
28
|
ApiRequest.new.post("#{PATH}/#{id}/build")
|
29
29
|
end
|
30
|
+
|
31
|
+
def build_complete?(params = {})
|
32
|
+
complete = false
|
33
|
+
error = false
|
34
|
+
start_time = Time.now
|
35
|
+
time_limit = start_time + (params[:poll_time_limit] || poll_time_limit)
|
36
|
+
while !complete && (Time.now < time_limit) && !error
|
37
|
+
response = ApiRequest.new.get("#{PATH}/#{id}")
|
38
|
+
if response.success?
|
39
|
+
json_object = JSON.parse(response.body)
|
40
|
+
complete = json_object['status'].all? { |platform, status| status == 'complete' }
|
41
|
+
error = json_object['status'].any? { |platform, status| status == 'error' }
|
42
|
+
end
|
43
|
+
sleep (params[:poll_interval] || poll_interval) unless complete or error
|
44
|
+
end
|
45
|
+
raise BuildError.new('An error occurred building at least one of the apps.') if error
|
46
|
+
complete
|
47
|
+
end
|
30
48
|
end
|
49
|
+
|
50
|
+
class BuildError < Exception ; end
|
31
51
|
end
|
32
|
-
end
|
52
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'phone_gap/build/creatable'
|
2
|
+
require 'phone_gap/build/base'
|
2
3
|
|
3
4
|
module PhoneGap
|
4
5
|
module Build
|
@@ -6,13 +7,24 @@ module PhoneGap
|
|
6
7
|
|
7
8
|
include PhoneGap::Build::Creatable
|
8
9
|
attr_reader :id
|
10
|
+
attr_accessor :poll_time_limit, :poll_interval
|
11
|
+
attr_writer :errors
|
12
|
+
|
13
|
+
def initialize(params = {})
|
14
|
+
@poll_time_limit = 120
|
15
|
+
@poll_interval = 5
|
16
|
+
super(params)
|
17
|
+
end
|
9
18
|
|
10
19
|
def create
|
11
20
|
response = ApiRequest.new.post(path, post_options)
|
12
21
|
if response.success?
|
13
22
|
populate_from_json(JSON.parse(response.body))
|
23
|
+
self
|
24
|
+
else
|
25
|
+
update_errors(JSON.parse(response.body))
|
26
|
+
false
|
14
27
|
end
|
15
|
-
self
|
16
28
|
end
|
17
29
|
|
18
30
|
def update
|
@@ -39,6 +51,10 @@ module PhoneGap
|
|
39
51
|
params[:remove_nils] ? json.delete_if {|k, v| v.nil? } : json
|
40
52
|
end
|
41
53
|
|
54
|
+
def errors
|
55
|
+
@errors ||= []
|
56
|
+
end
|
57
|
+
|
42
58
|
private
|
43
59
|
|
44
60
|
def post_options
|
@@ -62,6 +78,10 @@ module PhoneGap
|
|
62
78
|
end
|
63
79
|
end
|
64
80
|
end
|
81
|
+
|
82
|
+
def update_errors(json)
|
83
|
+
errors << json['error']
|
84
|
+
end
|
65
85
|
end
|
66
86
|
end
|
67
87
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
{
|
2
|
+
"title": "PhoneGap: Getting Started",
|
3
|
+
"id": 2,
|
4
|
+
"package": "com.phonegap.getting.started",
|
5
|
+
"version": "1.0.0",
|
6
|
+
"repo": "https://github.com/phonegap/phonegap-start.git",
|
7
|
+
"description": "A template for getting started with PhoneGap development and build.phonegap.com",
|
8
|
+
"debug": false,
|
9
|
+
"private": true,
|
10
|
+
"link": "/api/v1/apps/2",
|
11
|
+
"build_count": 12,
|
12
|
+
"status": {
|
13
|
+
"android": "complete",
|
14
|
+
"ios": "complete",
|
15
|
+
"winphone": "complete"
|
16
|
+
},
|
17
|
+
"download": {
|
18
|
+
"android": "/api/v1/apps/1/android",
|
19
|
+
"ios": "/api/v1/apps/1/ios",
|
20
|
+
"winphone": "/api/v1/apps/1/winphone"
|
21
|
+
},
|
22
|
+
"error": {},
|
23
|
+
"icon": {
|
24
|
+
"filename": "big-icon.png",
|
25
|
+
"link": "/api/v1/apps/2/icon"
|
26
|
+
},
|
27
|
+
"role": "admin",
|
28
|
+
"keys": {},
|
29
|
+
"collaborators": {
|
30
|
+
"link": "/api/v1/apps/9/collaborators",
|
31
|
+
"active": [
|
32
|
+
{
|
33
|
+
"id": 9,
|
34
|
+
"person": "andrew.lunny@nitobi.com",
|
35
|
+
"role": "admin",
|
36
|
+
"link": "/api/v1/apps/9/collaborators/9"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"id": 13,
|
40
|
+
"person": "foo@bar.com",
|
41
|
+
"role": "developer",
|
42
|
+
"link": "/api/v1/apps/9/collaborators/13"
|
43
|
+
}
|
44
|
+
],
|
45
|
+
"pending": [
|
46
|
+
{
|
47
|
+
"person": "nobody@nitobi.com",
|
48
|
+
"role": "tester"
|
49
|
+
}
|
50
|
+
]
|
51
|
+
}
|
52
|
+
}
|
@@ -2,6 +2,12 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe PhoneGap::Build::App do
|
4
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
|
+
|
5
11
|
it 'has a PATH of "apps"' do
|
6
12
|
expect(subject.class.const_get('PATH')).to eq '/apps'
|
7
13
|
end
|
@@ -30,8 +36,8 @@ describe PhoneGap::Build::App do
|
|
30
36
|
|
31
37
|
describe '#create' do
|
32
38
|
|
33
|
-
let(:response) { double('response', :success? => false) }
|
34
39
|
let(:api_request) { double('PhoneGap::Build::ApiRequest') }
|
40
|
+
let(:response) { double('response', :success? => false, body: '{"key":"value"}') }
|
35
41
|
|
36
42
|
context 'when there are populated and non-populated creatable variables' do
|
37
43
|
|
@@ -66,16 +72,94 @@ describe PhoneGap::Build::App do
|
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
69
|
-
|
75
|
+
context 'for an existing app' do
|
76
|
+
|
77
|
+
let(:id) { '1' }
|
78
|
+
|
79
|
+
before do
|
80
|
+
subject.instance_variable_set('@id',id)
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#build' do
|
84
|
+
|
85
|
+
context 'when the app has an id' do
|
86
|
+
|
87
|
+
let(:id) { 1 }
|
88
|
+
let(:api_request) { double('PhoneGap::Build::ApiRequest') }
|
89
|
+
|
90
|
+
before do
|
91
|
+
subject.instance_variable_set('@id', id)
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'sends a POST request to build the app' do
|
95
|
+
expect(api_request).to receive(:post).with("/apps/#{subject.id}/build")
|
96
|
+
subject.build
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
70
100
|
|
71
|
-
|
101
|
+
describe '#build_complete?' do
|
72
102
|
|
73
|
-
let(:
|
74
|
-
let(:api_request) { double('PhoneGap::Build::ApiRequest') }
|
103
|
+
let(:http_response) { double('http response', success?: false) }
|
75
104
|
|
76
105
|
before do
|
77
|
-
|
78
|
-
|
106
|
+
api_request.stub(:get).with("/apps/#{id}").and_return http_response
|
107
|
+
subject.poll_time_limit = 0.1
|
108
|
+
subject.poll_interval = 0
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'polls the api to see if the app has finished building' do
|
112
|
+
expect(api_request).to receive(:get).with("/apps/#{id}").and_return http_response
|
113
|
+
subject.build_complete?
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'with a poll interval of 0.09 second' do
|
117
|
+
|
118
|
+
before do
|
119
|
+
subject.poll_interval = 0.09
|
120
|
+
end
|
121
|
+
|
122
|
+
context 'when not given a time limit' do
|
123
|
+
|
124
|
+
context 'with a poll interval of 0.1 seconds' do
|
125
|
+
|
126
|
+
before do
|
127
|
+
subject.poll_interval = 0.1
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'checks every 0.09 seconds until the default time limit is exceeded' do
|
131
|
+
subject.poll_time_limit = 0.09
|
132
|
+
expect(api_request).to receive(:get).with("/apps/#{id}").exactly(1).times
|
133
|
+
subject.build_complete?
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context 'when supplied with a time limit' do
|
139
|
+
|
140
|
+
it 'checks every 0.1 seconds until the supplied time limit has exceeded' do
|
141
|
+
expect(api_request).to receive(:get).with("/apps/#{id}").exactly(1).times
|
142
|
+
subject.build_complete?(poll_time_limit: 0.09)
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
context 'when the build is complete' do
|
147
|
+
|
148
|
+
let(:http_response) { double('http response', success?: true, body: response_body_for('get-app') ) }
|
149
|
+
|
150
|
+
it 'returns true' do
|
151
|
+
expect(subject.build_complete?).to be_true
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context 'when there was an error building' do
|
156
|
+
|
157
|
+
let(:http_response) { double('http response', success?: true, body: '{"status": { "ios": "error"}}') }
|
158
|
+
|
159
|
+
it 'returns throws an exception' do
|
160
|
+
expect{subject.build_complete?}.to raise_error PhoneGap::Build::BuildError
|
161
|
+
end
|
162
|
+
end
|
79
163
|
end
|
80
164
|
|
81
165
|
it 'sends a POST request to build the app' do
|
@@ -9,6 +9,14 @@ describe PhoneGap::Build::RestResource do
|
|
9
9
|
PhoneGap::Build::ApiRequest.stub(:new).and_return api_request
|
10
10
|
end
|
11
11
|
|
12
|
+
it 'has a default poll_time_limit of 120' do
|
13
|
+
expect(subject.poll_time_limit).to eq 120
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has a default poll_interval of 5' do
|
17
|
+
expect(subject.poll_interval).to eq 5
|
18
|
+
end
|
19
|
+
|
12
20
|
context 'when an authentication token is present' do
|
13
21
|
|
14
22
|
let(:token) { 'BATMAN' }
|
@@ -31,10 +39,10 @@ describe PhoneGap::Build::RestResource do
|
|
31
39
|
|
32
40
|
describe '#create' do
|
33
41
|
|
34
|
-
let(:response) { double('response', success?: false) }
|
42
|
+
let(:response) { double('response', success?: false, body: '{"key": "value"}') }
|
35
43
|
|
36
44
|
before do
|
37
|
-
|
45
|
+
api_request.stub(:post).with('users', query: {data: subject.as_json}).and_return response
|
38
46
|
end
|
39
47
|
|
40
48
|
it 'sends POST request' do
|
@@ -69,9 +77,9 @@ describe PhoneGap::Build::RestResource do
|
|
69
77
|
end
|
70
78
|
end
|
71
79
|
|
72
|
-
context '
|
80
|
+
context 'when creation is successful' do
|
73
81
|
|
74
|
-
let(:success_response) { double('response', success?: true, body: '{"title" : "Batman", "rating" : 5}') }
|
82
|
+
let(:success_response) { double('response', success?: true, body: '{"id" : 1, "title" : "Batman", "rating" : 5}') }
|
75
83
|
|
76
84
|
before do
|
77
85
|
api_request.stub(:post).with('users', query: {data: {}}).and_return success_response
|
@@ -80,10 +88,25 @@ describe PhoneGap::Build::RestResource do
|
|
80
88
|
it 'updates the object with any response attributes' do
|
81
89
|
response = subject.create
|
82
90
|
expect(response.object_id).to be subject.object_id
|
91
|
+
expect(response.instance_variable_get('@id')).to eq 1
|
83
92
|
expect(response.instance_variable_get('@title')).to eq 'Batman'
|
84
93
|
expect(response.instance_variable_get('@rating')).to eq 5
|
85
94
|
end
|
86
95
|
end
|
96
|
+
|
97
|
+
context 'when creation is unsuccessful' do
|
98
|
+
|
99
|
+
let(:response) { double('response', success?: false, body: "{\"error\":\"Error: upload failed; please try again\"}\n") }
|
100
|
+
|
101
|
+
it 'returns false' do
|
102
|
+
expect(subject.create).to eq false
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'updates the object with the errors' do
|
106
|
+
subject.create
|
107
|
+
expect(subject.errors).to eq ['Error: upload failed; please try again']
|
108
|
+
end
|
109
|
+
end
|
87
110
|
end
|
88
111
|
|
89
112
|
describe '#update' do
|
@@ -135,7 +158,7 @@ describe PhoneGap::Build::RestResource do
|
|
135
158
|
|
136
159
|
context 'when the child object doesn\'t have an id attribute' do
|
137
160
|
|
138
|
-
let(:http_response) { double('response', success?: false) }
|
161
|
+
let(:http_response) { double('response', success?: false, body: '{"key":"value"}') }
|
139
162
|
|
140
163
|
before do
|
141
164
|
subject.id = nil
|
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.
|
4
|
+
version: 0.5.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-
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httmultiparty
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- lib/phone_gap/build/rest_resource.rb
|
105
105
|
- lib/phone_gap/build/version.rb
|
106
106
|
- phone_gap-build.gemspec
|
107
|
+
- spec/fixtures/api_responses/get-app.json
|
107
108
|
- spec/fixtures/api_responses/get-apps.json
|
108
109
|
- spec/fixtures/api_responses/rest-resource-create.json
|
109
110
|
- spec/fixtures/index.html
|
@@ -139,6 +140,7 @@ signing_key:
|
|
139
140
|
specification_version: 4
|
140
141
|
summary: PhoneGap Build Api gem
|
141
142
|
test_files:
|
143
|
+
- spec/fixtures/api_responses/get-app.json
|
142
144
|
- spec/fixtures/api_responses/get-apps.json
|
143
145
|
- spec/fixtures/api_responses/rest-resource-create.json
|
144
146
|
- spec/fixtures/index.html
|