aptible-auth 0.2.1 → 0.3.0

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: 05b6f13b708d4d05d8f553239c5ed83f6a41c2d2
4
- data.tar.gz: fcf947d45817171ba9f2475eb02e7e2427d25d9f
3
+ metadata.gz: 2fba294330104e596ef5313e4adaf0d4dbd72565
4
+ data.tar.gz: 233fd28c3182778fd16f82cf0f7ecef63aa185aa
5
5
  SHA512:
6
- metadata.gz: eb8ed96ad97b48e2d9f3187ad25cf1958e07ebc76ca40a2b02ddc5c48138eacbf27cb2fdf948f4e3ea5d01e9dd517edd8ad3999a2d64189261c6dc1045173efb
7
- data.tar.gz: c4915d38cc80121139bd52502f37d668dae10e7777bc0e33264fc5c447670bc57c6833851873c5a3d709b994a3e95887e75c27d04c49e7991e9ad9af2bf73ffb
6
+ metadata.gz: b5bb3c60cb4e2efd1e50f059087c690609f46d4c5365d6daebfd59b3ba93b77b4c54fa61165eb7e3e5e2edbeed060180edfc60c7682699aa47bc83171c6d8cec
7
+ data.tar.gz: b8d0210d77d9495d7a7a078251fbc9184605a59069dbe6da979c331e6b7ade6104229a8a09876b3e7dcb7daba7e9e2240a2734d20d7437367e5f5d0159a8e6c8
data/Gemfile CHANGED
@@ -1,7 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'oauth2', github: 'fancyremarker/oauth2', branch: 'aptible'
4
- gem 'hyperresource', github: 'fancyremarker/hyperresource', branch: 'aptible'
5
-
6
3
  # Specify your gem's dependencies in aptible-auth.gemspec
7
4
  gemspec
