Class: Stigg::Resources::V1::Subscriptions::Usage

Inherits:
Object
  • Object
show all
Defined in:
lib/stigg/resources/v1/subscriptions/usage.rb

Overview

Operations related to subscriptions

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Usage

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Usage.

Parameters:



79
80
81
# File 'lib/stigg/resources/v1/subscriptions/usage.rb', line 79

def initialize(client:)
  @client = client
end

Instance Method Details

#charge_usage(id, until_date: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Subscriptions::UsageChargeUsageResponse

Some parameter documentations has been truncated, see Models::V1::Subscriptions::UsageChargeUsageParams for more details.

Immediately charges usage for a subscription via the billing integration. Calculates usage since the last charge and creates an invoice.

Parameters:

  • id (String)

    Path param: The unique identifier of the entity

  • until_date (Time)

    Body param: Cutoff date for usage calculation. If not provided, the current time

  • x_account_id (String)

    Header param: Account ID — optional when authenticating with a user JWT (Bearer

  • x_environment_id (String)

    Header param: Environment ID — required when authenticating with a user JWT (Bea

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stigg/resources/v1/subscriptions/usage.rb', line 30

def charge_usage(id, params = {})
  parsed, options = Stigg::V1::Subscriptions::UsageChargeUsageParams.dump_request(params)
  header_params = {x_account_id: "x-account-id", x_environment_id: "x-environment-id"}
  @client.request(
    method: :post,
    path: ["api/v1/subscriptions/%1$s/usage/charge", id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Stigg::Models::V1::Subscriptions::UsageChargeUsageResponse,
    options: options
  )
end

#sync(id, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::Subscriptions::UsageSyncResponse

Some parameter documentations has been truncated, see Models::V1::Subscriptions::UsageSyncParams for more details.

Triggers a usage sync for a subscription, reporting current usage to the billing provider.

Parameters:

  • id (String)

    The unique identifier of the entity

  • x_account_id (String)

    Account ID — optional when authenticating with a user JWT (Bearer token); falls

  • x_environment_id (String)

    Environment ID — required when authenticating with a user JWT (Bearer token) on

  • request_options (Stigg::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/stigg/resources/v1/subscriptions/usage.rb', line 62

def sync(id, params = {})
  parsed, options = Stigg::V1::Subscriptions::UsageSyncParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["api/v1/subscriptions/%1$s/usage/sync", id],
    headers: parsed.transform_keys(
      x_account_id: "x-account-id",
      x_environment_id: "x-environment-id"
    ),
    model: Stigg::Models::V1::Subscriptions::UsageSyncResponse,
    options: options
  )
end