zaikio-directory 0.0.8 → 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 +4 -4
- data/CHANGELOG.md +22 -0
- data/README.md +6 -2
- data/lib/zaikio/directory.rb +12 -7
- data/lib/zaikio/directory/asset.rb +55 -0
- data/lib/zaikio/directory/authorization_middleware.rb +11 -4
- data/lib/zaikio/directory/basic_auth_middleware.rb +12 -4
- data/lib/zaikio/directory/configuration.rb +5 -5
- data/lib/zaikio/directory/connection.rb +11 -1
- data/lib/zaikio/directory/current_organization.rb +6 -0
- data/lib/zaikio/directory/machine.rb +2 -21
- data/lib/zaikio/directory/organization.rb +2 -0
- data/lib/zaikio/directory/software.rb +5 -18
- data/lib/zaikio/directory/specialist.rb +10 -0
- data/lib/zaikio/directory/subscription.rb +27 -0
- data/lib/zaikio/directory/version.rb +1 -1
- metadata +31 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90ecc69c9bfccc037868c41f76b665d456a9588bf9c573a3a53833d81b844419
|
4
|
+
data.tar.gz: 0c12da5059d2aadd77c4ec3f4f371c41582d77f0c866911df83216c42ee62b9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d084614b98a1ca2867b7806eb5f6edeeaab2ff29e4c4724de48b3edeadbffb926dccd7a4338f541e8358dd8dc90929b0b9576eda82b82f0195521ac8ce1fe0c
|
7
|
+
data.tar.gz: ce5486bccd57d2444533c6cb08380ad103af33ffafe9f41bec02daf1914afeca6f07c07eeb3bd528dc3bd9a7bd655dedf5b30d4fb70cbfcff2acb62992179d2f
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
## [0.1.1] - 2020-09-02
|
11
|
+
|
12
|
+
### Fixed
|
13
|
+
- Thread-Safety on current access token
|
14
|
+
|
15
|
+
## [0.1.0] - 2020-08-24
|
16
|
+
|
17
|
+
### Added
|
18
|
+
- Added subscriptions (migration required)
|
19
|
+
|
20
|
+
[Unreleased]: https://github.com/crispymtn/zaikio-directory-ruby/compare/v0.1.1...HEAD
|
21
|
+
[0.1.1]: https://github.com/crispymtn/zaikio-directory-ruby/compare/5c6cb4dbcac316733560ddb2b1e13b53e55eb66e...v0.1.1
|
22
|
+
[0.1.0]: https://github.com/crispymtn/zaikio-directory-ruby/compare/d149fb4c0abe6005f123def3952d2dd2ef6404bb...29889d8a6a496542a81e05688da2a46cf4c44188
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ $ gem install zaikio-directory
|
|
26
26
|
# config/initializers/zaikio_directory.rb
|
27
27
|
|
28
28
|
Zaikio::Directory.configure do |config|
|
29
|
-
config.
|
29
|
+
config.environment = :production # sandbox or production
|
30
30
|
end
|
31
31
|
```
|
32
32
|
|
@@ -35,7 +35,7 @@ end
|
|
35
35
|
|
36
36
|
The Directory Client has an ORM like design. However, we distinguish between the contexts of the organization and the person.
|
37
37
|
|
38
|
-
For the requests to work, a valid JSON Web token with the correct OAuth Scopes must always be provided. Please refer to [zakio-oauth_client](
|
38
|
+
For the requests to work, a valid JSON Web token with the correct OAuth Scopes must always be provided. Please refer to [zakio-oauth_client](https://github.com/crispymtn/zaikio-oauth_client).
|
39
39
|
|
40
40
|
If you want to know which actions are available and which scopes are required, please refer to the [Directory API Reference](https://docs.zaikio.com/api/directory/directory.html).
|
41
41
|
|
@@ -97,6 +97,10 @@ end
|
|
97
97
|
```rb
|
98
98
|
Zaikio::Directory.with_basic_auth(client_id, client_secret) do
|
99
99
|
connections = Zaikio::Directory::Connection.all
|
100
|
+
subscription = Zaikio::Directory::Subscription.find("Organization-b1475f65-236c-58b8-96e1-e1778b43beb7")
|
101
|
+
subscription.plan # => "advanced"
|
102
|
+
subscription.activate!
|
103
|
+
subscription.increment_usage_by!(:orders_created, 12)
|
100
104
|
end
|
101
105
|
|
102
106
|
roles = Zaikio::Directory::Role.all
|
data/lib/zaikio/directory.rb
CHANGED
@@ -8,12 +8,14 @@ require "zaikio/directory/basic_auth_middleware"
|
|
8
8
|
# Models
|
9
9
|
require "zaikio/error"
|
10
10
|
require "zaikio/directory/base"
|
11
|
+
require "zaikio/directory/asset"
|
11
12
|
require "zaikio/directory/organization_membership"
|
12
13
|
require "zaikio/directory/business_relationship"
|
13
14
|
require "zaikio/directory/organization"
|
14
15
|
require "zaikio/directory/person"
|
15
16
|
require "zaikio/directory/machine"
|
16
17
|
require "zaikio/directory/software"
|
18
|
+
require "zaikio/directory/specialist"
|
17
19
|
require "zaikio/directory/site"
|
18
20
|
require "zaikio/directory/membership"
|
19
21
|
require "zaikio/directory/current_person"
|
@@ -21,29 +23,31 @@ require "zaikio/directory/current_organization"
|
|
21
23
|
require "zaikio/directory/role"
|
22
24
|
require "zaikio/directory/revoked_access_token"
|
23
25
|
require "zaikio/directory/connection"
|
26
|
+
require "zaikio/directory/subscription"
|
24
27
|
|
25
28
|
module Zaikio
|
26
29
|
module Directory
|
27
30
|
class << self
|
28
31
|
attr_accessor :configuration
|
32
|
+
class_attribute :connection
|
29
33
|
|
30
34
|
def configure
|
31
|
-
|
35
|
+
self.connection = nil
|
32
36
|
self.configuration ||= Configuration.new
|
33
37
|
yield(configuration)
|
34
38
|
|
35
|
-
Base.connection =
|
39
|
+
Base.connection = create_connection
|
36
40
|
end
|
37
41
|
|
38
42
|
def with_token(token)
|
39
|
-
AuthorizationMiddleware.token token
|
43
|
+
AuthorizationMiddleware.token = token
|
40
44
|
yield
|
41
45
|
ensure
|
42
46
|
AuthorizationMiddleware.reset_token
|
43
47
|
end
|
44
48
|
|
45
49
|
def with_basic_auth(login, password)
|
46
|
-
BasicAuthMiddleware.credentials [login, password]
|
50
|
+
BasicAuthMiddleware.credentials = [login, password]
|
47
51
|
yield
|
48
52
|
ensure
|
49
53
|
BasicAuthMiddleware.reset_credentials
|
@@ -57,8 +61,9 @@ module Zaikio
|
|
57
61
|
create_token_data(payload)
|
58
62
|
end
|
59
63
|
|
60
|
-
def
|
61
|
-
|
64
|
+
def create_connection
|
65
|
+
self.connection = Faraday.new(url: "#{configuration.host}/api/v1",
|
66
|
+
ssl: { verify: configuration.environment != :test }) do |c|
|
62
67
|
c.request :json
|
63
68
|
c.response :logger, configuration&.logger
|
64
69
|
c.use JSONParser
|
@@ -70,7 +75,7 @@ module Zaikio
|
|
70
75
|
|
71
76
|
private
|
72
77
|
|
73
|
-
def create_token_data(payload)
|
78
|
+
def create_token_data(payload)
|
74
79
|
subjects = payload["sub"].split(">")
|
75
80
|
|
76
81
|
OpenStruct.new(
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Zaikio
|
2
|
+
module Directory
|
3
|
+
module Asset
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
# Callbacks
|
8
|
+
after_create :make_organization_owner
|
9
|
+
end
|
10
|
+
|
11
|
+
def make_organization_owner
|
12
|
+
if Zaikio::Directory.current_token_data.subject_type == "Organization"
|
13
|
+
self.class.request(:post,
|
14
|
+
"#{collection_name}/#{id}/#{singular_name}_ownership")
|
15
|
+
else
|
16
|
+
org_path = "person/organizations/#{organization_id}"
|
17
|
+
self.class.request(:post,
|
18
|
+
"#{org_path}/#{collection_name}/#{id}/#{singular_name}_ownership")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def destroy
|
23
|
+
if Zaikio::Directory.current_token_data.subject_type == "Organization"
|
24
|
+
self.class.request(:delete,
|
25
|
+
"#{collection_name}/#{id}/#{singular_name}_ownership")
|
26
|
+
else
|
27
|
+
org_path = "person/organizations/#{owner_id || organization_id}"
|
28
|
+
self.class.request(:delete,
|
29
|
+
"#{org_path}/#{collection_name}/#{id}/#{singular_name}_ownership")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def specification
|
34
|
+
prefix = if Zaikio::Directory.current_token_data.subject_type == "Person"
|
35
|
+
"person/organizations/#{owner_id || organization_id}/"
|
36
|
+
else
|
37
|
+
""
|
38
|
+
end
|
39
|
+
self.class.request(:get,
|
40
|
+
"#{prefix}#{collection_name}/#{id}/#{singular_name}_specification")
|
41
|
+
&.body&.dig("data")
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def collection_name
|
47
|
+
self.class.name.demodulize.underscore.pluralize
|
48
|
+
end
|
49
|
+
|
50
|
+
def singular_name
|
51
|
+
self.class.name.demodulize.underscore
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,15 +1,22 @@
|
|
1
1
|
require "faraday"
|
2
2
|
require "jwt"
|
3
|
+
require "concurrent"
|
3
4
|
|
4
5
|
module Zaikio
|
5
6
|
module Directory
|
6
7
|
class AuthorizationMiddleware < Faraday::Middleware
|
7
|
-
def self.
|
8
|
-
@token
|
8
|
+
def self.token
|
9
|
+
@token ||= Concurrent::ThreadLocalVar.new { nil }
|
10
|
+
@token.value
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.token=(value)
|
14
|
+
@token ||= Concurrent::ThreadLocalVar.new { nil }
|
15
|
+
@token.value = value
|
9
16
|
end
|
10
17
|
|
11
|
-
def self.
|
12
|
-
|
18
|
+
def self.reset_token
|
19
|
+
self.token = nil
|
13
20
|
end
|
14
21
|
|
15
22
|
def call(request_env)
|
@@ -4,12 +4,20 @@ require "base64"
|
|
4
4
|
module Zaikio
|
5
5
|
module Directory
|
6
6
|
class BasicAuthMiddleware < Faraday::Middleware
|
7
|
-
|
8
|
-
|
7
|
+
class_attribute :credentials
|
8
|
+
|
9
|
+
def self.credentials
|
10
|
+
@credentials ||= Concurrent::ThreadLocalVar.new { nil }
|
11
|
+
@credentials.value
|
9
12
|
end
|
10
13
|
|
11
|
-
def self.credentials(
|
12
|
-
@credentials
|
14
|
+
def self.credentials=(value)
|
15
|
+
@credentials ||= Concurrent::ThreadLocalVar.new { nil }
|
16
|
+
@credentials.value = value
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.reset_credentials
|
20
|
+
self.credentials = nil
|
13
21
|
end
|
14
22
|
|
15
23
|
def call(request_env)
|
@@ -4,11 +4,11 @@ module Zaikio
|
|
4
4
|
module Directory
|
5
5
|
class Configuration
|
6
6
|
HOSTS = {
|
7
|
-
development: "
|
8
|
-
test: "
|
9
|
-
staging: "https://
|
10
|
-
sandbox: "https://
|
11
|
-
production: "https://
|
7
|
+
development: "https://hub.zaikio.test",
|
8
|
+
test: "https://hub.zaikio.test",
|
9
|
+
staging: "https://hub.staging.zaikio.com",
|
10
|
+
sandbox: "https://hub.sandbox.zaikio.com",
|
11
|
+
production: "https://hub.zaikio.com"
|
12
12
|
}.freeze
|
13
13
|
|
14
14
|
attr_accessor :host
|
@@ -1,9 +1,19 @@
|
|
1
1
|
module Zaikio
|
2
2
|
module Directory
|
3
3
|
class Connection < Base
|
4
|
-
uri "connections"
|
4
|
+
uri "connections(/:id)"
|
5
5
|
|
6
6
|
include_root_in_json :connection
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
if attributes["connectable_id"]
|
10
|
+
super(attributes.merge(
|
11
|
+
"id" => "#{attributes['connectable_type']}-#{attributes['connectable_id']}"
|
12
|
+
))
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
7
17
|
end
|
8
18
|
end
|
9
19
|
end
|
@@ -22,6 +22,8 @@ module Zaikio
|
|
22
22
|
uri: "software(/:id)"
|
23
23
|
has_many :machines, class_name: "Zaikio::Directory::Machine",
|
24
24
|
uri: "machines(/:id)"
|
25
|
+
has_many :specialists, class_name: "Zaikio::Directory::Specialist",
|
26
|
+
uri: "specialists(/:id)"
|
25
27
|
has_many :sites, class_name: "Zaikio::Directory::Site",
|
26
28
|
uri: "sites(/:id)"
|
27
29
|
|
@@ -29,6 +31,10 @@ module Zaikio
|
|
29
31
|
self.attributes = get
|
30
32
|
end
|
31
33
|
|
34
|
+
def reload
|
35
|
+
self.attributes = self.class.find.attributes
|
36
|
+
end
|
37
|
+
|
32
38
|
def members
|
33
39
|
memberships.with_fallback.map(&:person)
|
34
40
|
end
|
@@ -1,29 +1,10 @@
|
|
1
1
|
module Zaikio
|
2
2
|
module Directory
|
3
3
|
class Machine < Base
|
4
|
+
include Asset
|
5
|
+
|
4
6
|
uri "machines(/:id)"
|
5
7
|
include_root_in_json :machine
|
6
|
-
|
7
|
-
# Callbacks
|
8
|
-
after_create :make_organization_owner
|
9
|
-
|
10
|
-
def make_organization_owner
|
11
|
-
if Zaikio::Directory.current_token_data.subject_type == "Organization"
|
12
|
-
self.class.request(:post, "machines/#{id}/machine_ownership")
|
13
|
-
else
|
14
|
-
org_path = "person/organizations/#{organization_id}"
|
15
|
-
self.class.request(:post, "#{org_path}/machines/#{id}/machine_ownership")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def destroy
|
20
|
-
if Zaikio::Directory.current_token_data.subject_type == "Organization"
|
21
|
-
self.class.request(:delete, "machines/#{id}/machine_ownership")
|
22
|
-
else
|
23
|
-
org_path = "person/organizations/#{owner_id || organization_id}"
|
24
|
-
self.class.request(:delete, "#{org_path}/machines/#{id}/machine_ownership")
|
25
|
-
end
|
26
|
-
end
|
27
8
|
end
|
28
9
|
end
|
29
10
|
end
|
@@ -12,6 +12,8 @@ module Zaikio
|
|
12
12
|
uri: "person/organizations/:organization_id/software"
|
13
13
|
has_many :machines, class_name: "Zaikio::Directory::Machine",
|
14
14
|
uri: "person/organizations/:organization_id/machines"
|
15
|
+
has_many :specialists, class_name: "Zaikio::Directory::Specialist",
|
16
|
+
uri: "person/organizations/:organization_id/specialists"
|
15
17
|
has_many :sites, class_name: "Zaikio::Directory::Site",
|
16
18
|
uri: "person/organizations/:organization_id/sites"
|
17
19
|
end
|
@@ -1,28 +1,15 @@
|
|
1
1
|
module Zaikio
|
2
2
|
module Directory
|
3
3
|
class Software < Base
|
4
|
+
include Asset
|
5
|
+
|
4
6
|
uri "software(/:id)"
|
5
7
|
include_root_in_json :software
|
6
8
|
|
7
|
-
|
8
|
-
after_create :make_organization_owner
|
9
|
-
|
10
|
-
def make_organization_owner
|
11
|
-
if Zaikio::Directory.current_token_data.subject_type == "Organization"
|
12
|
-
self.class.request(:post, "software/#{id}/software_ownership")
|
13
|
-
else
|
14
|
-
org_path = "person/organizations/#{organization_id}"
|
15
|
-
self.class.request(:post, "#{org_path}/software/#{id}/software_ownership")
|
16
|
-
end
|
17
|
-
end
|
9
|
+
private
|
18
10
|
|
19
|
-
def
|
20
|
-
|
21
|
-
self.class.request(:delete, "software/#{id}/software_ownership")
|
22
|
-
else
|
23
|
-
org_path = "person/organizations/#{owner_id || organization_id}"
|
24
|
-
self.class.request(:delete, "#{org_path}/software/#{id}/software_ownership")
|
25
|
-
end
|
11
|
+
def collection_name
|
12
|
+
"software"
|
26
13
|
end
|
27
14
|
end
|
28
15
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Zaikio
|
2
|
+
module Directory
|
3
|
+
class Subscription < Base
|
4
|
+
uri "subscriptions(/:id)"
|
5
|
+
|
6
|
+
include_root_in_json :subscription
|
7
|
+
|
8
|
+
def initialize(attributes = {})
|
9
|
+
if attributes["subscriber_id"]
|
10
|
+
super(attributes.merge(
|
11
|
+
"id" => "#{attributes['subscriber_type']}-#{attributes['subscriber_id']}"
|
12
|
+
))
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def activate!
|
19
|
+
update(status: "active")
|
20
|
+
end
|
21
|
+
|
22
|
+
def increment_usage_by!(usage, by = 1)
|
23
|
+
update(increment_usages_in_current_billing_period: { usage => by })
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zaikio-directory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- crispymtn
|
@@ -10,8 +10,22 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-
|
13
|
+
date: 2020-09-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: concurrent-ruby
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
15
29
|
- !ruby/object:Gem::Dependency
|
16
30
|
name: jwt
|
17
31
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,16 +44,22 @@ dependencies:
|
|
30
44
|
name: multi_json
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
32
46
|
requirements:
|
33
|
-
- - "
|
47
|
+
- - ">="
|
34
48
|
- !ruby/object:Gem::Version
|
35
49
|
version: 1.14.1
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.16.0
|
36
53
|
type: :runtime
|
37
54
|
prerelease: false
|
38
55
|
version_requirements: !ruby/object:Gem::Requirement
|
39
56
|
requirements:
|
40
|
-
- - "
|
57
|
+
- - ">="
|
41
58
|
- !ruby/object:Gem::Version
|
42
59
|
version: 1.14.1
|
60
|
+
- - "<"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.16.0
|
43
63
|
- !ruby/object:Gem::Dependency
|
44
64
|
name: oj
|
45
65
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,10 +97,12 @@ executables: []
|
|
77
97
|
extensions: []
|
78
98
|
extra_rdoc_files: []
|
79
99
|
files:
|
100
|
+
- CHANGELOG.md
|
80
101
|
- MIT-LICENSE
|
81
102
|
- README.md
|
82
103
|
- Rakefile
|
83
104
|
- lib/zaikio/directory.rb
|
105
|
+
- lib/zaikio/directory/asset.rb
|
84
106
|
- lib/zaikio/directory/authorization_middleware.rb
|
85
107
|
- lib/zaikio/directory/base.rb
|
86
108
|
- lib/zaikio/directory/basic_auth_middleware.rb
|
@@ -99,12 +121,15 @@ files:
|
|
99
121
|
- lib/zaikio/directory/role.rb
|
100
122
|
- lib/zaikio/directory/site.rb
|
101
123
|
- lib/zaikio/directory/software.rb
|
124
|
+
- lib/zaikio/directory/specialist.rb
|
125
|
+
- lib/zaikio/directory/subscription.rb
|
102
126
|
- lib/zaikio/directory/version.rb
|
103
127
|
- lib/zaikio/error.rb
|
104
128
|
homepage: https://www.zaikio.com/
|
105
129
|
licenses:
|
106
130
|
- MIT
|
107
|
-
metadata:
|
131
|
+
metadata:
|
132
|
+
changelog_uri: https://github.com/crispymtn/zaikio-directory-ruby/blob/master/CHANGELOG.md
|
108
133
|
post_install_message:
|
109
134
|
rdoc_options: []
|
110
135
|
require_paths:
|
@@ -120,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
145
|
- !ruby/object:Gem::Version
|
121
146
|
version: '0'
|
122
147
|
requirements: []
|
123
|
-
rubygems_version: 3.1.
|
148
|
+
rubygems_version: 3.1.4
|
124
149
|
signing_key:
|
125
150
|
specification_version: 4
|
126
151
|
summary: Ruby API Client for Zaikio's Directory
|