aptible-api 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -11
- data/aptible-api.gemspec +1 -1
- data/lib/aptible/api/account.rb +5 -0
- data/lib/aptible/api/resource.rb +21 -1
- data/spec/aptible/api/resource_spec.rb +9 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d2457b7c3accb03805735dfaaa760880eee3588
|
4
|
+
data.tar.gz: 30e94d083309a23e8ef0da7e2f7a19ab284f949a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cab3f8b2378c7cdba2abfb5ee9c5fee35cd2d66032fcc544da03f85f7da212bb44e7a2039b26a09d6412456cf99810c00917bba7244f031e3cf909f8fd65bcb5
|
7
|
+
data.tar.gz: dd7e70a80f2ce6b4197c21a55b16e078436c1ba2020b3bd37a756b166c69e1211c3e3d329c72bedb62964e618fb8d76efb4c046e4c5e7d770d18e299eb572b50
|
data/README.md
CHANGED
@@ -24,21 +24,18 @@ First, get a token:
|
|
24
24
|
token = Aptible::Auth::Token.new(email: 'user0@example.com', password: 'password')
|
25
25
|
```
|
26
26
|
|
27
|
-
Then, initialize a client:
|
28
|
-
```ruby
|
29
|
-
api = Aptible::Api::Client.new(token: token)
|
30
|
-
```
|
31
|
-
|
32
27
|
From here, you can interact with the Authorization API however you wish:
|
33
28
|
|
34
29
|
```ruby
|
35
|
-
api.
|
30
|
+
api = Aptible::Api.new(token: token)
|
31
|
+
account = api.accounts.first
|
32
|
+
account.apps.count
|
36
33
|
# => 4
|
37
|
-
|
38
|
-
# => "
|
39
|
-
|
40
|
-
|
41
|
-
# => "http://localhost:
|
34
|
+
account.apps.first.handle
|
35
|
+
# => "foodle"
|
36
|
+
newapp = account.create_app(handle: 'bardle')
|
37
|
+
newapp.href
|
38
|
+
# => "http://localhost:4001/apps/7"
|
42
39
|
```
|
43
40
|
|
44
41
|
## Configuration
|
data/aptible-api.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'English'
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'aptible-api'
|
9
|
-
spec.version = '0.2.
|
9
|
+
spec.version = '0.2.2'
|
10
10
|
spec.authors = ['Frank Macreery']
|
11
11
|
spec.email = ['frank@macreery.com']
|
12
12
|
spec.description = %q{Ruby client for api.aptible.com}
|
data/lib/aptible/api/account.rb
CHANGED
data/lib/aptible/api/resource.rb
CHANGED
@@ -27,8 +27,22 @@ module Aptible
|
|
27
27
|
nil
|
28
28
|
end
|
29
29
|
|
30
|
+
def self.create(options)
|
31
|
+
token = options.delete(:token)
|
32
|
+
auth = Api.new(token: token)
|
33
|
+
auth.send(basename).create(options)
|
34
|
+
end
|
35
|
+
|
30
36
|
# rubocop:disable PredicateName
|
31
37
|
def self.has_many(relation)
|
38
|
+
define_has_many_getter(relation)
|
39
|
+
define_has_many_setter(relation)
|
40
|
+
end
|
41
|
+
# rubocop:enable PredicateName
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def self.define_has_many_getter(relation)
|
32
46
|
define_method relation do
|
33
47
|
get unless loaded
|
34
48
|
if (memoized = instance_variable_get("@#{relation}"))
|
@@ -38,7 +52,13 @@ module Aptible
|
|
38
52
|
end
|
39
53
|
end
|
40
54
|
end
|
41
|
-
|
55
|
+
|
56
|
+
def self.define_has_many_setter(relation)
|
57
|
+
define_method "create_#{relation.to_s.singularize}" do |options = {}|
|
58
|
+
get unless loaded
|
59
|
+
links[relation].create(options)
|
60
|
+
end
|
61
|
+
end
|
42
62
|
end
|
43
63
|
end
|
44
64
|
|
@@ -40,4 +40,13 @@ describe Aptible::Api::Resource do
|
|
40
40
|
Aptible::Api::App.all(options)
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
describe '.create' do
|
45
|
+
it 'should create a new top-level resource' do
|
46
|
+
apps = double Aptible::Api
|
47
|
+
Aptible::Api.stub_chain(:new, :apps) { apps }
|
48
|
+
expect(apps).to receive(:create).with(foo: 'bar')
|
49
|
+
Aptible::Api::App.create(foo: 'bar')
|
50
|
+
end
|
51
|
+
end
|
43
52
|
end
|