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

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

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:



76
77
78
# File 'lib/stigg/resources/v1/usage.rb', line 76

def initialize(client:)
  @client = client
end

Instance Method Details

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

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

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

Returns:

See Also:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/stigg/resources/v1/usage.rb', line 29

def history(feature_id, params)
  parsed, options = Stigg::V1::UsageHistoryParams.dump_request(params)
  query = Stigg::Internal::Util.encode_query_params(parsed)
  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"
    ),
    model: Stigg::Models::V1::UsageHistoryResponse,
    options: options
  )
end

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

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

Parameters:

Returns:

See Also:



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

def report(params)
  parsed, options = Stigg::V1::UsageReportParams.dump_request(params)
  @client.request(
    method: :post,
    path: "api/v1/usage",
    body: parsed,
    model: Stigg::Models::V1::UsageReportResponse,
    options: options
  )
end