aptible-auth 0.3.1 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c11aa57a4ce568364c6a15d9b10705c760adac2f
4
- data.tar.gz: af79f64c068aa5d7c4f2317da1987ac3cf7995f0
3
+ metadata.gz: de55501fb9d9bba196c315fa4c9e3c4bbc5db1a5
4
+ data.tar.gz: 625a173e5f59d42eea65758ab64d64b86152bb29
5
5
  SHA512:
6
- metadata.gz: 8ef0b24dd70e5e975a296a891445752083f67d1e9b901e2172cc72d89d37c1e7a7fccb1a05430d453af3d1ce0140eee688eb4ee7df56f65e568abd9b2da72493
7
- data.tar.gz: 750595b584386a619ada01656482562a9a9b2cfbe8ee73b3dfa06651f926b3e10f4efd69aeed7f5352022222a26bff98e2d2794cdc74b3f08f840e4640eba689
6
+ metadata.gz: a6f702280e3e3481a521b0fac4b3965f6bdd6a4b8fad15d95520b0399a69d7c214d142f6f91ac2dc9a9c81495574d301c4b5ecc6540da72a47ad006e366e572a
7
+ data.tar.gz: 67aaf8c6ba45fb3f15c22b3955545600398ecbd3e259d68581e335131619f1270baa7544414296ff06d8af8bb9cdb9cb2c567f311d3477cef810d50c3d08632c
data/README.md CHANGED
@@ -28,19 +28,13 @@ First, get a token:
28
28
  token = Aptible::Auth::Token.create(email: 'user0@example.com', password: 'password')
29
29
  ```
30
30
 
31
- Then, initialize a resource agent:
32
- ```ruby
33
- auth = Aptible::Auth.new(token: token)
34
- ```
35
-
36
31
  From here, you can interact with the Authorization API however you wish:
37
32
 
38
33
  ```ruby
39
- auth.get.clients.count
40
- # => 4
41
- auth.get.clients.first.name
34
+ auth = Aptible::Auth.new(token: token)
35
+ auth.clients.first.name
42
36
  # => "Client 0"
43
- client = auth.get.clients.create(name: 'Dogeclient')
37
+ client = Aptible::Auth::Client.create(token: token, name: 'Dogeclient')
44
38
  client.href
45
39
  # => "http://localhost:4000/clients/60765b69-ffd8-4762-b9d2-96354ddb16f9"
46
40
  ```
data/aptible-auth.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'English'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
8
  spec.name = 'aptible-auth'
9
- spec.version = '0.3.1'
9
+ spec.version = '0.3.2'
10
10
  spec.authors = ['Frank Macreery']
11
11
  spec.email = ['frank@macreery.com']
12
12
  spec.description = 'Ruby client for auth.aptible.com'
@@ -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 = Auth.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::Auth::Resource do
40
40
  Aptible::Auth::Session.all(options)
41
41
  end
42
42
  end
43
+
44
+ describe '.create' do
45
+ it 'should create a new top-level resource' do
46
+ sessions = double Aptible::Auth
47
+ Aptible::Auth.stub_chain(:new, :sessions) { sessions }
48
+ expect(sessions).to receive(:create).with(foo: 'bar')
49
+ Aptible::Auth::Session.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-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery