zaikio-directory 0.0.11 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07fb7419f188af643dfaa5440d77827a4bedd91b820e18a6714b8d45f194d2f7
4
- data.tar.gz: 878c7ba7a273c9526c556727cc9673d02956298d5b820a1f724949557d73eab0
3
+ metadata.gz: a72248c2cce21c6086f28c1973032fb48be5a3090887209dd0eff98441506fe1
4
+ data.tar.gz: 6e7bd4cee9fe02cc0faae2f2acfd67eae92346951e9500df050865402996f001
5
5
  SHA512:
6
- metadata.gz: ad30c796f5615df1ef8c1f61d8a11f01460d085db6c2e2e054bb25e588b36fec61ac657c66b019b1b6f5412f8568211af50b3aa25797c7cc31a8a63db89ccded
7
- data.tar.gz: 65c882cdf8824f5bed2d7c1da73d7b8dcf03e89d74961b72010f04b365da04374289b319e5ef4a93a33f7d73641dde2fd869852dd215fa938443389c728e5e0a
6
+ metadata.gz: 73add47c0e748bf676d5dc0d1db7da71ae5e5393d191b68eb14025f936dee92cff0e9933db56201d33a03e4b51cd992a14c3ecb7aaf1ce531a6599c490ad34f6
7
+ data.tar.gz: c8e8b679d75533d493090edc93fce47db3ab884833499fd1a40cd238df650583db86c3cb5d3197e3b792cb04b210dfb42db52496bc357b430c114dd7f47d28c6
data/README.md CHANGED
@@ -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](#todo).
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
@@ -23,6 +23,7 @@ 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"
26
27
 
27
28
  module Zaikio
28
29
  module Directory
@@ -61,7 +62,8 @@ module Zaikio
61
62
  end
62
63
 
63
64
  def create_connection
64
- self.connection = Faraday.new(url: "#{configuration.host}/api/v1") do |c|
65
+ self.connection = Faraday.new(url: "#{configuration.host}/api/v1",
66
+ ssl: { verify: configuration.environment != :test }) do |c|
65
67
  c.request :json
66
68
  c.response :logger, configuration&.logger
67
69
  c.use JSONParser
@@ -73,7 +75,7 @@ module Zaikio
73
75
 
74
76
  private
75
77
 
76
- def create_token_data(payload) # rubocop:disable Metrics/AbcSize
78
+ def create_token_data(payload)
77
79
  subjects = payload["sub"].split(">")
78
80
 
79
81
  OpenStruct.new(
@@ -4,11 +4,11 @@ module Zaikio
4
4
  module Directory
5
5
  class Configuration
6
6
  HOSTS = {
7
- development: "http://directory.zaikio.test",
8
- test: "http://directory.zaikio.test",
9
- staging: "https://directory.staging.zaikio.com",
10
- sandbox: "https://directory.sandbox.zaikio.com",
11
- production: "https://directory.zaikio.com"
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module Directory
3
- VERSION = "0.0.11".freeze
3
+ VERSION = "0.1.0".freeze
4
4
  end
5
5
  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.0.11
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - crispymtn
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-06-15 00:00:00.000000000 Z
13
+ date: 2020-08-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jwt
@@ -30,16 +30,22 @@ dependencies:
30
30
  name: multi_json
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ">="
34
34
  - !ruby/object:Gem::Version
35
35
  version: 1.14.1
36
+ - - "<"
37
+ - !ruby/object:Gem::Version
38
+ version: 1.16.0
36
39
  type: :runtime
37
40
  prerelease: false
38
41
  version_requirements: !ruby/object:Gem::Requirement
39
42
  requirements:
40
- - - "~>"
43
+ - - ">="
41
44
  - !ruby/object:Gem::Version
42
45
  version: 1.14.1
46
+ - - "<"
47
+ - !ruby/object:Gem::Version
48
+ version: 1.16.0
43
49
  - !ruby/object:Gem::Dependency
44
50
  name: oj
45
51
  requirement: !ruby/object:Gem::Requirement
@@ -101,6 +107,7 @@ files:
101
107
  - lib/zaikio/directory/site.rb
102
108
  - lib/zaikio/directory/software.rb
103
109
  - lib/zaikio/directory/specialist.rb
110
+ - lib/zaikio/directory/subscription.rb
104
111
  - lib/zaikio/directory/version.rb
105
112
  - lib/zaikio/error.rb
106
113
  homepage: https://www.zaikio.com/