people-ruby 0.1.1
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 +7 -0
- data/.gitignore +11 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +63 -0
- data/Rakefile +1 -0
- data/lib/people.rb +6 -0
- data/lib/people/api/v1.rb +12 -0
- data/lib/people/api/v1/persons.rb +62 -0
- data/lib/people/api/v1/roles.rb +22 -0
- data/lib/people/client.rb +12 -0
- data/lib/people/exception.rb +39 -0
- data/lib/people/http_proxy.rb +31 -0
- data/lib/people/initializer.rb +40 -0
- data/lib/people/version.rb +3 -0
- data/people-ruby.gemspec +27 -0
- metadata +103 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 66f771ab87ee148d6270557144373d1c35facace
|
|
4
|
+
data.tar.gz: 377b59a8ec4acbfa37fc94bbb2fb74fc109b31ee
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a9cb33435af8531bb5387b9705660b551672466f54bca91dc9966800b695bc869684fde120bc6285a00ce34b78b6e97899053969db17fd046a31b980d73f214c
|
|
7
|
+
data.tar.gz: 99c8d0e6b4e15b3084018a47c1ef8cc1ab25683623ec99ecde3f91e5611c1694b34476cade4870a88d006821e35229af257a00a2df30a59a948a158c4d9291f1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015 Raz Konforti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
data/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# People Ruby bindings
|
|
2
|
+
|
|
3
|
+
The People Ruby bindings provide a small SDK for convenient access to the People API from applications written in the Ruby language.
|
|
4
|
+
|
|
5
|
+
## Documentation
|
|
6
|
+
|
|
7
|
+
[API Docs](http://www.konforti.net/slate)
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
You don't need this source code unless you want to modify the gem.
|
|
12
|
+
If you just want to use the People Ruby bindings, you should run:
|
|
13
|
+
|
|
14
|
+
``` bash
|
|
15
|
+
$ gem install people
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
or with [Bundler](http://bundler.io)
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
gem 'people'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
If you want to build the gem from source:
|
|
25
|
+
|
|
26
|
+
``` bash
|
|
27
|
+
$ gem build people.gemspec
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Basic usage
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
require "people"
|
|
34
|
+
|
|
35
|
+
people = People::Client.new(
|
|
36
|
+
secret_key: "YOUR SECRET KEY",
|
|
37
|
+
domain: "YOUR People's installation path"
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
puts people.get_users
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Development
|
|
44
|
+
|
|
45
|
+
If you want to build the gem from source:
|
|
46
|
+
|
|
47
|
+
``` bash
|
|
48
|
+
$ gem build people.gemspec
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
52
|
+
|
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
54
|
+
|
|
55
|
+
## Contributing
|
|
56
|
+
|
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/konforti/people-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org/ ) code of conduct.
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
## License
|
|
61
|
+
|
|
62
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
63
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/people.rb
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module People
|
|
2
|
+
module Api
|
|
3
|
+
module V1
|
|
4
|
+
module Persons
|
|
5
|
+
|
|
6
|
+
# Users list
|
|
7
|
+
def persons(*args)
|
|
8
|
+
path = '/api/v1/persons/'
|
|
9
|
+
path += "?search=#{args['search']}" if args.include? 'search'
|
|
10
|
+
path += "?limit=#{args['limit']}" if args.include? 'limit'
|
|
11
|
+
path += "?page=#{args['page']}" if args.include? 'page'
|
|
12
|
+
path += "?sort=#{args['sort']}" if args.include? 'sort'
|
|
13
|
+
get(path)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
alias_method :get_persons, :persons
|
|
17
|
+
alias_method :get_users, :persons
|
|
18
|
+
|
|
19
|
+
# Get User.
|
|
20
|
+
def person(id)
|
|
21
|
+
path = "/api/v1/persons/#{id}"
|
|
22
|
+
get(path)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
alias_method :get_person, :person
|
|
26
|
+
alias_method :get_user, :person
|
|
27
|
+
|
|
28
|
+
# Get the Current User
|
|
29
|
+
def current_person
|
|
30
|
+
jwt = cookies['people.jwt']
|
|
31
|
+
path = "/api/v1/persons/current/#{jwt}"
|
|
32
|
+
get(path)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
alias_method :get_current_person, :current_person
|
|
36
|
+
alias_method :get_current_user, :current_person
|
|
37
|
+
|
|
38
|
+
def update_person(id, payload)
|
|
39
|
+
path = "/api/v1/persons/#{id}"
|
|
40
|
+
put(path, query: payload)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
alias_method :update_user, :update_person
|
|
44
|
+
|
|
45
|
+
def person_add_role(id, role)
|
|
46
|
+
path = "/api/v1/persons/#{id}/roles"
|
|
47
|
+
post(path, query: role)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
alias_method :user_add_role, :person_add_role
|
|
51
|
+
|
|
52
|
+
def person_remove_role(id, role)
|
|
53
|
+
path = "/api/v1/persons/#{id}/roles/#{role}"
|
|
54
|
+
delete(path)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
alias_method :user_add_role, :person_add_role
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module People
|
|
2
|
+
module Api
|
|
3
|
+
module V1
|
|
4
|
+
module Roles
|
|
5
|
+
def roles
|
|
6
|
+
path = 'api/v1/roles/'
|
|
7
|
+
get(path)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# alias_method :get_roles, :roles
|
|
11
|
+
|
|
12
|
+
def role(rid)
|
|
13
|
+
path = "api/v1/roles/#{rid}"
|
|
14
|
+
get(path)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
alias_method :get_role, :role
|
|
18
|
+
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module People
|
|
2
|
+
|
|
3
|
+
class Exception < StandardError;
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
class Unauthorized < People::Exception;
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class NotFound < People::Exception;
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class Unsupported < People::Exception;
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
class ServerError < People::Exception;
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class BadRequest < People::Exception;
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class MissingUserId < People::Exception;
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class MissingConnectionId < People::Exception;
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class AccessDenied < People::Exception;
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
class InvalidParameter < People::Exception;
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class InvalidCredentials < People::Exception;
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
class InvalidApiNamespace < People::Exception;
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module People
|
|
2
|
+
module HttpProxy
|
|
3
|
+
%i(get post put patch delete).each do |method|
|
|
4
|
+
define_method(method) do |path, body = {}|
|
|
5
|
+
safe_path = URI.escape(path)
|
|
6
|
+
body = body.delete_if { |_, v| v.nil? }
|
|
7
|
+
if method == :get
|
|
8
|
+
result = self.class.send(method, safe_path, query: body)
|
|
9
|
+
else
|
|
10
|
+
result = self.class.send(method, safe_path, body: body.to_json)
|
|
11
|
+
end
|
|
12
|
+
response_body =
|
|
13
|
+
begin
|
|
14
|
+
JSON.parse(result.body.to_s)
|
|
15
|
+
rescue JSON::ParserError
|
|
16
|
+
result.body
|
|
17
|
+
end
|
|
18
|
+
case result.code
|
|
19
|
+
when 200...226 then response_body
|
|
20
|
+
when 400 then fail People::BadRequest, response_body
|
|
21
|
+
when 401 then fail People::Unauthorized, response_body
|
|
22
|
+
when 403 then fail People::AccessDenied, response_body
|
|
23
|
+
when 404 then fail People::NotFound, response_body
|
|
24
|
+
when 500 then fail People::ServerError, response_body
|
|
25
|
+
else
|
|
26
|
+
fail People::Unsupported, response_body
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'people/api/v1'
|
|
2
|
+
|
|
3
|
+
module People
|
|
4
|
+
module Initializer
|
|
5
|
+
def initialize(config)
|
|
6
|
+
options = config.deep_symbolize_keys
|
|
7
|
+
self.class.base_uri base_url(options[:domain])
|
|
8
|
+
self.class.headers headers(options)
|
|
9
|
+
self.class.basic_auth *auth(options[:secret_key])
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def auth(secret_key)
|
|
15
|
+
extend People::Api::V1
|
|
16
|
+
fail InvalidCredentials, 'Invalid API v1 secret_key' if secret_key.nil?
|
|
17
|
+
[secret_key, '']
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def base_url(domain)
|
|
21
|
+
fail InvalidApiNamespace, 'Api namespace must supply an API domain' if domain.nil?
|
|
22
|
+
"#{domain}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def headers(options)
|
|
26
|
+
headers = {}
|
|
27
|
+
client_info = JSON.dump(name: 'ruby-people', version: People::VERSION)
|
|
28
|
+
|
|
29
|
+
headers['Content-Type'] = 'application/json'
|
|
30
|
+
|
|
31
|
+
unless options[:opt_out_sdk_info]
|
|
32
|
+
headers['User-Agent'] = "Ruby/#{RUBY_VERSION}"
|
|
33
|
+
headers['People-Client'] = Base64.urlsafe_encode64(client_info)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
headers
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
data/people-ruby.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
|
|
5
|
+
require 'people/version'
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = 'people-ruby'
|
|
9
|
+
spec.version = People::VERSION
|
|
10
|
+
spec.authors = ['Raz Konforti']
|
|
11
|
+
spec.email = ['konforti@gmail.com']
|
|
12
|
+
spec.required_ruby_version = '>= 2.2.2'
|
|
13
|
+
spec.summary = 'Ruby bindings for People - Remote Identity Management People'
|
|
14
|
+
spec.description = 'The People Ruby bindings provide a small SDK for convenient access to the People API from applications written in the Ruby language.'
|
|
15
|
+
spec.homepage = 'https://github.com/konforti/people-ruby'
|
|
16
|
+
spec.license = 'MIT'
|
|
17
|
+
|
|
18
|
+
spec.files = `git ls-files`.split("\n")
|
|
19
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
20
|
+
|
|
21
|
+
spec.require_paths = ['lib']
|
|
22
|
+
|
|
23
|
+
spec.add_dependency 'httparty', '~> 0.13'
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: people-ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Raz Konforti
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-12-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: httparty
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.13'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.13'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.10'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.10'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
description: The People Ruby bindings provide a small SDK for convenient access to
|
|
56
|
+
the People API from applications written in the Ruby language.
|
|
57
|
+
email:
|
|
58
|
+
- konforti@gmail.com
|
|
59
|
+
executables: []
|
|
60
|
+
extensions: []
|
|
61
|
+
extra_rdoc_files: []
|
|
62
|
+
files:
|
|
63
|
+
- ".gitignore"
|
|
64
|
+
- Gemfile
|
|
65
|
+
- LICENSE
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- lib/people.rb
|
|
69
|
+
- lib/people/api/v1.rb
|
|
70
|
+
- lib/people/api/v1/persons.rb
|
|
71
|
+
- lib/people/api/v1/roles.rb
|
|
72
|
+
- lib/people/client.rb
|
|
73
|
+
- lib/people/exception.rb
|
|
74
|
+
- lib/people/http_proxy.rb
|
|
75
|
+
- lib/people/initializer.rb
|
|
76
|
+
- lib/people/version.rb
|
|
77
|
+
- people-ruby.gemspec
|
|
78
|
+
homepage: https://github.com/konforti/people-ruby
|
|
79
|
+
licenses:
|
|
80
|
+
- MIT
|
|
81
|
+
metadata: {}
|
|
82
|
+
post_install_message:
|
|
83
|
+
rdoc_options: []
|
|
84
|
+
require_paths:
|
|
85
|
+
- lib
|
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
version: 2.2.2
|
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
requirements: []
|
|
97
|
+
rubyforge_project:
|
|
98
|
+
rubygems_version: 2.4.8
|
|
99
|
+
signing_key:
|
|
100
|
+
specification_version: 4
|
|
101
|
+
summary: Ruby bindings for People - Remote Identity Management People
|
|
102
|
+
test_files: []
|
|
103
|
+
has_rdoc:
|