brivo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/brivo.gemspec +29 -0
- data/lib/brivo.rb +10 -0
- data/lib/brivo/api/api.rb +6 -0
- data/lib/brivo/api/credentials.rb +64 -0
- data/lib/brivo/api/groups.rb +56 -0
- data/lib/brivo/api/http.rb +117 -0
- data/lib/brivo/api/users.rb +74 -0
- data/lib/brivo/application.rb +19 -0
- data/lib/brivo/collection.rb +37 -0
- data/lib/brivo/credential.rb +39 -0
- data/lib/brivo/error.rb +15 -0
- data/lib/brivo/group.rb +41 -0
- data/lib/brivo/user.rb +48 -0
- data/lib/brivo/version.rb +5 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: '0861fdd02d422aecc203d4185ac1c2de64973b57'
|
4
|
+
data.tar.gz: fe632e314d7a501ee286240243931a3c5cf1ddc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b66f6d82df8429c0954379336be143f9a3a130a993c966a7b6a86da7800762e21b4606d12e1c4054038277b7d79fa1d3f690c22f90cdb7947cb964cdb46812b8
|
7
|
+
data.tar.gz: 6d5a835ec4c161666717cff3e398c16cd899151fdb21c0962317d4c163d4e423d0de82e92b46d01cff379737bdc9ad55ed7aec6f94517de9d730779ea3277d1c
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Techspace Property Group Ltd.
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Brivo
|
2
|
+
|
3
|
+
API wrapper for the [Brivo API](http://apidocs.brivo.com/)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'brivo'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ gem install brivo
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
client = Brivo::Application.new(
|
29
|
+
client_id: YOUR_CLIENT_ID,
|
30
|
+
secret: YOUR_SECRET,
|
31
|
+
api_key: YOUR_API_KEY,
|
32
|
+
username: YOUR_USERNAME,
|
33
|
+
password: YOUR_PASSWORD
|
34
|
+
)
|
35
|
+
|
36
|
+
# Create a user
|
37
|
+
client.user.create(
|
38
|
+
first_name: 'First name',
|
39
|
+
last_name: 'last name',
|
40
|
+
external_id: 1
|
41
|
+
)
|
42
|
+
|
43
|
+
# Get all users
|
44
|
+
client.users
|
45
|
+
|
46
|
+
# Find a user
|
47
|
+
client.user(id)
|
48
|
+
|
49
|
+
# Create a group
|
50
|
+
client.group.create(
|
51
|
+
name: 'Group name'
|
52
|
+
)
|
53
|
+
|
54
|
+
# Get all groups
|
55
|
+
client.groups
|
56
|
+
|
57
|
+
# Find a group
|
58
|
+
group = client.group(id)
|
59
|
+
|
60
|
+
# Assign a user to a group
|
61
|
+
group.assign_user(user_id)
|
62
|
+
```
|
63
|
+
|
64
|
+
## Development
|
65
|
+
|
66
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
67
|
+
|
68
|
+
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).
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/techspaceco/brivo
|
73
|
+
|
74
|
+
|
75
|
+
## License
|
76
|
+
|
77
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "brivo"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/brivo.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'brivo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "brivo"
|
8
|
+
spec.version = Brivo::VERSION
|
9
|
+
spec.authors = ["Adam Rainsby"]
|
10
|
+
spec.email = ["adamrainsby@live.co.uk"]
|
11
|
+
|
12
|
+
spec.summary = %q{Brivo API wrapper.}
|
13
|
+
spec.homepage = "https://github.com/techspaceco/brivo"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
26
|
+
spec.add_development_dependency "vcr"
|
27
|
+
spec.add_development_dependency "webmock"
|
28
|
+
spec.add_development_dependency "qq"
|
29
|
+
end
|
data/lib/brivo.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Brivo
|
4
|
+
module API
|
5
|
+
module Credentials
|
6
|
+
include Brivo::API::HTTP
|
7
|
+
|
8
|
+
FORMAT_NAME = 'Standard 26 Bit'
|
9
|
+
|
10
|
+
def credentials(status: nil)
|
11
|
+
path = 'credentials'
|
12
|
+
path += "?filter=status__eq:#{status}" if status
|
13
|
+
Brivo::Collection.new(self, path, credential_class)
|
14
|
+
end
|
15
|
+
|
16
|
+
def user_credentials(user_id)
|
17
|
+
Brivo::Collection.new(self, "users/#{user_id}/credentials", credential_class)
|
18
|
+
end
|
19
|
+
|
20
|
+
def credential id = nil
|
21
|
+
if id
|
22
|
+
credential_json = http_request("credentials/#{id}")
|
23
|
+
credential_class.new(credential_json)
|
24
|
+
else
|
25
|
+
credential_class
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_credential id, facility_code
|
30
|
+
@credential_formats ||= http_request('credentials/formats')['data']
|
31
|
+
credential_format = @credential_formats.find do |format|
|
32
|
+
format['name'] == FORMAT_NAME
|
33
|
+
end
|
34
|
+
|
35
|
+
credential_json = http_request(
|
36
|
+
'credentials',
|
37
|
+
params: {
|
38
|
+
credentialFormat: {
|
39
|
+
id: credential_format['id']
|
40
|
+
},
|
41
|
+
referenceId: id,
|
42
|
+
fieldValues: [
|
43
|
+
{id: 1, value: id},
|
44
|
+
{id: 2, value: facility_code}
|
45
|
+
]
|
46
|
+
},
|
47
|
+
method: :post
|
48
|
+
)
|
49
|
+
|
50
|
+
credential_class.new(credential_json)
|
51
|
+
end
|
52
|
+
|
53
|
+
def delete_credential id
|
54
|
+
http_request "credentials/#{id}", method: :delete
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def credential_class
|
60
|
+
Brivo::Credential.tap { |klass| klass.application = self }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Brivo
|
4
|
+
module API
|
5
|
+
module Groups
|
6
|
+
include Brivo::API::HTTP
|
7
|
+
|
8
|
+
def groups
|
9
|
+
Brivo::Collection.new(self, 'groups', group_class)
|
10
|
+
end
|
11
|
+
|
12
|
+
def user_groups(user_id)
|
13
|
+
Brivo::Collection.new(self, "users/#{user_id}/groups", group_class)
|
14
|
+
end
|
15
|
+
|
16
|
+
def group id = nil
|
17
|
+
if id
|
18
|
+
group_json = http_request("groups/#{id}")
|
19
|
+
group_class.new(group_json)
|
20
|
+
else
|
21
|
+
group_class
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def group_assign_user group_id, user_id
|
26
|
+
http_request "groups/#{group_id}/users/#{user_id}", method: :put
|
27
|
+
end
|
28
|
+
|
29
|
+
def group_remove_user group_id, user_id
|
30
|
+
http_request "groups/#{group_id}/users/#{user_id}", method: :delete
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_group name
|
34
|
+
group_json = http_request(
|
35
|
+
'groups',
|
36
|
+
params: {
|
37
|
+
name: name
|
38
|
+
},
|
39
|
+
method: :post
|
40
|
+
)
|
41
|
+
|
42
|
+
group_class.new(group_json)
|
43
|
+
end
|
44
|
+
|
45
|
+
def delete_group id
|
46
|
+
http_request "groups/#{id}", method: :delete
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def group_class
|
52
|
+
Brivo::Group.tap { |klass| klass.application = self }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Brivo
|
4
|
+
module API
|
5
|
+
module HTTP
|
6
|
+
MAX_RETRIES = 3
|
7
|
+
API_URL = -'https://api.brivo.com/v1/api'
|
8
|
+
PAGE_SIZE = 100
|
9
|
+
DEFAULT_HTTPS_SETTINGS = {
|
10
|
+
use_ssl: true,
|
11
|
+
open_timeout: 3,
|
12
|
+
read_timeout: 3,
|
13
|
+
ssl_timeout: 3
|
14
|
+
}
|
15
|
+
|
16
|
+
def set_access_token
|
17
|
+
uri = URI.parse("https://auth.brivo.com/oauth/token?grant_type=password&username=#{username}&password=#{password}")
|
18
|
+
|
19
|
+
authorization_code = Base64.strict_encode64("#{client_id}:#{secret}")
|
20
|
+
|
21
|
+
res = Net::HTTP.start(uri.host, uri.port, DEFAULT_HTTPS_SETTINGS) do |https|
|
22
|
+
req = Net::HTTP::Post.new(uri)
|
23
|
+
req['Content-Type'] = 'application/json'
|
24
|
+
req['Authorization'] = "Basic #{authorization_code}"
|
25
|
+
req['api-key'] = api_key
|
26
|
+
|
27
|
+
https.request(req)
|
28
|
+
end
|
29
|
+
|
30
|
+
response = JSON.parse res.body
|
31
|
+
|
32
|
+
@access_token = response['access_token']
|
33
|
+
@access_token_expiry = monotonic_time + (response['expires_in'] - 2)
|
34
|
+
end
|
35
|
+
|
36
|
+
def http_request path, method: :get, params: {}, offset: nil
|
37
|
+
attempts = 0
|
38
|
+
begin
|
39
|
+
attempts += 1
|
40
|
+
uri = "#{API_URL}/#{path}"
|
41
|
+
|
42
|
+
parsed_uri = URI.parse(uri)
|
43
|
+
|
44
|
+
if offset
|
45
|
+
if parsed_uri.query.nil?
|
46
|
+
parsed_uri.query = "pageSize=#{PAGE_SIZE}&offset=#{offset}"
|
47
|
+
else
|
48
|
+
parsed_uri.query = "#{parsed_uri.query}&pageSize=#{PAGE_SIZE}&offset=#{offset}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
http_methods = {
|
53
|
+
get: Net::HTTP::Get,
|
54
|
+
post: Net::HTTP::Post,
|
55
|
+
put: Net::HTTP::Put,
|
56
|
+
delete: Net::HTTP::Delete
|
57
|
+
}
|
58
|
+
|
59
|
+
response = Net::HTTP.start(parsed_uri.host, parsed_uri.port, DEFAULT_HTTPS_SETTINGS) do |https|
|
60
|
+
request = http_methods[method].new(parsed_uri)
|
61
|
+
request.body = params.to_json
|
62
|
+
|
63
|
+
if @access_token.nil? || monotonic_time > @access_token_expiry
|
64
|
+
set_access_token
|
65
|
+
end
|
66
|
+
|
67
|
+
request['Content-Type'] = 'application/json'
|
68
|
+
request['Authorization'] = "bearer #{@access_token}"
|
69
|
+
request['api-key'] = api_key
|
70
|
+
|
71
|
+
https.request(request)
|
72
|
+
end
|
73
|
+
|
74
|
+
# http://apidocs.brivo.com/#response-codes
|
75
|
+
case response.code.to_i
|
76
|
+
when 200
|
77
|
+
JSON.parse(response.body)
|
78
|
+
when 201
|
79
|
+
JSON.parse(response.body)
|
80
|
+
when 204
|
81
|
+
true
|
82
|
+
when 400
|
83
|
+
raise Brivo::Error::BadRequest
|
84
|
+
when 401
|
85
|
+
raise Brivo::Error::Unauthorized
|
86
|
+
when 403
|
87
|
+
raise Brivo::Error::Forbidden
|
88
|
+
when 404
|
89
|
+
raise Brivo::Error::NotFound
|
90
|
+
when 415
|
91
|
+
raise Brivo::Error::UnsupportedMediaType
|
92
|
+
when 418
|
93
|
+
raise Brivo::Error::IsATeapot
|
94
|
+
when 503
|
95
|
+
raise Brivo::Error::ServiceUnavailable
|
96
|
+
when 596
|
97
|
+
raise Brivo::Error::ServiceNotFound
|
98
|
+
else
|
99
|
+
raise Brivo::Error::UnkownResponse
|
100
|
+
end
|
101
|
+
rescue StandardError
|
102
|
+
if attempts > MAX_RETRIES
|
103
|
+
raise
|
104
|
+
else
|
105
|
+
retry
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def monotonic_time
|
113
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Brivo
|
4
|
+
module API
|
5
|
+
module Users
|
6
|
+
include Brivo::API::HTTP
|
7
|
+
|
8
|
+
def users
|
9
|
+
Brivo::Collection.new(self, 'users', user_class)
|
10
|
+
end
|
11
|
+
|
12
|
+
def group_users group_id
|
13
|
+
Brivo::Collection.new(self, "groups/#{group_id}/users", user_class)
|
14
|
+
end
|
15
|
+
|
16
|
+
def credential_user credential_id
|
17
|
+
user_json = http_request("credentials/#{credential_id}/user")
|
18
|
+
user_class.new(user_json)
|
19
|
+
end
|
20
|
+
|
21
|
+
def user id = nil, external_id: nil
|
22
|
+
if id
|
23
|
+
user_json = http_request "users/#{id}"
|
24
|
+
user_class.new(user_json)
|
25
|
+
elsif external_id
|
26
|
+
user_json = http_request "users/#{external_id}/external"
|
27
|
+
user_class.new(user_json)
|
28
|
+
else
|
29
|
+
user_class
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_user first_name, last_name, external_id, suspended = false
|
34
|
+
user_json = http_request(
|
35
|
+
'users',
|
36
|
+
params: {
|
37
|
+
firstName: first_name,
|
38
|
+
lastName: last_name,
|
39
|
+
externalId: external_id,
|
40
|
+
suspended: suspended
|
41
|
+
},
|
42
|
+
method: :post
|
43
|
+
)
|
44
|
+
|
45
|
+
user_class.new(user_json)
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete_user id
|
49
|
+
http_request "users/#{id}", method: :delete
|
50
|
+
end
|
51
|
+
|
52
|
+
def user_assign_credential user_id, credential_id, effective_from, effective_to
|
53
|
+
http_request(
|
54
|
+
"users/#{user_id}/credentials/#{credential_id}",
|
55
|
+
method: :put,
|
56
|
+
params: {
|
57
|
+
effectiveFrom: effective_from,
|
58
|
+
effectiveTo: effective_to
|
59
|
+
}
|
60
|
+
)
|
61
|
+
end
|
62
|
+
|
63
|
+
def user_remove_credential user_id, credential_id
|
64
|
+
http_request "users/#{user_id}/credentials/#{credential_id}", method: :delete
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def user_class
|
70
|
+
Brivo::User.tap { |klass| klass.application = self }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Brivo
|
4
|
+
class Application
|
5
|
+
include Brivo::API::Users
|
6
|
+
include Brivo::API::Groups
|
7
|
+
include Brivo::API::Credentials
|
8
|
+
|
9
|
+
attr_reader :client_id, :secret, :api_key, :username, :password
|
10
|
+
|
11
|
+
def initialize client_id:, secret:, api_key:, username:, password:
|
12
|
+
@client_id = client_id
|
13
|
+
@secret = secret
|
14
|
+
@api_key = api_key
|
15
|
+
@username = username
|
16
|
+
@password = password
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Brivo
|
4
|
+
class Collection
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize application, api_path, model
|
8
|
+
@application = application
|
9
|
+
@api_path = api_path
|
10
|
+
@model = model
|
11
|
+
@collection = []
|
12
|
+
|
13
|
+
fetch_collection
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def each(&block)
|
18
|
+
total_count = @total_count
|
19
|
+
while @collection.count < total_count do
|
20
|
+
collection_count = @collection.count
|
21
|
+
fetch_collection(offset: collection_count)
|
22
|
+
end
|
23
|
+
|
24
|
+
@collection.each(&block)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def fetch_collection offset: 0
|
30
|
+
response = @application.http_request(@api_path, offset: offset)
|
31
|
+
@total_count = response['count']
|
32
|
+
response['data'].each do |json|
|
33
|
+
@collection << @model.new(json)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Brivo
|
4
|
+
class Credential
|
5
|
+
attr_reader :id, :reference_id, :field_values
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :application
|
9
|
+
|
10
|
+
def create id:, facility_code:
|
11
|
+
application.create_credential(id, facility_code)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize attributes = {}
|
16
|
+
@id = attributes['id']
|
17
|
+
@reference_id = attributes['referenceId']
|
18
|
+
@field_values = attributes['fieldValues']&.map do |field_value|
|
19
|
+
field_value.inject({}) do |m, (k, v)|
|
20
|
+
m.tap { m[k.to_sym] = v }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete
|
26
|
+
application.delete_credential(id)
|
27
|
+
end
|
28
|
+
|
29
|
+
def user
|
30
|
+
application.credential_user(id)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def application
|
36
|
+
self.class.application
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/brivo/error.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Brivo
|
4
|
+
class Error < StandardError
|
5
|
+
class BadRequest < Error; end
|
6
|
+
class Unauthorized < Error; end
|
7
|
+
class Forbidden < Error; end
|
8
|
+
class NotFound < Error; end
|
9
|
+
class UnsupportedMediaType < Error; end
|
10
|
+
class ServiceUnavailable < Error; end
|
11
|
+
class ServiceNotFound < Error; end
|
12
|
+
class UnkownResponse < Error; end
|
13
|
+
class IsATeapot < Error; end
|
14
|
+
end
|
15
|
+
end
|
data/lib/brivo/group.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Brivo
|
4
|
+
class Group
|
5
|
+
attr_reader :id, :name
|
6
|
+
class << self
|
7
|
+
attr_accessor :application
|
8
|
+
|
9
|
+
def create name:
|
10
|
+
application.create_group(name)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize attributes = {}
|
15
|
+
@id = attributes['id']
|
16
|
+
@name = attributes['name']
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete
|
20
|
+
application.delete_group(id)
|
21
|
+
end
|
22
|
+
|
23
|
+
def users
|
24
|
+
application.group_users(id)
|
25
|
+
end
|
26
|
+
|
27
|
+
def assign_user user_id
|
28
|
+
application.group_assign_user(id, user_id)
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove_user user_id
|
32
|
+
application.group_remove_user(id, user_id)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def application
|
38
|
+
self.class.application
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/brivo/user.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Brivo
|
4
|
+
class User
|
5
|
+
attr_reader :id, :first_name, :last_name, :external_id, :suspended
|
6
|
+
class << self
|
7
|
+
attr_accessor :application
|
8
|
+
|
9
|
+
def create first_name:, last_name:, external_id: nil, suspended: false
|
10
|
+
application.create_user(first_name, last_name, external_id, suspended)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize attributes = {}
|
15
|
+
@id = attributes['id']
|
16
|
+
@first_name = attributes['firstName']
|
17
|
+
@last_name = attributes['lastName']
|
18
|
+
@external_id = attributes['externalId']
|
19
|
+
@suspended = attributes['suspended']
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete
|
23
|
+
application.delete_user(id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def groups
|
27
|
+
application.user_groups(id)
|
28
|
+
end
|
29
|
+
|
30
|
+
def credentials
|
31
|
+
application.user_credentials(id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def assign_credential credential_id, effective_from, effective_to
|
35
|
+
application.user_assign_credential(id, credential_id, effective_from, effective_to)
|
36
|
+
end
|
37
|
+
|
38
|
+
def remove_credential credential_id
|
39
|
+
application.user_remove_credential(id, credential_id)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def application
|
45
|
+
self.class.application
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: brivo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Rainsby
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: qq
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- adamrainsby@live.co.uk
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- brivo.gemspec
|
113
|
+
- lib/brivo.rb
|
114
|
+
- lib/brivo/api/api.rb
|
115
|
+
- lib/brivo/api/credentials.rb
|
116
|
+
- lib/brivo/api/groups.rb
|
117
|
+
- lib/brivo/api/http.rb
|
118
|
+
- lib/brivo/api/users.rb
|
119
|
+
- lib/brivo/application.rb
|
120
|
+
- lib/brivo/collection.rb
|
121
|
+
- lib/brivo/credential.rb
|
122
|
+
- lib/brivo/error.rb
|
123
|
+
- lib/brivo/group.rb
|
124
|
+
- lib/brivo/user.rb
|
125
|
+
- lib/brivo/version.rb
|
126
|
+
homepage: https://github.com/techspaceco/brivo
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.6.8
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Brivo API wrapper.
|
150
|
+
test_files: []
|