schematichq 1.5.2 → 1.5.3
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/.fern/metadata.json +3 -3
- data/.fern/replay.lock +8 -338
- data/.fernignore +6 -0
- data/README.md +141 -0
- data/custom.gemspec.rb +6 -0
- data/lib/schematic/accounts/types/update_environment_request_body.rb +2 -0
- data/lib/schematic/client.rb +1 -1
- data/lib/schematic/credits/client.rb +50 -6
- data/lib/schematic/credits/leases/check.rb +477 -0
- data/lib/schematic/credits/leases/lease_manager.rb +565 -0
- data/lib/schematic/credits/leases/lease_store.rb +240 -0
- data/lib/schematic/credits/leases/redis_lease_store.rb +358 -0
- data/lib/schematic/credits/leases/redis_reservation_store.rb +326 -0
- data/lib/schematic/credits/leases/reservation_store.rb +161 -0
- data/lib/schematic/credits/leases/server_check.rb +237 -0
- data/lib/schematic/credits/leases/track.rb +66 -0
- data/lib/schematic/credits/leases/types.rb +329 -0
- data/lib/schematic/credits/leases/wire_client.rb +83 -0
- data/lib/schematic/credits/types/acquire_credit_lease_request_body.rb +2 -0
- data/lib/schematic/credits/types/create_credit_spend_policy_request_body.rb +5 -1
- data/lib/schematic/credits/types/extend_credit_lease_request_body.rb +2 -0
- data/lib/schematic/credits/types/get_credit_spend_policy_usage_params.rb +16 -0
- data/lib/schematic/credits/types/get_credit_spend_policy_usage_request.rb +15 -0
- data/lib/schematic/credits/types/get_credit_spend_policy_usage_response.rb +13 -0
- data/lib/schematic/credits/types/update_credit_spend_policy_request_body.rb +4 -0
- data/lib/schematic/datastream/client.rb +32 -2
- data/lib/schematic/entitlements/client.rb +165 -0
- data/lib/schematic/entitlements/types/count_company_user_usage_params.rb +24 -0
- data/lib/schematic/entitlements/types/count_company_user_usage_request.rb +23 -0
- data/lib/schematic/entitlements/types/count_company_user_usage_response.rb +13 -0
- data/lib/schematic/entitlements/types/get_company_user_usage_metrics_params.rb +16 -0
- data/lib/schematic/entitlements/types/get_company_user_usage_metrics_request.rb +15 -0
- data/lib/schematic/entitlements/types/get_company_user_usage_metrics_response.rb +13 -0
- data/lib/schematic/entitlements/types/list_company_user_usage_params.rb +24 -0
- data/lib/schematic/entitlements/types/list_company_user_usage_request.rb +23 -0
- data/lib/schematic/entitlements/types/list_company_user_usage_response.rb +13 -0
- data/lib/schematic/plangroups/client.rb +2 -0
- data/lib/schematic/plangroups/types/create_plan_group_request_body.rb +2 -0
- data/lib/schematic/plangroups/types/update_plan_group_request_body.rb +2 -0
- data/lib/schematic/planmigrations/client.rb +6 -0
- data/lib/schematic/planmigrations/types/count_migrations_params.rb +2 -0
- data/lib/schematic/planmigrations/types/count_migrations_request.rb +2 -0
- data/lib/schematic/planmigrations/types/create_migration_input.rb +2 -0
- data/lib/schematic/planmigrations/types/list_migrations_params.rb +2 -0
- data/lib/schematic/planmigrations/types/list_migrations_request.rb +2 -0
- data/lib/schematic/plans/types/publish_plan_version_request_body.rb +4 -0
- data/lib/schematic/plans/types/retry_custom_plan_billing_request_body.rb +2 -0
- data/lib/schematic/rules_engine.rb +37 -0
- data/lib/schematic/schematic_client.rb +830 -33
- data/lib/schematic/types/capture_raw_event.rb +4 -0
- data/lib/schematic/types/check_flags_response_data.rb +2 -0
- data/lib/schematic/types/company_detail_response_data.rb +2 -0
- data/lib/schematic/types/company_plan_detail_response_data.rb +2 -0
- data/lib/schematic/types/company_user_usage_metrics_response_data.rb +15 -0
- data/lib/schematic/types/company_user_usage_response_data.rb +19 -0
- data/lib/schematic/types/company_user_usage_row_response_data.rb +17 -0
- data/lib/schematic/types/component_display_settings.rb +2 -0
- data/lib/schematic/types/component_settings_response_data.rb +2 -0
- data/lib/schematic/types/credit_event_ledger_response_data.rb +5 -1
- data/lib/schematic/types/credit_event_type.rb +3 -0
- data/lib/schematic/types/credit_ledger_entry_kind.rb +17 -0
- data/lib/schematic/types/credit_spend_policy.rb +25 -0
- data/lib/schematic/types/credit_spend_policy_response_data.rb +12 -0
- data/lib/schematic/types/credit_spend_window.rb +11 -0
- data/lib/schematic/types/credit_spend_window_unit.rb +13 -0
- data/lib/schematic/types/custom_plan_billing_response_data.rb +2 -0
- data/lib/schematic/types/environment_detail_response_data.rb +2 -0
- data/lib/schematic/types/environment_response_data.rb +2 -0
- data/lib/schematic/types/estimated_plan_total.rb +13 -0
- data/lib/schematic/types/pending_migration_response_data.rb +6 -0
- data/lib/schematic/types/plan_version_migration_response_data.rb +2 -0
- data/lib/schematic/types/plan_version_migration_strategy.rb +1 -0
- data/lib/schematic/types/rules_engine_schema_version.rb +1 -1
- data/lib/schematic/types/rulesengine_company.rb +2 -0
- data/lib/schematic/types/rulesengine_credit_spend_policy.rb +25 -0
- data/lib/schematic/types/rulesengine_credit_spend_policy_scope.rb +13 -0
- data/lib/schematic/types/rulesengine_credit_spend_window.rb +11 -0
- data/lib/schematic/types/rulesengine_user.rb +2 -0
- data/lib/schematic/types/user_usage_metric.rb +12 -0
- data/lib/schematic/version.rb +1 -1
- data/lib/schematic.rb +26 -2
- data/lib/schematichq.rb +10 -0
- data/reference.md +474 -9
- metadata +36 -2
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "securerandom"
|
|
4
|
+
require "time"
|
|
5
|
+
|
|
6
|
+
module Schematic
|
|
7
|
+
module Credits
|
|
8
|
+
module Leases
|
|
9
|
+
# What the server says a lease is after an acquire or an extend. It is
|
|
10
|
+
# also what installs a lease into a store: the local balance is derived,
|
|
11
|
+
# never supplied.
|
|
12
|
+
LeaseGrant = Struct.new(:lease_id, :company_id, :credit_type_id, :granted_amount, :expires_at,
|
|
13
|
+
keyword_init: true)
|
|
14
|
+
|
|
15
|
+
# The lease lifecycle over the generated API client. Separated from
|
|
16
|
+
# LeaseManager so tests and the conformance runner can script the wire.
|
|
17
|
+
#
|
|
18
|
+
# Both calls take the client's default retry policy. Acquire is safe to
|
|
19
|
+
# retry because the server hands back the slot's existing active lease
|
|
20
|
+
# rather than opening a second one. An extend is an increment, so a retry
|
|
21
|
+
# after a lost response would grant the tranche twice; the request carries
|
|
22
|
+
# an idempotency key minted once per extend to collapse them.
|
|
23
|
+
class ApiWireClient
|
|
24
|
+
def initialize(credits_client:)
|
|
25
|
+
@credits = credits_client
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def acquire(company_id:, credit_type_id:, requested_amount:, expires_at:, request_options: {})
|
|
29
|
+
response = @credits.acquire_credit_lease(
|
|
30
|
+
request_options: request_options,
|
|
31
|
+
company_id: company_id,
|
|
32
|
+
credit_type_id: credit_type_id,
|
|
33
|
+
# Rounded up, not to nearest: the API takes a whole number, and a
|
|
34
|
+
# shortfall of 10.4 asked for as 10 leaves the retried reserve short
|
|
35
|
+
# by the same fraction every time.
|
|
36
|
+
requested_amount: Leases.wire_quantity(requested_amount),
|
|
37
|
+
expires_at: expires_at.utc.iso8601
|
|
38
|
+
)
|
|
39
|
+
grant_from(response)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def extend(lease_id:, additional_amount:, expires_at:, idempotency_key: nil, request_options: {})
|
|
43
|
+
body = {
|
|
44
|
+
lease_id: lease_id,
|
|
45
|
+
additional_amount: Leases.wire_quantity(additional_amount),
|
|
46
|
+
expires_at: expires_at.utc.iso8601,
|
|
47
|
+
# The key is minted once here, outside the retry loop, so every
|
|
48
|
+
# attempt of this extend carries the same one and the server folds
|
|
49
|
+
# them into a single increment. A caller that already minted one
|
|
50
|
+
# keeps it: the manager does, so its single-flight followers settle
|
|
51
|
+
# against the same key.
|
|
52
|
+
idempotency_key: idempotency_key || SecureRandom.uuid
|
|
53
|
+
}
|
|
54
|
+
grant_from(@credits.extend_credit_lease(request_options: request_options, **body))
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def release(lease_id:, request_options: {})
|
|
58
|
+
@credits.release_credit_lease(request_options: request_options, lease_id: lease_id)
|
|
59
|
+
nil
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def grant_from(response)
|
|
65
|
+
data = response&.data
|
|
66
|
+
raise "credit lease response carried no data" if data.nil?
|
|
67
|
+
|
|
68
|
+
LeaseGrant.new(
|
|
69
|
+
lease_id: data.id,
|
|
70
|
+
company_id: data.company_id,
|
|
71
|
+
credit_type_id: data.credit_type_id,
|
|
72
|
+
granted_amount: data.granted_amount.to_f,
|
|
73
|
+
expires_at: parse_time(data.expires_at)
|
|
74
|
+
)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def parse_time(value)
|
|
78
|
+
Leases.parse_api_time(value)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -10,9 +10,13 @@ module Schematic
|
|
|
10
10
|
|
|
11
11
|
field :label, -> { String }, optional: true, nullable: false
|
|
12
12
|
|
|
13
|
-
field :max_per_draw, -> { Integer }, optional:
|
|
13
|
+
field :max_per_draw, -> { Integer }, optional: true, nullable: false
|
|
14
14
|
|
|
15
15
|
field :user_id, -> { String }, optional: true, nullable: false
|
|
16
|
+
|
|
17
|
+
field :window_amount, -> { Integer }, optional: true, nullable: false
|
|
18
|
+
|
|
19
|
+
field :window_unit, -> { Schematic::Types::CreditSpendWindowUnit }, optional: true, nullable: false
|
|
16
20
|
end
|
|
17
21
|
end
|
|
18
22
|
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Credits
|
|
5
|
+
module Types
|
|
6
|
+
# Input parameters
|
|
7
|
+
class GetCreditSpendPolicyUsageParams < Internal::Types::Model
|
|
8
|
+
field :billing_credit_id, -> { String }, optional: true, nullable: false
|
|
9
|
+
|
|
10
|
+
field :company_id, -> { String }, optional: true, nullable: false
|
|
11
|
+
|
|
12
|
+
field :user_ids, -> { Internal::Types::Array[String] }, optional: true, nullable: false
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Credits
|
|
5
|
+
module Types
|
|
6
|
+
class GetCreditSpendPolicyUsageRequest < Internal::Types::Model
|
|
7
|
+
field :billing_credit_id, -> { String }, optional: true, nullable: false
|
|
8
|
+
|
|
9
|
+
field :company_id, -> { String }, optional: false, nullable: false
|
|
10
|
+
|
|
11
|
+
field :user_ids, -> { String }, optional: true, nullable: false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Credits
|
|
5
|
+
module Types
|
|
6
|
+
class GetCreditSpendPolicyUsageResponse < Internal::Types::Model
|
|
7
|
+
field :data, -> { Internal::Types::Array[Schematic::Types::CreditSpendPolicyResponseData] }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :params, -> { Schematic::Credits::Types::GetCreditSpendPolicyUsageParams }, optional: false, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -9,6 +9,10 @@ module Schematic
|
|
|
9
9
|
field :label, -> { String }, optional: true, nullable: false
|
|
10
10
|
|
|
11
11
|
field :max_per_draw, -> { Integer }, optional: true, nullable: false
|
|
12
|
+
|
|
13
|
+
field :window_amount, -> { Integer }, optional: true, nullable: false
|
|
14
|
+
|
|
15
|
+
field :window_unit, -> { Schematic::Types::CreditSpendWindowUnit }, optional: true, nullable: false
|
|
12
16
|
end
|
|
13
17
|
end
|
|
14
18
|
end
|
|
@@ -146,7 +146,11 @@ module Schematic
|
|
|
146
146
|
# Raises DataStream::EvaluationError when the flag cannot be evaluated
|
|
147
147
|
# locally (e.g. flag not in cache, rules engine unavailable), so the caller
|
|
148
148
|
# can fall back to the API path.
|
|
149
|
-
|
|
149
|
+
# options carries the caller's preflight (a simulated usage, an
|
|
150
|
+
# event-scoped usage, or a per-credit cost) through to the engine, so a
|
|
151
|
+
# client-side evaluation gates on the post-call balance. Nil evaluates the
|
|
152
|
+
# flag as it stands.
|
|
153
|
+
def check_flag(eval_ctx, flag_key, options = nil)
|
|
150
154
|
flag = get_flag(flag_key)
|
|
151
155
|
raise EvaluationError, "flag '#{flag_key}' not found in cache" unless flag
|
|
152
156
|
|
|
@@ -172,12 +176,22 @@ module Schematic
|
|
|
172
176
|
end
|
|
173
177
|
|
|
174
178
|
@logger.debug("Evaluating flag with rules engine: flag=#{flag_key}, company=#{company&.dig(:id)}, user=#{user&.dig(:id)}")
|
|
175
|
-
result = @rules_engine.
|
|
179
|
+
result = @rules_engine.check_flag_with_options(flag, company, user, options)
|
|
176
180
|
@logger.debug("Rules engine evaluation result: value=#{result[:value]}, reason=#{result[:reason]}")
|
|
177
181
|
result[:flag_key] = flag_key
|
|
178
182
|
result
|
|
179
183
|
end
|
|
180
184
|
|
|
185
|
+
# Evaluate a flag against an explicit company and user with preflight
|
|
186
|
+
# options, skipping the cache lookups check_flag does. The credit-lease
|
|
187
|
+
# path has already resolved both entities and needs to gate against a
|
|
188
|
+
# substituted credit balance, which only it can build.
|
|
189
|
+
def check_flag_with_options(flag, company, user, options)
|
|
190
|
+
raise EvaluationError, "rules engine not available" unless @rules_engine&.initialized?
|
|
191
|
+
|
|
192
|
+
@rules_engine.check_flag_with_options(flag, company, user, options)
|
|
193
|
+
end
|
|
194
|
+
|
|
181
195
|
def update_company_metrics(company_keys, event_name, quantity)
|
|
182
196
|
company = @company_cache.get_by_keys(company_keys)
|
|
183
197
|
return unless company
|
|
@@ -231,6 +245,10 @@ module Schematic
|
|
|
231
245
|
return cached if cached
|
|
232
246
|
|
|
233
247
|
return nil if @replicator_mode
|
|
248
|
+
# A request sent over a closed socket is dropped without an error, so
|
|
249
|
+
# waiting on it just burns the resource timeout. Answer now and let the
|
|
250
|
+
# caller fall back.
|
|
251
|
+
return nil unless connected?
|
|
234
252
|
|
|
235
253
|
request_entity(ENTITY_TYPE_COMPANY, keys, @pending_companies) do |_data|
|
|
236
254
|
@company_cache.get_by_keys(keys)
|
|
@@ -242,6 +260,7 @@ module Schematic
|
|
|
242
260
|
return cached if cached
|
|
243
261
|
|
|
244
262
|
return nil if @replicator_mode
|
|
263
|
+
return nil unless connected?
|
|
245
264
|
|
|
246
265
|
request_entity(ENTITY_TYPE_USER, keys, @pending_users) do |_data|
|
|
247
266
|
@user_cache.get_by_keys(keys)
|
|
@@ -513,6 +532,17 @@ module Schematic
|
|
|
513
532
|
@logger.info("Replicator is no longer ready") if was_ready
|
|
514
533
|
@logger.warn("Replicator health check error: #{e.message}")
|
|
515
534
|
end
|
|
535
|
+
|
|
536
|
+
# The cached company for these keys, without the fetch get_company falls
|
|
537
|
+
# back to. prewarm polls this to resolve a company id from secondary keys.
|
|
538
|
+
def get_cached_company(keys)
|
|
539
|
+
@company_cache.get_by_keys(keys)
|
|
540
|
+
end
|
|
541
|
+
|
|
542
|
+
# Cache-first flag and entity lookups, declared public after their
|
|
543
|
+
# definitions. The credit-lease check path resolves the flag, the company,
|
|
544
|
+
# and the user itself before evaluating, so it needs all three.
|
|
545
|
+
public :get_flag, :get_company, :get_user, :get_cached_company
|
|
516
546
|
end
|
|
517
547
|
end
|
|
518
548
|
end
|
|
@@ -1196,6 +1196,171 @@ module Schematic
|
|
|
1196
1196
|
end
|
|
1197
1197
|
end
|
|
1198
1198
|
|
|
1199
|
+
# @param request_options [Hash]
|
|
1200
|
+
# @param params [Hash]
|
|
1201
|
+
# @option request_options [String] :base_url
|
|
1202
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
1203
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
1204
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
1205
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
1206
|
+
# @option params [String] :company_id
|
|
1207
|
+
# @option params [String, nil] :end_time
|
|
1208
|
+
# @option params [String, nil] :start_time
|
|
1209
|
+
#
|
|
1210
|
+
# @example
|
|
1211
|
+
# client.entitlements.get_company_user_usage_metrics(
|
|
1212
|
+
# company_id: "company_id",
|
|
1213
|
+
# end_time: "2024-01-15T09:30:00Z",
|
|
1214
|
+
# start_time: "2024-01-15T09:30:00Z"
|
|
1215
|
+
# )
|
|
1216
|
+
#
|
|
1217
|
+
# @return [Schematic::Entitlements::Types::GetCompanyUserUsageMetricsResponse]
|
|
1218
|
+
def get_company_user_usage_metrics(request_options: {}, **params)
|
|
1219
|
+
params = Schematic::Internal::Types::Utils.normalize_keys(params)
|
|
1220
|
+
query_params = {}
|
|
1221
|
+
query_params["company_id"] = params[:company_id] if params.key?(:company_id)
|
|
1222
|
+
query_params["end_time"] = params[:end_time] if params.key?(:end_time)
|
|
1223
|
+
query_params["start_time"] = params[:start_time] if params.key?(:start_time)
|
|
1224
|
+
|
|
1225
|
+
request = Schematic::Internal::JSON::Request.new(
|
|
1226
|
+
base_url: request_options[:base_url],
|
|
1227
|
+
method: "GET",
|
|
1228
|
+
path: "user-usage-by-company/metrics",
|
|
1229
|
+
query: query_params,
|
|
1230
|
+
request_options: request_options
|
|
1231
|
+
)
|
|
1232
|
+
begin
|
|
1233
|
+
response = @client.send(request)
|
|
1234
|
+
rescue Net::HTTPRequestTimeout
|
|
1235
|
+
raise Schematic::Errors::TimeoutError
|
|
1236
|
+
end
|
|
1237
|
+
code = response.code.to_i
|
|
1238
|
+
if code.between?(200, 299)
|
|
1239
|
+
(response.body.to_s.empty? ? nil : Schematic::Entitlements::Types::GetCompanyUserUsageMetricsResponse.load(response.body))
|
|
1240
|
+
else
|
|
1241
|
+
error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
|
|
1242
|
+
raise error_class.new(response.body, code: code)
|
|
1243
|
+
end
|
|
1244
|
+
end
|
|
1245
|
+
|
|
1246
|
+
# @param request_options [Hash]
|
|
1247
|
+
# @param params [Hash]
|
|
1248
|
+
# @option request_options [String] :base_url
|
|
1249
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
1250
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
1251
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
1252
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
1253
|
+
# @option params [String] :company_id
|
|
1254
|
+
# @option params [String, nil] :end_time
|
|
1255
|
+
# @option params [String, nil] :feature_id
|
|
1256
|
+
# @option params [Schematic::Types::UserUsageMetric] :metric
|
|
1257
|
+
# @option params [Integer, nil] :limit
|
|
1258
|
+
# @option params [Integer, nil] :offset
|
|
1259
|
+
# @option params [String, nil] :start_time
|
|
1260
|
+
#
|
|
1261
|
+
# @example
|
|
1262
|
+
# client.entitlements.list_company_user_usage(
|
|
1263
|
+
# company_id: "company_id",
|
|
1264
|
+
# end_time: "2024-01-15T09:30:00Z",
|
|
1265
|
+
# feature_id: "feature_id",
|
|
1266
|
+
# metric: "credits",
|
|
1267
|
+
# limit: 1000000,
|
|
1268
|
+
# offset: 1000000,
|
|
1269
|
+
# start_time: "2024-01-15T09:30:00Z"
|
|
1270
|
+
# )
|
|
1271
|
+
#
|
|
1272
|
+
# @return [Schematic::Entitlements::Types::ListCompanyUserUsageResponse]
|
|
1273
|
+
def list_company_user_usage(request_options: {}, **params)
|
|
1274
|
+
params = Schematic::Internal::Types::Utils.normalize_keys(params)
|
|
1275
|
+
query_params = {}
|
|
1276
|
+
query_params["company_id"] = params[:company_id] if params.key?(:company_id)
|
|
1277
|
+
query_params["end_time"] = params[:end_time] if params.key?(:end_time)
|
|
1278
|
+
query_params["feature_id"] = params[:feature_id] if params.key?(:feature_id)
|
|
1279
|
+
query_params["metric"] = params[:metric] if params.key?(:metric)
|
|
1280
|
+
query_params["limit"] = params[:limit] if params.key?(:limit)
|
|
1281
|
+
query_params["offset"] = params[:offset] if params.key?(:offset)
|
|
1282
|
+
query_params["start_time"] = params[:start_time] if params.key?(:start_time)
|
|
1283
|
+
|
|
1284
|
+
request = Schematic::Internal::JSON::Request.new(
|
|
1285
|
+
base_url: request_options[:base_url],
|
|
1286
|
+
method: "GET",
|
|
1287
|
+
path: "user-usage-by-company/users",
|
|
1288
|
+
query: query_params,
|
|
1289
|
+
request_options: request_options
|
|
1290
|
+
)
|
|
1291
|
+
begin
|
|
1292
|
+
response = @client.send(request)
|
|
1293
|
+
rescue Net::HTTPRequestTimeout
|
|
1294
|
+
raise Schematic::Errors::TimeoutError
|
|
1295
|
+
end
|
|
1296
|
+
code = response.code.to_i
|
|
1297
|
+
if code.between?(200, 299)
|
|
1298
|
+
(response.body.to_s.empty? ? nil : Schematic::Entitlements::Types::ListCompanyUserUsageResponse.load(response.body))
|
|
1299
|
+
else
|
|
1300
|
+
error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
|
|
1301
|
+
raise error_class.new(response.body, code: code)
|
|
1302
|
+
end
|
|
1303
|
+
end
|
|
1304
|
+
|
|
1305
|
+
# @param request_options [Hash]
|
|
1306
|
+
# @param params [Hash]
|
|
1307
|
+
# @option request_options [String] :base_url
|
|
1308
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
1309
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
1310
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
1311
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
1312
|
+
# @option params [String] :company_id
|
|
1313
|
+
# @option params [String, nil] :end_time
|
|
1314
|
+
# @option params [String, nil] :feature_id
|
|
1315
|
+
# @option params [Schematic::Types::UserUsageMetric] :metric
|
|
1316
|
+
# @option params [Integer, nil] :limit
|
|
1317
|
+
# @option params [Integer, nil] :offset
|
|
1318
|
+
# @option params [String, nil] :start_time
|
|
1319
|
+
#
|
|
1320
|
+
# @example
|
|
1321
|
+
# client.entitlements.count_company_user_usage(
|
|
1322
|
+
# company_id: "company_id",
|
|
1323
|
+
# end_time: "2024-01-15T09:30:00Z",
|
|
1324
|
+
# feature_id: "feature_id",
|
|
1325
|
+
# metric: "credits",
|
|
1326
|
+
# limit: 1000000,
|
|
1327
|
+
# offset: 1000000,
|
|
1328
|
+
# start_time: "2024-01-15T09:30:00Z"
|
|
1329
|
+
# )
|
|
1330
|
+
#
|
|
1331
|
+
# @return [Schematic::Entitlements::Types::CountCompanyUserUsageResponse]
|
|
1332
|
+
def count_company_user_usage(request_options: {}, **params)
|
|
1333
|
+
params = Schematic::Internal::Types::Utils.normalize_keys(params)
|
|
1334
|
+
query_params = {}
|
|
1335
|
+
query_params["company_id"] = params[:company_id] if params.key?(:company_id)
|
|
1336
|
+
query_params["end_time"] = params[:end_time] if params.key?(:end_time)
|
|
1337
|
+
query_params["feature_id"] = params[:feature_id] if params.key?(:feature_id)
|
|
1338
|
+
query_params["metric"] = params[:metric] if params.key?(:metric)
|
|
1339
|
+
query_params["limit"] = params[:limit] if params.key?(:limit)
|
|
1340
|
+
query_params["offset"] = params[:offset] if params.key?(:offset)
|
|
1341
|
+
query_params["start_time"] = params[:start_time] if params.key?(:start_time)
|
|
1342
|
+
|
|
1343
|
+
request = Schematic::Internal::JSON::Request.new(
|
|
1344
|
+
base_url: request_options[:base_url],
|
|
1345
|
+
method: "GET",
|
|
1346
|
+
path: "user-usage-by-company/users/count",
|
|
1347
|
+
query: query_params,
|
|
1348
|
+
request_options: request_options
|
|
1349
|
+
)
|
|
1350
|
+
begin
|
|
1351
|
+
response = @client.send(request)
|
|
1352
|
+
rescue Net::HTTPRequestTimeout
|
|
1353
|
+
raise Schematic::Errors::TimeoutError
|
|
1354
|
+
end
|
|
1355
|
+
code = response.code.to_i
|
|
1356
|
+
if code.between?(200, 299)
|
|
1357
|
+
(response.body.to_s.empty? ? nil : Schematic::Entitlements::Types::CountCompanyUserUsageResponse.load(response.body))
|
|
1358
|
+
else
|
|
1359
|
+
error_class = Schematic::Errors::ResponseError.subclass_for_code(code)
|
|
1360
|
+
raise error_class.new(response.body, code: code)
|
|
1361
|
+
end
|
|
1362
|
+
end
|
|
1363
|
+
|
|
1199
1364
|
# @param request_options [Hash]
|
|
1200
1365
|
# @param params [Hash]
|
|
1201
1366
|
# @option request_options [String] :base_url
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Entitlements
|
|
5
|
+
module Types
|
|
6
|
+
# Input parameters
|
|
7
|
+
class CountCompanyUserUsageParams < Internal::Types::Model
|
|
8
|
+
field :company_id, -> { String }, optional: true, nullable: false
|
|
9
|
+
|
|
10
|
+
field :end_time, -> { String }, optional: true, nullable: false
|
|
11
|
+
|
|
12
|
+
field :feature_id, -> { String }, optional: true, nullable: false
|
|
13
|
+
|
|
14
|
+
field :limit, -> { Integer }, optional: true, nullable: false
|
|
15
|
+
|
|
16
|
+
field :metric, -> { Schematic::Types::UserUsageMetric }, optional: true, nullable: false
|
|
17
|
+
|
|
18
|
+
field :offset, -> { Integer }, optional: true, nullable: false
|
|
19
|
+
|
|
20
|
+
field :start_time, -> { String }, optional: true, nullable: false
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Entitlements
|
|
5
|
+
module Types
|
|
6
|
+
class CountCompanyUserUsageRequest < Internal::Types::Model
|
|
7
|
+
field :company_id, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :end_time, -> { String }, optional: true, nullable: false
|
|
10
|
+
|
|
11
|
+
field :feature_id, -> { String }, optional: true, nullable: false
|
|
12
|
+
|
|
13
|
+
field :metric, -> { Schematic::Types::UserUsageMetric }, optional: false, nullable: false
|
|
14
|
+
|
|
15
|
+
field :limit, -> { Integer }, optional: true, nullable: false
|
|
16
|
+
|
|
17
|
+
field :offset, -> { Integer }, optional: true, nullable: false
|
|
18
|
+
|
|
19
|
+
field :start_time, -> { String }, optional: true, nullable: false
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Entitlements
|
|
5
|
+
module Types
|
|
6
|
+
class CountCompanyUserUsageResponse < Internal::Types::Model
|
|
7
|
+
field :data, -> { Schematic::Types::CountResponse }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :params, -> { Schematic::Entitlements::Types::CountCompanyUserUsageParams }, optional: false, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Entitlements
|
|
5
|
+
module Types
|
|
6
|
+
# Input parameters
|
|
7
|
+
class GetCompanyUserUsageMetricsParams < Internal::Types::Model
|
|
8
|
+
field :company_id, -> { String }, optional: true, nullable: false
|
|
9
|
+
|
|
10
|
+
field :end_time, -> { String }, optional: true, nullable: false
|
|
11
|
+
|
|
12
|
+
field :start_time, -> { String }, optional: true, nullable: false
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Entitlements
|
|
5
|
+
module Types
|
|
6
|
+
class GetCompanyUserUsageMetricsRequest < Internal::Types::Model
|
|
7
|
+
field :company_id, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :end_time, -> { String }, optional: true, nullable: false
|
|
10
|
+
|
|
11
|
+
field :start_time, -> { String }, optional: true, nullable: false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Entitlements
|
|
5
|
+
module Types
|
|
6
|
+
class GetCompanyUserUsageMetricsResponse < Internal::Types::Model
|
|
7
|
+
field :data, -> { Schematic::Types::CompanyUserUsageMetricsResponseData }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :params, -> { Schematic::Entitlements::Types::GetCompanyUserUsageMetricsParams }, optional: false, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Entitlements
|
|
5
|
+
module Types
|
|
6
|
+
# Input parameters
|
|
7
|
+
class ListCompanyUserUsageParams < Internal::Types::Model
|
|
8
|
+
field :company_id, -> { String }, optional: true, nullable: false
|
|
9
|
+
|
|
10
|
+
field :end_time, -> { String }, optional: true, nullable: false
|
|
11
|
+
|
|
12
|
+
field :feature_id, -> { String }, optional: true, nullable: false
|
|
13
|
+
|
|
14
|
+
field :limit, -> { Integer }, optional: true, nullable: false
|
|
15
|
+
|
|
16
|
+
field :metric, -> { Schematic::Types::UserUsageMetric }, optional: true, nullable: false
|
|
17
|
+
|
|
18
|
+
field :offset, -> { Integer }, optional: true, nullable: false
|
|
19
|
+
|
|
20
|
+
field :start_time, -> { String }, optional: true, nullable: false
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Entitlements
|
|
5
|
+
module Types
|
|
6
|
+
class ListCompanyUserUsageRequest < Internal::Types::Model
|
|
7
|
+
field :company_id, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :end_time, -> { String }, optional: true, nullable: false
|
|
10
|
+
|
|
11
|
+
field :feature_id, -> { String }, optional: true, nullable: false
|
|
12
|
+
|
|
13
|
+
field :metric, -> { Schematic::Types::UserUsageMetric }, optional: false, nullable: false
|
|
14
|
+
|
|
15
|
+
field :limit, -> { Integer }, optional: true, nullable: false
|
|
16
|
+
|
|
17
|
+
field :offset, -> { Integer }, optional: true, nullable: false
|
|
18
|
+
|
|
19
|
+
field :start_time, -> { String }, optional: true, nullable: false
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Schematic
|
|
4
|
+
module Entitlements
|
|
5
|
+
module Types
|
|
6
|
+
class ListCompanyUserUsageResponse < Internal::Types::Model
|
|
7
|
+
field :data, -> { Schematic::Types::CompanyUserUsageResponseData }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :params, -> { Schematic::Entitlements::Types::ListCompanyUserUsageParams }, optional: false, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -80,6 +80,7 @@ module Schematic
|
|
|
80
80
|
# proration_behavior: "create_prorations",
|
|
81
81
|
# show_as_monthly_prices: true,
|
|
82
82
|
# show_credits: true,
|
|
83
|
+
# show_estimated_total: true,
|
|
83
84
|
# show_feature_description: true,
|
|
84
85
|
# show_hard_limit: true,
|
|
85
86
|
# show_period_toggle: true,
|
|
@@ -144,6 +145,7 @@ module Schematic
|
|
|
144
145
|
# proration_behavior: "create_prorations",
|
|
145
146
|
# show_as_monthly_prices: true,
|
|
146
147
|
# show_credits: true,
|
|
148
|
+
# show_estimated_total: true,
|
|
147
149
|
# show_feature_description: true,
|
|
148
150
|
# show_hard_limit: true,
|
|
149
151
|
# show_period_toggle: true,
|
|
@@ -62,6 +62,8 @@ module Schematic
|
|
|
62
62
|
|
|
63
63
|
field :show_credits, -> { Internal::Types::Boolean }, optional: false, nullable: false
|
|
64
64
|
|
|
65
|
+
field :show_estimated_total, -> { Internal::Types::Boolean }, optional: false, nullable: false
|
|
66
|
+
|
|
65
67
|
field :show_feature_description, -> { Internal::Types::Boolean }, optional: false, nullable: false
|
|
66
68
|
|
|
67
69
|
field :show_hard_limit, -> { Internal::Types::Boolean }, optional: false, nullable: false
|
|
@@ -64,6 +64,8 @@ module Schematic
|
|
|
64
64
|
|
|
65
65
|
field :show_credits, -> { Internal::Types::Boolean }, optional: false, nullable: false
|
|
66
66
|
|
|
67
|
+
field :show_estimated_total, -> { Internal::Types::Boolean }, optional: false, nullable: false
|
|
68
|
+
|
|
67
69
|
field :show_feature_description, -> { Internal::Types::Boolean }, optional: false, nullable: false
|
|
68
70
|
|
|
69
71
|
field :show_hard_limit, -> { Internal::Types::Boolean }, optional: false, nullable: false
|