aptible-auth 0.4.2 → 0.4.3

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: 43d3b3d8495d9fa28087f251c458b515abbe30b9
4
- data.tar.gz: 39012d00859e3399cb74e143bcfceb1da538b34c
3
+ metadata.gz: a8af4bf9e2e8ac1bb6966eaee5354eec672ca3a8
4
+ data.tar.gz: 469679f0afb91b09d850ad2a74d120aad664daa5
5
5
  SHA512:
6
- metadata.gz: 236005d58bd5fbe2852c82115dbdfa5a8ede1fbc676c63768cf2ff65c9fac4d0c05650583832236237d091c006ae11f92149371565ffd1547c515c324f66bf54
7
- data.tar.gz: ac7ebe93e7342b4a87820ae5aaf843c6dda08116b8860f5451e5b04c4f5a12e5617a64ff067ab1bfb86742412e15e87712e46a1303453be5f4e30a52e0ed3551
6
+ metadata.gz: ea85782e75ddace3eb78f66a3abab1f25b3f224c1256ece3a225f35f23bcbd54a824a3d735ac44bc3cb2f079a5d9269549742b4af92f0b33ecb30bccc3ae5259
7
+ data.tar.gz: b93bac000b8b1234a4beb3930fc9415c165ff72199535afa7679f1c5132ef55b740373fee970950cfc97494e1b9d682eee227866b965273387a61ef14f751b33
@@ -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.4.2'
9
+ spec.version = '0.4.3'
10
10
  spec.authors = ['Frank Macreery']
11
11
  spec.email = ['frank@macreery.com']
12
12
  spec.description = 'Ruby client for auth.aptible.com'
@@ -3,6 +3,14 @@ module Aptible
3
3
  class Auth::Organization < Auth::Resource
4
4
  has_many :roles
5
5
 
6
+ def security_officer
7
+ # REVIEW: Examine underlying data model for a less arbitrary solution
8
+ security_officers_role = roles.find do |role|
9
+ role.name == 'Security Officers'
10
+ end
11
+ security_officers_role.users.first if security_officers_role
12
+ end
13
+
6
14
  def accounts
7
15
  api = Aptible::Api.new(token: token, headers: headers)
8
16
  api.get unless api.loaded
@@ -33,10 +33,10 @@ module Aptible
33
33
  end
34
34
  end
35
35
 
36
- def self.create(options)
37
- token = options.delete(:token)
36
+ def self.create(params)
37
+ token = params.delete(:token)
38
38
  auth = Auth.new(token: token)
39
- auth.send(basename).create(options)
39
+ auth.send(basename).create(normalize_params(params))
40
40
  end
41
41
 
42
42
  # rubocop:disable PredicateName
@@ -57,7 +57,21 @@ module Aptible
57
57
  end
58
58
  end
59
59
 
60
- private
60
+ def self.normalize_params(params = {})
61
+ params_array = params.map do |key, value|
62
+ value.is_a?(HyperResource) ? [key, value.href] : [key, value]
63
+ end
64
+ Hash[params_array]
65
+ end
66
+
67
+ def update(params = {})
68
+ super(self.class.normalize_params(params))
69
+ end
70
+
71
+ # NOTE: The following does not update the object in-place
72
+ def reload
73
+ self.class.find_by_url(href, headers: headers)
74
+ end
61
75
 
62
76
  def self.define_has_many_getter(relation)
63
77
  define_method relation do
@@ -71,9 +85,9 @@ module Aptible
71
85
  end
72
86
 
73
87
  def self.define_has_many_setter(relation)
74
- define_method "create_#{relation.to_s.singularize}" do |options = {}|
88
+ define_method "create_#{relation.to_s.singularize}" do |params = {}|
75
89
  get unless loaded
76
- links[relation].create(options)
90
+ links[relation].create(self.class.normalize_params(params))
77
91
  end
78
92
  end
79
93
  end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aptible::Auth::Organization do
4
+ describe '#security_officer' do
5
+ let(:role) { double 'Aptible::Auth::Role' }
6
+ let(:user) { double 'Aptible::Auth::User' }
7
+
8
+ before { role.stub(:name) { 'Security Officers' } }
9
+ before { role.stub(:users) { [user] } }
10
+
11
+ it 'should return the first member of the security officers role' do
12
+ subject.stub(:roles) { [role] }
13
+ expect(subject.security_officer).to eq user
14
+ end
15
+
16
+ it 'should return nil if there is no such role' do
17
+ subject.stub(:roles) { [] }
18
+ expect(subject.security_officer).to be_nil
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-28 00:00:00.000000000 Z
11
+ date: 2014-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_config
@@ -176,6 +176,7 @@ files:
176
176
  - lib/aptible/auth/session.rb
177
177
  - lib/aptible/auth/token.rb
178
178
  - lib/aptible/auth/user.rb
179
+ - spec/aptible/auth/organization_spec.rb
179
180
  - spec/aptible/auth/resource_spec.rb
180
181
  - spec/aptible/auth/token_spec.rb
181
182
  - spec/aptible/auth_spec.rb
@@ -201,11 +202,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
202
  version: '0'
202
203
  requirements: []
203
204
  rubyforge_project:
204
- rubygems_version: 2.2.1
205
+ rubygems_version: 2.2.2
205
206
  signing_key:
206
207
  specification_version: 4
207
208
  summary: Ruby client for auth.aptible.com
208
209
  test_files:
210
+ - spec/aptible/auth/organization_spec.rb
209
211
  - spec/aptible/auth/resource_spec.rb
210
212
  - spec/aptible/auth/token_spec.rb
211
213
  - spec/aptible/auth_spec.rb