data/README.md CHANGED
@@ -8,18 +8,18 @@ Ruby client for [auth.aptible.com](https://auth.aptible.com/). Aptible's authori
8
8
 
9
9
  ## Installation
10
10
 
11
- Add the following lines to your application's Gemfile.
11
+ Add the following line to your application's Gemfile.
12
12
 
13
13
  gem 'aptible-auth'
14
- gem 'oauth2', github: 'fancyremarker/oauth2', branch: 'aptible'
15
- gem 'hyperresource', github: 'fancyremarker/hyperresource', branch: 'aptible'
14
+
15
+ And then run `bundle install`.
16
+
17
+ The gem depends on forked releases of the `oauth2` and `hyperresource` gems.
16
18
 
17
19
  The forked version of the OAuth2 gem is necessary until [intridea/oauth2#165](https://github.com/intridea/oauth2/pull/165) and [intridea/oauth2#166](https://github.com/intridea/oauth2/pull/166) are merged.
18
20
 
19
21
  The forked version of the HyperResource gem is necessary until [gamache/hyperresource#22](https://github.com/gamache/hyperresource/pull/22) and [gamache/hyperresource#23](https://github.com/gamache/hyperresource/pull/23) are merged.
20
22
 
21
- And then run `bundle install`.
22
-
23
23
  ## Usage
24
24
 
25
25
  First, get a token:
@@ -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.2.1'
9
+ spec.version = '0.3.0'
10
10
  spec.authors = ['Frank Macreery']
11
11
  spec.email = ['frank@macreery.com']
12
12
  spec.description = 'Ruby client for auth.aptible.com'
@@ -19,13 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'gem_config'
22
- spec.add_dependency 'oauth2'
23
- spec.add_dependency 'hyperresource'
22
+ spec.add_dependency 'oauth2-aptible'
23
+ spec.add_dependency 'hyperresource-aptible'
24
24
  spec.add_dependency 'fridge'
25
+ spec.add_dependency 'activesupport'
25
26
 
26
27
  spec.add_development_dependency 'bundler', '~> 1.3'
27
28
  spec.add_development_dependency 'aptible-tasks', '>= 0.2.0'
28
- spec.add_development_dependency 'activesupport'
29
29
  spec.add_development_dependency 'rake'
30
30
  spec.add_development_dependency 'rspec', '~> 2.0'
31
31
  spec.add_development_dependency 'pry'
@@ -1,4 +1,12 @@
1
1
  module Aptible
2
2
  class Auth::Organization < Auth::Resource
3
+ has_many :roles
4
+
5
+ def accounts
6
+ api = Aptible::Api.new(token: token, headers: headers)
7
+ api.get unless api.loaded
8
+ accounts = api.accounts.entries
9
+ accounts.select { |account| account.organization.href == href }
10
+ end
3
11
  end
4
12
  end
@@ -1,9 +1,36 @@
1
+ require 'active_support/inflector'
2
+
1
3
  module Aptible
2
4
  class Auth::Resource < Auth
5
+ def self.collection_url
6
+ basename = name.split('::').last
7
+ config = Aptible::Auth.configuration
8
+ config.root_url.chomp('/') + "/#{basename.downcase.pluralize}"
9
+ end
10
+
11
+ def self.find(id)
12
+ find_by_url("#{collection_url}/#{id}")
13
+ end
14
+
3
15
  def self.find_by_url(url)
4
16
  # REVIEW: Should exception be raised if return type mismatch?
5
17
  new.find_by_url(url)
18
+ rescue
19
+ nil
20
+ end
21
+
22
+ # rubocop:disable PredicateName
23
+ def self.has_many(relation)
24
+ define_method relation do
25
+ get unless loaded
26
+ if (memoized = instance_variable_get("@#{relation}"))
27
+ memoized
28
+ elsif links[relation]
29
+ instance_variable_set("@#{relation}", links[relation].entries)
30
+ end
31
+ end
6
32
  end
33
+ # rubocop:enable PredicateName
7
34
  end
8
35
  end
9
36
 
@@ -1,5 +1,7 @@
1
1
  module Aptible
2
2
  class Auth::User < Auth::Resource
3
+ has_many :roles
4
+
3
5
  def verified?
4
6
  !!attributes['verified']
5
7
  end
@@ -8,6 +10,11 @@ module Aptible
8
10
  roles.map(&:organization)
9
11
  end
10
12
 
13
+ def operations
14
+ # TODO: Implement query params for /operations
15
+ []
16
+ end
17
+
11
18
  def privileged_organizations
12
19
  privileged_roles.map(&:organization)
13
20
  end
@@ -1,4 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
- # describe Aptible::Auth::Resource do
4
- # end
3
+ describe Aptible::Auth::Resource do
4
+ describe '.collection_url' do
5
+ it 'should use the pluralized resource name' do
6
+ url = Aptible::Auth::Role.collection_url
7
+ expect(url).to eq 'https://auth.aptible.com/roles'
8
+ end
9
+ end
10
+
11
+ describe '.find' do
12
+ it 'should call find_by_url' do
13
+ url = 'https://auth.aptible.com/roles/42'
14
+ expect(Aptible::Auth::Role).to receive(:find_by_url).with url
15
+ Aptible::Auth::Role.find(42)
16
+ end
17
+ end
18
+ 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.2.1
4
+ version: 0.3.0
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-07 00:00:00.000000000 Z
11
+ date: 2014-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_config
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: oauth2
28
+ name: oauth2-aptible
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '>='
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: hyperresource
42
+ name: hyperresource-aptible
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '>='
@@ -67,47 +67,47 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: bundler
70
+ name: activesupport
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
- version: '1.3'
76
- type: :development
75
+ version: '0'
76
+ type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
- version: '1.3'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: aptible-tasks
84
+ name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: 0.2.0
89
+ version: '1.3'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: 0.2.0
96
+ version: '1.3'
97
97
  - !ruby/object:Gem::Dependency
98
- name: activesupport
98
+ name: aptible-tasks
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '>='
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 0.2.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 0.2.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rake
113
113
  requirement: !ruby/object:Gem::Requirement