phone_gap-build 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -3
- data/lib/phone_gap/build/app.rb +10 -9
- data/lib/phone_gap/build/creatable.rb +41 -0
- data/lib/phone_gap/build/credentials.rb +10 -2
- data/lib/phone_gap/build/rest_resource.rb +63 -0
- data/lib/phone_gap/build/version.rb +1 -1
- data/lib/phone_gap/build.rb +3 -1
- data/phone_gap-build.gemspec +1 -1
- data/spec/fixtures/api_responses/rest-resource-create.json +46 -0
- data/spec/phone_gap/build/app_spec.rb +17 -9
- data/spec/phone_gap/build/rest_resource_spec.rb +186 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 899a79a1f62e5235bc0f9a1f216d3a9bbd72ca89
|
4
|
+
data.tar.gz: 704aaa02c1219ff6077c4fd37c7201a81ff15d7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00e0094338041ae7785c8b943eea9747e259b9922a19407d5ca5f1fd2867aae0cb4ef98608d721ac43e4d80d8dc18d5dc03b914c2679efae4c1b9571c5e3103d
|
7
|
+
data.tar.gz: 2060ab63c6e1b05228f38ca2323b420100a41f01a6d709e7f52e4e6f3c64131091a79d3e0fc8df20ef140812486e7343a03373e52dc8a362f83957197c01402a
|
data/README.md
CHANGED
@@ -24,11 +24,31 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
require 'phone_gap/build'
|
27
|
+
require 'phone_gap/build'
|
28
28
|
|
29
|
-
PhoneGap::Build.credentials(token: 'my_api_token')
|
29
|
+
PhoneGap::Build.credentials(token: 'my_api_token')
|
30
30
|
|
31
|
-
apps = PhoneGap::Build.apps
|
31
|
+
apps = PhoneGap::Build.apps
|
32
|
+
|
33
|
+
# get the app you're interested in
|
34
|
+
|
35
|
+
app = apps.first
|
36
|
+
|
37
|
+
app.description = 'Fancy Pants App'
|
38
|
+
|
39
|
+
app.save (#save will update an existing app)
|
40
|
+
|
41
|
+
# create a new app
|
42
|
+
|
43
|
+
app = PhoneGap::Build::App.new
|
44
|
+
|
45
|
+
# add any required values (see http://docs.build.phonegap.com/en_US/3.3.0/developer_api_api.md.html#PhoneGap%20Build%20Developer%20API)
|
46
|
+
|
47
|
+
app.save (#save create a new app)
|
48
|
+
|
49
|
+
# delete it!
|
50
|
+
|
51
|
+
app.destroy
|
32
52
|
|
33
53
|
## Contributing
|
34
54
|
|
data/lib/phone_gap/build/app.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
+
require 'phone_gap/build/rest_resource'
|
2
|
+
require 'httmultiparty'
|
3
|
+
|
1
4
|
module PhoneGap
|
2
5
|
module Build
|
3
|
-
class App
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
singleton_class.class_eval { attr_accessor key }
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
6
|
+
class App < RestResource
|
7
|
+
|
8
|
+
PATH = '/apps'
|
9
|
+
attr_creatable :title, :create_method, :package, :version, :description, :debug, :keys, :private, :phonegap_version, :hydrates
|
10
|
+
attr_updatable :title, :package, :version, :description, :debug, :private, :phonegap_version
|
12
11
|
|
12
|
+
|
13
|
+
end
|
13
14
|
end
|
14
15
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module PhoneGap
|
2
|
+
module Build
|
3
|
+
module Creatable
|
4
|
+
|
5
|
+
self.class_variable_set('@@creatable_attributes', {})
|
6
|
+
self.class_variable_set('@@updatable_attributes', {})
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.extend(ClassMethods)
|
10
|
+
end
|
11
|
+
|
12
|
+
def creatable_attributes
|
13
|
+
self.class.class_variable_get('@@creatable_attributes')[self.class]
|
14
|
+
end
|
15
|
+
|
16
|
+
def updatable_attributes
|
17
|
+
self.class.class_variable_get('@@updatable_attributes')[self.class]
|
18
|
+
end
|
19
|
+
|
20
|
+
module ClassMethods
|
21
|
+
|
22
|
+
def attr_creatable(*args)
|
23
|
+
args.each { |attribute| add_to_collection('@@creatable_attributes', attribute) }
|
24
|
+
end
|
25
|
+
|
26
|
+
def attr_updatable(*args)
|
27
|
+
args.each { |attribute| add_to_collection('@@updatable_attributes', attribute) }
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_to_collection(collection_name, value)
|
31
|
+
if self.class_variable_get(collection_name)[self]
|
32
|
+
self.class_variable_get(collection_name)[self] << "@#{value}"
|
33
|
+
else
|
34
|
+
self.class_variable_get(collection_name)[self] = ["@#{value}"]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,11 +1,19 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
1
3
|
module PhoneGap
|
2
4
|
module Build
|
3
5
|
class Credentials
|
4
6
|
|
7
|
+
include Singleton
|
8
|
+
|
5
9
|
attr_reader :username, :password, :token
|
10
|
+
attr_writer :token
|
6
11
|
|
7
|
-
def
|
8
|
-
@username
|
12
|
+
def set(credentials)
|
13
|
+
@username = credentials[:username]
|
14
|
+
@password = credentials[:password]
|
15
|
+
@token = credentials[:token]
|
16
|
+
self
|
9
17
|
end
|
10
18
|
end
|
11
19
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'phone_gap/build/creatable'
|
2
|
+
require 'httmultiparty'
|
3
|
+
|
4
|
+
module PhoneGap
|
5
|
+
module Build
|
6
|
+
class RestResource
|
7
|
+
|
8
|
+
include PhoneGap::Build::Creatable
|
9
|
+
include HTTMultiParty
|
10
|
+
base_uri 'https://build.phonegap.com/api/v1'
|
11
|
+
|
12
|
+
def initialize(attributes = {})
|
13
|
+
attributes.each do |key, value|
|
14
|
+
instance_variable_set("@#{key}", value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def create
|
19
|
+
response = self.class.post(path, query: {data: as_json(only: creatable_attributes)})
|
20
|
+
if response.success?
|
21
|
+
populate_from_json(JSON.parse(response.body))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def update
|
26
|
+
self.class.put(path, query: {data: as_json(only: updatable_attributes)})
|
27
|
+
end
|
28
|
+
|
29
|
+
def save
|
30
|
+
@id ? update : create
|
31
|
+
end
|
32
|
+
|
33
|
+
def destroy
|
34
|
+
self.class.delete(path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def as_json(params = {})
|
38
|
+
if params[:only]
|
39
|
+
params[:only].inject({}) do | memo, attribute_name|
|
40
|
+
memo[attribute_name[1..-1].to_sym] = instance_variable_get(attribute_name)
|
41
|
+
memo
|
42
|
+
end
|
43
|
+
else
|
44
|
+
{}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def path
|
51
|
+
@id ? "#{self.class.const_get('PATH')}/#{@id}?auth_token=#{token}" : "#{self.class.const_get('PATH')}?auth_token=#{token}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def token
|
55
|
+
PhoneGap::Build::Credentials.instance.token
|
56
|
+
end
|
57
|
+
|
58
|
+
def populate_from_json(json)
|
59
|
+
self.class.new(json)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/phone_gap/build.rb
CHANGED
@@ -2,6 +2,8 @@ require 'phone_gap/build/version'
|
|
2
2
|
require 'phone_gap/build/credentials'
|
3
3
|
require 'phone_gap/build/app_factory'
|
4
4
|
require 'phone_gap/build/app'
|
5
|
+
require 'phone_gap/build/rest_resource'
|
6
|
+
require 'phone_gap/build/creatable'
|
5
7
|
|
6
8
|
require 'httparty'
|
7
9
|
|
@@ -9,7 +11,7 @@ module PhoneGap
|
|
9
11
|
module Build
|
10
12
|
|
11
13
|
def self.credentials(credentials)
|
12
|
-
@credentials = Credentials.
|
14
|
+
@credentials = Credentials.instance.set(credentials)
|
13
15
|
end
|
14
16
|
|
15
17
|
def self.apps
|
data/phone_gap-build.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency '
|
21
|
+
spec.add_dependency 'httmultiparty'
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler'
|
24
24
|
spec.add_development_dependency 'rake'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
{
|
2
|
+
"keys": {
|
3
|
+
"ios": {
|
4
|
+
"title": "ios-key",
|
5
|
+
"default": true,
|
6
|
+
"id": 2,
|
7
|
+
"link": "/api/v1/keys/ios/2"
|
8
|
+
},
|
9
|
+
"android": {
|
10
|
+
"title": "release-key",
|
11
|
+
"default": true,
|
12
|
+
"id": 2,
|
13
|
+
"link": "/api/v1/keys/android/2"
|
14
|
+
}
|
15
|
+
},
|
16
|
+
"download": {},
|
17
|
+
"title": "API V1 App",
|
18
|
+
"repo": null,
|
19
|
+
"collaborators": [
|
20
|
+
{
|
21
|
+
"person": "andrew.lunny@nitobi.com",
|
22
|
+
"role": "admin"
|
23
|
+
}
|
24
|
+
],
|
25
|
+
"role": "admin",
|
26
|
+
"id": 26486,
|
27
|
+
"icon": {
|
28
|
+
"filename": null,
|
29
|
+
"link": "/api/v1/apps/26486/icon"
|
30
|
+
},
|
31
|
+
"package": "com.alunny.apiv1",
|
32
|
+
"version": "0.1.0",
|
33
|
+
"description": null,
|
34
|
+
"debug": false,
|
35
|
+
"private": true,
|
36
|
+
"link": "/api/v1/apps/26486",
|
37
|
+
"status": {
|
38
|
+
"ios": "pending",
|
39
|
+
"android": "pending",
|
40
|
+
"winphone": "pending"
|
41
|
+
},
|
42
|
+
"error": {},
|
43
|
+
"phonegap_version": "2.9.0",
|
44
|
+
"hydrates": false,
|
45
|
+
"build_count": null
|
46
|
+
}
|
@@ -2,20 +2,28 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe PhoneGap::Build::App do
|
4
4
|
|
5
|
-
|
5
|
+
it 'has a PATH of "apps"' do
|
6
|
+
expect(subject.class.const_get('PATH')).to eq '/apps'
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'creatable attributes' do
|
6
10
|
|
7
|
-
|
11
|
+
subject { PhoneGap::Build::App }
|
8
12
|
|
9
|
-
|
10
|
-
|
13
|
+
%w(title create_method package version description debug keys private phonegap_version hydrates).each do |attribute|
|
14
|
+
it "'#{attribute}' is updatable" do
|
15
|
+
expect(subject.class_variable_get('@@creatable_attributes')[subject]).to include "@#{attribute}"
|
11
16
|
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'updatable attributes' do
|
12
21
|
|
13
|
-
|
22
|
+
subject { PhoneGap::Build::App }
|
14
23
|
|
15
|
-
|
16
|
-
|
17
|
-
expect(subject.
|
18
|
-
expect(subject.status).to eq({height: 'tall', weight: 'heavy'})
|
24
|
+
%w(title package version description debug private phonegap_version).each do |attribute|
|
25
|
+
it "'#{attribute}' is updatable" do
|
26
|
+
expect(subject.class_variable_get('@@updatable_attributes')[subject]).to include "@#{attribute}"
|
19
27
|
end
|
20
28
|
end
|
21
29
|
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PhoneGap::Build::RestResource do
|
4
|
+
|
5
|
+
let(:base_uri) { 'https://build.phonegap.com/api/v1/' }
|
6
|
+
|
7
|
+
context 'when an authentication token is present' do
|
8
|
+
|
9
|
+
let(:token) { 'BATMAN' }
|
10
|
+
|
11
|
+
before do
|
12
|
+
PhoneGap::Build::Credentials.instance.token = token
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when used in a child class' do
|
16
|
+
|
17
|
+
class Child < PhoneGap::Build::RestResource
|
18
|
+
|
19
|
+
attr_accessor :id
|
20
|
+
|
21
|
+
PATH = 'users'
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
subject { Child.new }
|
26
|
+
|
27
|
+
describe '#create' do
|
28
|
+
|
29
|
+
let(:response) { double('response', success?: false) }
|
30
|
+
|
31
|
+
before do
|
32
|
+
subject.class.stub(:post).with("users?auth_token=#{token}", query: {data: subject.as_json}).and_return response
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'sends POST request' do
|
36
|
+
expect(subject.class).to receive(:post).and_return response
|
37
|
+
subject.create
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'uses the resource base as the path and includes the auth token in the request' do
|
41
|
+
expect(subject.class).to receive(:post).with("users?auth_token=#{token}", anything()).and_return response
|
42
|
+
subject.create
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'sends a body containing all the json representation of the object' do
|
46
|
+
expect(subject.class).to receive(:post).with(anything(), query: {data: {}}).and_return response
|
47
|
+
subject.create
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'after successful creation' do
|
51
|
+
|
52
|
+
let(:success_response) { double('response', success?: true, body: '{"title" : "Batman", "rating" : 5}') }
|
53
|
+
|
54
|
+
before do
|
55
|
+
subject.class.stub(:post).with("users?auth_token=#{token}", query: {data: {}}).and_return success_response
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'updates the object with any response attributes' do
|
59
|
+
response = subject.create
|
60
|
+
expect(response).to be_kind_of Child
|
61
|
+
expect(response.instance_variable_get('@title')).to eq 'Batman'
|
62
|
+
expect(response.instance_variable_get('@rating')).to eq 5
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#update' do
|
68
|
+
|
69
|
+
context 'when the object has an id' do
|
70
|
+
|
71
|
+
let(:id) { double('id') }
|
72
|
+
|
73
|
+
before do
|
74
|
+
subject.id = id
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'sends PUT request' do
|
78
|
+
expect(subject.class).to receive(:put)
|
79
|
+
subject.update
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'uses the resource base as the path and includes the auth token in the request' do
|
83
|
+
expect(subject.class).to receive(:put).with("users/#{id}?auth_token=#{token}", anything())
|
84
|
+
subject.update
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'send a body containing all the json representation of the object' do
|
88
|
+
expect(subject.class).to receive(:put).with(anything(), query: {data: {}})
|
89
|
+
subject.update
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'after successful update' do
|
93
|
+
|
94
|
+
it 'returns the populated object'
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#save' do
|
101
|
+
|
102
|
+
context 'when the child object has an id attribute' do
|
103
|
+
|
104
|
+
before do
|
105
|
+
subject.id = 69
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'attempts to update an existing item' do
|
109
|
+
expect(subject.class).to receive(:put)
|
110
|
+
subject.save
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context 'when the child object doesn\'t have an id attribute' do
|
115
|
+
|
116
|
+
let(:http_response) { double('response', success?: false) }
|
117
|
+
|
118
|
+
before do
|
119
|
+
subject.id = nil
|
120
|
+
subject.class.stub(:post).and_return http_response
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'attempts to create a new item' do
|
124
|
+
expect(subject.class).to receive(:post)
|
125
|
+
subject.save
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '#destroy' do
|
131
|
+
|
132
|
+
context 'when the object has an id' do
|
133
|
+
|
134
|
+
let(:id) { double('id') }
|
135
|
+
|
136
|
+
before do
|
137
|
+
subject.id = id
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'sends DELETE request' do
|
141
|
+
expect(subject.class).to receive(:delete)
|
142
|
+
subject.destroy
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'includes the auth token in the request' do
|
146
|
+
expect(subject.class).to receive(:delete).with("users/#{id}?auth_token=#{token}")
|
147
|
+
subject.destroy
|
148
|
+
end
|
149
|
+
|
150
|
+
context 'upon successful deletion' do
|
151
|
+
|
152
|
+
it 'does something'
|
153
|
+
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'when the object does not have an id' do
|
158
|
+
|
159
|
+
it 'returns an error'
|
160
|
+
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe '#as_json' do
|
165
|
+
|
166
|
+
context 'when there are instance variables' do
|
167
|
+
|
168
|
+
before do
|
169
|
+
subject.instance_variable_set('@superman', 'superman')
|
170
|
+
subject.instance_variable_set('@spiderman', 'spiderman')
|
171
|
+
subject.instance_variable_set('@batman', 'batman')
|
172
|
+
end
|
173
|
+
|
174
|
+
context 'when given a list of variables to use' do
|
175
|
+
|
176
|
+
let(:attributes) { ['@superman', '@spiderman'] }
|
177
|
+
|
178
|
+
it 'returns a hash of the given attributes and their values' do
|
179
|
+
expect(subject.as_json(only: attributes)).to eq({superman: 'superman', spiderman: 'spiderman'})
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
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.2.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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: httmultiparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -95,11 +95,15 @@ files:
|
|
95
95
|
- lib/phone_gap/build.rb
|
96
96
|
- lib/phone_gap/build/app.rb
|
97
97
|
- lib/phone_gap/build/app_factory.rb
|
98
|
+
- lib/phone_gap/build/creatable.rb
|
98
99
|
- lib/phone_gap/build/credentials.rb
|
100
|
+
- lib/phone_gap/build/rest_resource.rb
|
99
101
|
- lib/phone_gap/build/version.rb
|
100
102
|
- phone_gap-build.gemspec
|
101
103
|
- spec/fixtures/api_responses/get-apps.json
|
104
|
+
- spec/fixtures/api_responses/rest-resource-create.json
|
102
105
|
- spec/phone_gap/build/app_spec.rb
|
106
|
+
- spec/phone_gap/build/rest_resource_spec.rb
|
103
107
|
- spec/phone_gap/build_spec.rb
|
104
108
|
- spec/spec_helper.rb
|
105
109
|
- spec/support/fixtures.rb
|
@@ -129,7 +133,9 @@ specification_version: 4
|
|
129
133
|
summary: PhoneGap Build Api gem
|
130
134
|
test_files:
|
131
135
|
- spec/fixtures/api_responses/get-apps.json
|
136
|
+
- spec/fixtures/api_responses/rest-resource-create.json
|
132
137
|
- spec/phone_gap/build/app_spec.rb
|
138
|
+
- spec/phone_gap/build/rest_resource_spec.rb
|
133
139
|
- spec/phone_gap/build_spec.rb
|
134
140
|
- spec/spec_helper.rb
|
135
141
|
- spec/support/fixtures.rb
|