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

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

Overview

Operations related to usage & metering

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:



140
141
142
# File 'lib/stigg/resources/v1/usage.rb', line 140

def initialize(client:)
  @client = client
end

Instance Method Details

#estimate_cost(customer_id:, feature_id:, value:, dimensions: nil, resource_id: nil, update_behavior: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::UsageEstimateCostResponse

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

Estimates the credit cost of a usage report without recording it. Returns the estimated cost per credit currency, the current balance, and the balance after the estimated consumption.

Parameters:

  • customer_id (String)

    Body param: Customer id

  • feature_id (String)

    Body param: Feature id

  • value (Integer)

    Body param: The value to report for usage

  • dimensions (Hash{Symbol=>String, Float, Boolean})

    Body param: Additional dimensions for the usage report

  • resource_id (String, nil)

    Body param: Resource id

  • update_behavior (Symbol, Stigg::Models::V1::UsageEstimateCostParams::UpdateBehavior)

    Body param: The method by which the usage value should be updated

  • 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:



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/stigg/resources/v1/usage.rb', line 38

def estimate_cost(params)
  parsed, options = Stigg::V1::UsageEstimateCostParams.dump_request(params)
  header_params = {x_account_id: "x-account-id", x_environment_id: "x-environment-id"}
  @client.request(
    method: :post,
    path: "api/v1/usage/estimate",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Stigg::Models::V1::UsageEstimateCostResponse,
    options: options
  )
end

#history(feature_id, customer_id:, start_date:, end_date: nil, group_by: nil, resource_id: nil, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::UsageHistoryResponse

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

Retrieves historical usage data for a customer's metered feature over time.

Parameters:

  • feature_id (String)

    Path param: Feature id

  • customer_id (String)

    Path param: Customer id

  • start_date (Time)

    Query param: The start date of the range

  • end_date (Time)

    Query param: The end date of the range

  • group_by (String)

    Query param: Criteria by which to group the usage history

  • resource_id (String, nil)

    Query param: Resource id

  • 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:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/stigg/resources/v1/usage.rb', line 79

def history(feature_id, params)
  query_params = [:start_date, :end_date, :group_by, :resource_id]
  parsed, options = Stigg::V1::UsageHistoryParams.dump_request(params)
  query = Stigg::Internal::Util.encode_query_params(parsed.slice(*query_params))
  customer_id =
    parsed.delete(:customer_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["api/v1/usage/%1$s/history/%2$s", customer_id, feature_id],
    query: query.transform_keys(
      start_date: "startDate",
      end_date: "endDate",
      group_by: "groupBy",
      resource_id: "resourceId"
    ),
    headers: parsed.except(*query_params).transform_keys(
      x_account_id: "x-account-id",
      x_environment_id: "x-environment-id"
    ),
    model: Stigg::Models::V1::UsageHistoryResponse,
    options: options
  )
end

#report(usages:, x_account_id: nil, x_environment_id: nil, request_options: {}) ⇒ Stigg::Models::V1::UsageReportResponse

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

Reports usage measurements for metered features. The reported usage is used to track, limit, and bill customer consumption.

Parameters:

  • usages (Array<Stigg::Models::V1::UsageReportParams::Usage>)

    Body param: A list of usage reports to be submitted in bulk

  • 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:



124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/stigg/resources/v1/usage.rb', line 124

def report(params)
  parsed, options = Stigg::V1::UsageReportParams.dump_request(params)
  header_params = {x_account_id: "x-account-id", x_environment_id: "x-environment-id"}
  @client.request(
    method: :post,
    path: "api/v1/usage",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Stigg::Models::V1::UsageReportResponse,
    options: options
  )
end