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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf5bb691c313660234c7a06c17826cd33df75f9d
4
- data.tar.gz: e44dff1c1e3a995f59f4156724861a5ff092fc08
3
+ metadata.gz: 9d2457b7c3accb03805735dfaaa760880eee3588
4
+ data.tar.gz: 30e94d083309a23e8ef0da7e2f7a19ab284f949a
5
5
  SHA512:
6
- metadata.gz: 4c0d90be3dde38ed35651f47c26e230c8c90f009cd61b1f6feb513c5518573be7207b9869e826466faf1c891c29d587554aa58ed9fab1346a13f3e374119313a
7
- data.tar.gz: 2902b720d1751424f4cb2daa540b05e09217fe78d5fde6b20f37fe43f94f762478b095eda3b243ccdf2520a138d1a9c566162bd8c9e282f788512edd350b1842
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.get.clients.count
30
+ api = Aptible::Api.new(token: token)
31
+ account = api.accounts.first
32
+ account.apps.count
36
33
  # => 4
37
- api.get.clients.first.name
38
- # => "Client 0"
39
- client = api.get.clients.create(name: 'Dogeclient')
40
- client.href
41
- # => "http://localhost:4000/clients/60765b69-ffd8-4762-b9d2-96354ddb16f9"
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.1'
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}
@@ -12,5 +12,10 @@ module Aptible
12
12
  # TODO: Implement /accounts/:id/operations
13
13
  []
14
14
  end
15
+
16
+ def organization
17
+ auth = Aptible::Auth::Resource.new(token: token, headers: headers)
18
+ auth.find_by_url(links['organization'].href)
19
+ end
15
20
  end
16
21
  end
@@ -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
- # rubocop:enable PredicateName
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery