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:



58
59
60
# File 'lib/stigg/resources/v1/subscriptions/usage.rb', line 58

def initialize(client:)
  @client = client
end

Instance Method Details

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

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

Parameters:

  • id (String)

    The unique identifier of the entity

  • until_date (Time)

    Cutoff date for usage calculation. If not provided, the current time is used.

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

Returns:

See Also:



23
24
25
26
27
28
29
30
31
32
# File 'lib/stigg/resources/v1/subscriptions/usage.rb', line 23

def charge_usage(id, params = {})
  parsed, options = Stigg::V1::Subscriptions::UsageChargeUsageParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["api/v1/subscriptions/%1$s/usage/charge", id],
    body: parsed,
    model: Stigg::Models::V1::Subscriptions::UsageChargeUsageResponse,
    options: options
  )
end

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

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

Parameters:

  • id (String)

    The unique identifier of the entity

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

Returns:

See Also:



46
47
48
49
50
51
52
53
# File 'lib/stigg/resources/v1/subscriptions/usage.rb', line 46

def sync(id, params = {})
  @client.request(
    method: :post,
    path: ["api/v1/subscriptions/%1$s/usage/sync", id],
    model: Stigg::Models::V1::Subscriptions::UsageSyncResponse,
    options: params[:request_options]
  )
end