lago-ruby-client 1.32.0 → 1.33.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 +4 -4
- data/lib/lago/api/client.rb +6 -0
- data/lib/lago/api/connection.rb +12 -0
- data/lib/lago/api/resources/feature.rb +41 -0
- data/lib/lago/api/resources/plan.rb +55 -0
- data/lib/lago/api/resources/subscription.rb +40 -0
- data/lib/lago/api/resources/usage.rb +17 -0
- data/lib/lago/api/resources/wallet.rb +1 -1
- data/lib/lago/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae486c8aa536d42665ea1994923d83baa1a35b782a8d679d3b39fc2aeb36f983
|
4
|
+
data.tar.gz: e5d0735075100f36509294a93413e58fab3108626522aef0fcbc47b78a3d5057
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c3c2e3a7829ed0e421f503f01228853e5e45e5e957f0c39efca95bdbb243e7a065f1678b66fa850dfe0d3febdb0f4b4c6d5c14429905ed7843a2db8c2473df7
|
7
|
+
data.tar.gz: 604bc299b1ac0b145879db8f476126378de33e1189ddd778fd3900eabad78e1178e28fce1c18e251a67e2a20ce7e68fb05e9032524057ef29278e6252118faf6
|
data/lib/lago/api/client.rb
CHANGED
@@ -11,6 +11,7 @@ require 'lago/api/resources/coupon'
|
|
11
11
|
require 'lago/api/resources/credit_note'
|
12
12
|
require 'lago/api/resources/customer'
|
13
13
|
require 'lago/api/resources/event'
|
14
|
+
require 'lago/api/resources/feature'
|
14
15
|
require 'lago/api/resources/fee'
|
15
16
|
require 'lago/api/resources/gross_revenue'
|
16
17
|
require 'lago/api/resources/invoice'
|
@@ -25,6 +26,7 @@ require 'lago/api/resources/payment_request'
|
|
25
26
|
require 'lago/api/resources/plan'
|
26
27
|
require 'lago/api/resources/subscription'
|
27
28
|
require 'lago/api/resources/tax'
|
29
|
+
require 'lago/api/resources/usage'
|
28
30
|
require 'lago/api/resources/wallet'
|
29
31
|
require 'lago/api/resources/wallet_transaction'
|
30
32
|
require 'lago/api/resources/webhook'
|
@@ -100,6 +102,10 @@ module Lago
|
|
100
102
|
Resources::Event.new(self)
|
101
103
|
end
|
102
104
|
|
105
|
+
def features
|
106
|
+
Resources::Feature.new(self)
|
107
|
+
end
|
108
|
+
|
103
109
|
def fees
|
104
110
|
Resources::Fee.new(self)
|
105
111
|
end
|
data/lib/lago/api/connection.rb
CHANGED
@@ -33,6 +33,18 @@ module Lago
|
|
33
33
|
handle_response(response)
|
34
34
|
end
|
35
35
|
|
36
|
+
def patch(path = uri.path, identifier:, body:)
|
37
|
+
uri_path = identifier.nil? ? path : "#{path}/#{URI.encode_www_form_component(identifier)}"
|
38
|
+
response = http_client.send_request(
|
39
|
+
'PATCH',
|
40
|
+
uri_path,
|
41
|
+
prepare_payload(body),
|
42
|
+
headers
|
43
|
+
)
|
44
|
+
|
45
|
+
handle_response(response)
|
46
|
+
end
|
47
|
+
|
36
48
|
def get(path = uri.path, identifier:)
|
37
49
|
uri_path = identifier.nil? ? path : "#{path}/#{URI.encode_www_form_component(identifier)}"
|
38
50
|
response = http_client.send_request(
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lago
|
4
|
+
module Api
|
5
|
+
module Resources
|
6
|
+
class Feature < Base
|
7
|
+
def api_resource
|
8
|
+
'features'
|
9
|
+
end
|
10
|
+
|
11
|
+
def root_name
|
12
|
+
'feature'
|
13
|
+
end
|
14
|
+
|
15
|
+
def whitelist_params(params)
|
16
|
+
result_hash = {
|
17
|
+
code: params[:code],
|
18
|
+
name: params[:name],
|
19
|
+
description: params[:description],
|
20
|
+
privileges: whitelist_privileges_params(params[:privileges]),
|
21
|
+
}.compact
|
22
|
+
|
23
|
+
{ root_name => result_hash }
|
24
|
+
end
|
25
|
+
|
26
|
+
def whitelist_privileges_params(privileges)
|
27
|
+
privileges&.map do |privilege|
|
28
|
+
{
|
29
|
+
code: privilege[:code],
|
30
|
+
name: privilege[:name],
|
31
|
+
value_type: privilege[:value_type],
|
32
|
+
config: {
|
33
|
+
select_options: privilege[:config][:select_options],
|
34
|
+
},
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -14,6 +14,46 @@ module Lago
|
|
14
14
|
'plan'
|
15
15
|
end
|
16
16
|
|
17
|
+
def get_entitlements(plan_code)
|
18
|
+
response = connection.get(entitlements_uri(plan_code), identifier: nil)
|
19
|
+
JSON.parse(response.to_json, object_class: OpenStruct).entitlements
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_entitlements(plan_code, params)
|
23
|
+
response = connection.post(
|
24
|
+
whitelist_entitlements_params(params),
|
25
|
+
entitlements_uri(plan_code),
|
26
|
+
)
|
27
|
+
JSON.parse(response.to_json, object_class: OpenStruct).entitlements
|
28
|
+
end
|
29
|
+
|
30
|
+
def update_entitlements(plan_code, params)
|
31
|
+
response = connection.patch(
|
32
|
+
entitlements_uri(plan_code),
|
33
|
+
identifier: nil,
|
34
|
+
body: whitelist_entitlements_params(params),
|
35
|
+
)
|
36
|
+
JSON.parse(response.to_json, object_class: OpenStruct).entitlements
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_entitlement(plan_code, feature_code)
|
40
|
+
response = connection.get(entitlements_uri(plan_code, feature_code), identifier: nil)
|
41
|
+
JSON.parse(response.to_json, object_class: OpenStruct).entitlement
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete_entitlement(plan_code, feature_code)
|
45
|
+
response = connection.destroy(entitlements_uri(plan_code, feature_code), identifier: nil)
|
46
|
+
JSON.parse(response.to_json, object_class: OpenStruct).entitlement
|
47
|
+
end
|
48
|
+
|
49
|
+
def delete_entitlement_privilege(plan_code, feature_code, privilege_code)
|
50
|
+
response = connection.destroy(
|
51
|
+
entitlements_uri(plan_code, feature_code, "privileges/#{privilege_code}"),
|
52
|
+
identifier: nil,
|
53
|
+
)
|
54
|
+
JSON.parse(response.to_json, object_class: OpenStruct).entitlement
|
55
|
+
end
|
56
|
+
|
17
57
|
def whitelist_params(params)
|
18
58
|
result_hash = {
|
19
59
|
name: params[:name],
|
@@ -94,6 +134,21 @@ module Lago
|
|
94
134
|
|
95
135
|
processed_usage_thresholds
|
96
136
|
end
|
137
|
+
|
138
|
+
def whitelist_entitlements_params(params)
|
139
|
+
{
|
140
|
+
entitlements: params,
|
141
|
+
}
|
142
|
+
end
|
143
|
+
|
144
|
+
private
|
145
|
+
|
146
|
+
def entitlements_uri(plan_code, feature_code = nil, action = nil)
|
147
|
+
url = "#{client.base_api_url}#{api_resource}/#{plan_code}/entitlements"
|
148
|
+
url += "/#{feature_code}" if feature_code
|
149
|
+
url += "/#{action}" if action
|
150
|
+
URI(url)
|
151
|
+
end
|
97
152
|
end
|
98
153
|
end
|
99
154
|
end
|
@@ -35,6 +35,33 @@ module Lago
|
|
35
35
|
JSON.parse(response.to_json, object_class: OpenStruct).lifetime_usage
|
36
36
|
end
|
37
37
|
|
38
|
+
def get_entitlements(external_subscription_id)
|
39
|
+
response = connection.get(entitlements_uri(external_subscription_id), identifier: nil)
|
40
|
+
JSON.parse(response.to_json, object_class: OpenStruct).entitlements
|
41
|
+
end
|
42
|
+
|
43
|
+
def update_entitlements(external_subscription_id, params)
|
44
|
+
response = connection.patch(
|
45
|
+
entitlements_uri(external_subscription_id),
|
46
|
+
identifier: nil,
|
47
|
+
body: whitelist_entitlements_update_params(params),
|
48
|
+
)
|
49
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
50
|
+
end
|
51
|
+
|
52
|
+
def delete_entitlement(external_subscription_id, feature_code)
|
53
|
+
response = connection.destroy(entitlements_uri(external_subscription_id, feature_code), identifier: nil)
|
54
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
55
|
+
end
|
56
|
+
|
57
|
+
def delete_entitlement_privilege(external_subscription_id, entitlement_code, privilege_code)
|
58
|
+
response = connection.destroy(
|
59
|
+
entitlements_uri(external_subscription_id, entitlement_code, "privileges/#{privilege_code}"),
|
60
|
+
identifier: nil,
|
61
|
+
)
|
62
|
+
JSON.parse(response.to_json, object_class: OpenStruct)
|
63
|
+
end
|
64
|
+
|
38
65
|
def get_alert(external_subscription_id, code)
|
39
66
|
response = connection.get(alert_uri(external_subscription_id, code), identifier: nil)
|
40
67
|
JSON.parse(response.to_json, object_class: OpenStruct).alert
|
@@ -119,8 +146,21 @@ module Lago
|
|
119
146
|
end
|
120
147
|
end
|
121
148
|
|
149
|
+
def whitelist_entitlements_update_params(params)
|
150
|
+
{
|
151
|
+
entitlements: params,
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
122
155
|
private
|
123
156
|
|
157
|
+
def entitlements_uri(external_subscription_id, feature_code = nil, action = nil)
|
158
|
+
url = "#{client.base_api_url}#{api_resource}/#{external_subscription_id}/entitlements"
|
159
|
+
url += "/#{feature_code}" if feature_code
|
160
|
+
url += "/#{action}" if action
|
161
|
+
URI(url)
|
162
|
+
end
|
163
|
+
|
124
164
|
def alert_uri(external_subscription_id, code = nil)
|
125
165
|
URI("#{client.base_api_url}#{api_resource}/#{external_subscription_id}/alerts#{code ? "/#{code}" : ''}")
|
126
166
|
end
|
data/lib/lago/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lago-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.33.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lovro Colic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jwt
|
@@ -242,6 +242,7 @@ files:
|
|
242
242
|
- lib/lago/api/resources/credit_note.rb
|
243
243
|
- lib/lago/api/resources/customer.rb
|
244
244
|
- lib/lago/api/resources/event.rb
|
245
|
+
- lib/lago/api/resources/feature.rb
|
245
246
|
- lib/lago/api/resources/fee.rb
|
246
247
|
- lib/lago/api/resources/gross_revenue.rb
|
247
248
|
- lib/lago/api/resources/invoice.rb
|
@@ -256,6 +257,7 @@ files:
|
|
256
257
|
- lib/lago/api/resources/plan.rb
|
257
258
|
- lib/lago/api/resources/subscription.rb
|
258
259
|
- lib/lago/api/resources/tax.rb
|
260
|
+
- lib/lago/api/resources/usage.rb
|
259
261
|
- lib/lago/api/resources/wallet.rb
|
260
262
|
- lib/lago/api/resources/wallet_transaction.rb
|
261
263
|
- lib/lago/api/resources/webhook.rb
|