zaikio-directory 0.0.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -0
- data/README.md +15 -2
- data/lib/zaikio/directory.rb +12 -7
- 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 +6 -6
- data/lib/zaikio/directory/connection.rb +11 -1
- data/lib/zaikio/directory/subscription.rb +27 -0
- data/lib/zaikio/directory/test_account.rb +15 -0
- data/lib/zaikio/directory/version.rb +1 -1
- data/lib/zaikio/error.rb +2 -0
- metadata +39 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dc2956d9034111c7ad80906d9f705c98503817f6cc6cb938f787646ca31cd7f
|
4
|
+
data.tar.gz: f8418bfc9b9c98ae9d245f24c50d5ac5f62493a56f36d5a1bfd5b769a24d7e9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00a3f4b24da97e0a6b7ecf041fe466e4ea30554f4ccc0b05cb51a5b1f14051c9c4516fec892b675d54f747b524b0dd0cf8b3eea8bdeaefc22388cf731762a0a1
|
7
|
+
data.tar.gz: a28cb5c4cae83c646c815019a41b0f6f0e592a7398caeaf582cbe52c2b7ba492e817d98255649c119a00ad1d25f88343897ffe1d40f16ae4cb0064770c066884
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,29 @@
|
|
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.2.0] - 2020-01-21
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- `Zaikio::Directory::TestAccount`
|
15
|
+
|
16
|
+
## [0.1.1] - 2020-09-02
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
- Thread-Safety on current access token
|
20
|
+
|
21
|
+
## [0.1.0] - 2020-08-24
|
22
|
+
|
23
|
+
### Added
|
24
|
+
- Added subscriptions (migration required)
|
25
|
+
|
26
|
+
[Unreleased]: https://github.com/zaikio/zaikio-directory-ruby/compare/v0.2.0...HEAD
|
27
|
+
[0.2.0]: https://github.com/zaikio/zaikio-directory-ruby/compare/v0.1.1...v.0.2.0
|
28
|
+
[0.1.1]: https://github.com/zaikio/zaikio-directory-ruby/compare/5c6cb4dbcac316733560ddb2b1e13b53e55eb66e...v0.1.1
|
29
|
+
[0.1.0]: https://github.com/zaikio/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/zaikio/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,19 @@ 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)
|
104
|
+
end
|
105
|
+
|
106
|
+
Zaikio::Directory.with_basic_auth(client_id, client_secret) do
|
107
|
+
Zaikio::Directory::TestAccount.create(
|
108
|
+
name: "My Test Org",
|
109
|
+
country_code: "DE",
|
110
|
+
kinds: ["printer"],
|
111
|
+
connection_attributes: ["procurement_consumer"]
|
112
|
+
)
|
100
113
|
end
|
101
114
|
|
102
115
|
roles = Zaikio::Directory::Role.all
|
data/lib/zaikio/directory.rb
CHANGED
@@ -23,29 +23,33 @@ require "zaikio/directory/current_organization"
|
|
23
23
|
require "zaikio/directory/role"
|
24
24
|
require "zaikio/directory/revoked_access_token"
|
25
25
|
require "zaikio/directory/connection"
|
26
|
+
require "zaikio/directory/subscription"
|
27
|
+
require "zaikio/directory/test_account"
|
26
28
|
|
27
29
|
module Zaikio
|
28
30
|
module Directory
|
29
31
|
class << self
|
30
32
|
attr_accessor :configuration
|
31
33
|
|
34
|
+
class_attribute :connection
|
35
|
+
|
32
36
|
def configure
|
33
|
-
|
37
|
+
self.connection = nil
|
34
38
|
self.configuration ||= Configuration.new
|
35
39
|
yield(configuration)
|
36
40
|
|
37
|
-
Base.connection =
|
41
|
+
Base.connection = create_connection
|
38
42
|
end
|
39
43
|
|
40
44
|
def with_token(token)
|
41
|
-
AuthorizationMiddleware.token token
|
45
|
+
AuthorizationMiddleware.token = token
|
42
46
|
yield
|
43
47
|
ensure
|
44
48
|
AuthorizationMiddleware.reset_token
|
45
49
|
end
|
46
50
|
|
47
51
|
def with_basic_auth(login, password)
|
48
|
-
BasicAuthMiddleware.credentials [login, password]
|
52
|
+
BasicAuthMiddleware.credentials = [login, password]
|
49
53
|
yield
|
50
54
|
ensure
|
51
55
|
BasicAuthMiddleware.reset_credentials
|
@@ -59,8 +63,9 @@ module Zaikio
|
|
59
63
|
create_token_data(payload)
|
60
64
|
end
|
61
65
|
|
62
|
-
def
|
63
|
-
|
66
|
+
def create_connection
|
67
|
+
self.connection = Faraday.new(url: "#{configuration.host}/api/v1",
|
68
|
+
ssl: { verify: configuration.environment != :test }) do |c|
|
64
69
|
c.request :json
|
65
70
|
c.response :logger, configuration&.logger
|
66
71
|
c.use JSONParser
|
@@ -72,7 +77,7 @@ module Zaikio
|
|
72
77
|
|
73
78
|
private
|
74
79
|
|
75
|
-
def create_token_data(payload)
|
80
|
+
def create_token_data(payload)
|
76
81
|
subjects = payload["sub"].split(">")
|
77
82
|
|
78
83
|
OpenStruct.new(
|
@@ -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
|
@@ -20,7 +20,7 @@ module Zaikio
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def logger
|
23
|
-
@logger ||= Logger.new(
|
23
|
+
@logger ||= Logger.new($stdout)
|
24
24
|
end
|
25
25
|
|
26
26
|
def environment=(env)
|
@@ -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
|
@@ -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
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Zaikio
|
2
|
+
module Directory
|
3
|
+
class TestAccount < Base
|
4
|
+
uri "test_accounts(/:id)"
|
5
|
+
|
6
|
+
include_root_in_json :test_account
|
7
|
+
|
8
|
+
# Associations
|
9
|
+
has_many :memberships, class_name: "Zaikio::Directory::Membership",
|
10
|
+
uri: nil
|
11
|
+
has_many :sites, class_name: "Zaikio::Directory::Site",
|
12
|
+
uri: nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/zaikio/error.rb
CHANGED
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.0
|
4
|
+
version: 0.2.0
|
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:
|
13
|
+
date: 2021-01-21 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,30 +44,42 @@ 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
|
46
66
|
requirements:
|
47
|
-
- - "
|
67
|
+
- - ">="
|
48
68
|
- !ruby/object:Gem::Version
|
49
69
|
version: 3.10.5
|
70
|
+
- - "<"
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 3.12.0
|
50
73
|
type: :runtime
|
51
74
|
prerelease: false
|
52
75
|
version_requirements: !ruby/object:Gem::Requirement
|
53
76
|
requirements:
|
54
|
-
- - "
|
77
|
+
- - ">="
|
55
78
|
- !ruby/object:Gem::Version
|
56
79
|
version: 3.10.5
|
80
|
+
- - "<"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.12.0
|
57
83
|
- !ruby/object:Gem::Dependency
|
58
84
|
name: spyke
|
59
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,6 +103,7 @@ executables: []
|
|
77
103
|
extensions: []
|
78
104
|
extra_rdoc_files: []
|
79
105
|
files:
|
106
|
+
- CHANGELOG.md
|
80
107
|
- MIT-LICENSE
|
81
108
|
- README.md
|
82
109
|
- Rakefile
|
@@ -101,12 +128,15 @@ files:
|
|
101
128
|
- lib/zaikio/directory/site.rb
|
102
129
|
- lib/zaikio/directory/software.rb
|
103
130
|
- lib/zaikio/directory/specialist.rb
|
131
|
+
- lib/zaikio/directory/subscription.rb
|
132
|
+
- lib/zaikio/directory/test_account.rb
|
104
133
|
- lib/zaikio/directory/version.rb
|
105
134
|
- lib/zaikio/error.rb
|
106
135
|
homepage: https://www.zaikio.com/
|
107
136
|
licenses:
|
108
137
|
- MIT
|
109
|
-
metadata:
|
138
|
+
metadata:
|
139
|
+
changelog_uri: https://github.com/zaikio/zaikio-directory-ruby/blob/master/CHANGELOG.md
|
110
140
|
post_install_message:
|
111
141
|
rdoc_options: []
|
112
142
|
require_paths:
|
@@ -115,14 +145,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
145
|
requirements:
|
116
146
|
- - ">="
|
117
147
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
148
|
+
version: 2.6.5
|
119
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
150
|
requirements:
|
121
151
|
- - ">="
|
122
152
|
- !ruby/object:Gem::Version
|
123
153
|
version: '0'
|
124
154
|
requirements: []
|
125
|
-
rubygems_version: 3.1.
|
155
|
+
rubygems_version: 3.1.4
|
126
156
|
signing_key:
|
127
157
|
specification_version: 4
|
128
158
|
summary: Ruby API Client for Zaikio's Directory
|