Class: Orb::Resources::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/orb/resources/metrics.rb,
sig/orb/resources/metrics.rbs

Overview

The Metric resource represents a calculation of a quantity based on events. Metrics are defined by the query that transforms raw usage events into meaningful values for your customers.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Metrics

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 Metrics.

Parameters:



140
141
142
# File 'lib/orb/resources/metrics.rb', line 140

def initialize(client:)
  @client = client
end

Instance Method Details

#create(description:, item_id:, name:, sql:, metadata: nil, request_options: {}) ⇒ Orb::Models::BillableMetric

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

This endpoint is used to create a metric using a SQL string. See SQL support for a description of constructing SQL queries with examples.

Parameters:

  • description (String, nil)

    A description of the metric.

  • item_id (String)

    The id of the item

  • name (String)

    The name of the metric.

  • sql (String)

    A sql string defining the metric.

  • metadata (Hash{Symbol=>String, nil}, nil)

    User-specified key/value pairs for the resource. Individual keys can be removed

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

Returns:

See Also:



33
34
35
36
37
38
39
40
41
42
# File 'lib/orb/resources/metrics.rb', line 33

def create(params)
  parsed, options = Orb::MetricCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "metrics",
    body: parsed,
    model: Orb::BillableMetric,
    options: options
  )
end

#fetch(metric_id, request_options: {}) ⇒ Orb::Models::BillableMetric

This endpoint is used to fetch metric details given a metric identifier. It returns information about the metrics including its name, description, and item.

Parameters:

Returns:

See Also:



128
129
130
131
132
133
134
135
# File 'lib/orb/resources/metrics.rb', line 128

def fetch(metric_id, params = {})
  @client.request(
    method: :get,
    path: ["metrics/%1$s", metric_id],
    model: Orb::BillableMetric,
    options: params[:request_options]
  )
end

#list(created_at_gt: nil, created_at_gte: nil, created_at_lt: nil, created_at_lte: nil, cursor: nil, limit: nil, request_options: {}) ⇒ Orb::Internal::Page<Orb::Models::BillableMetric>

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

This endpoint is used to list metrics. It returns information about the metrics including its name, description, and item.

Parameters:

  • created_at_gt (Time, nil)
  • created_at_gte (Time, nil)
  • created_at_lt (Time, nil)
  • created_at_lte (Time, nil)
  • cursor (String, nil)

    Cursor for pagination. This can be populated by the next_cursor value returned

  • limit (Integer)

    The number of items to fetch. Defaults to 20.

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

Returns:

See Also:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/orb/resources/metrics.rb', line 98

def list(params = {})
  parsed, options = Orb::MetricListParams.dump_request(params)
  query = Orb::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "metrics",
    query: query.transform_keys(
      created_at_gt: "created_at[gt]",
      created_at_gte: "created_at[gte]",
      created_at_lt: "created_at[lt]",
      created_at_lte: "created_at[lte]"
    ),
    page: Orb::Internal::Page,
    model: Orb::BillableMetric,
    options: options
  )
end

#update(metric_id, metadata: nil, request_options: {}) ⇒ Orb::Models::BillableMetric

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

This endpoint allows you to update the metadata property on a metric. If you pass null for the metadata value, it will clear any existing metadata for that invoice.

Parameters:

  • metric_id (String)
  • metadata (Hash{Symbol=>String, nil}, nil)

    User-specified key/value pairs for the resource. Individual keys can be removed

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

Returns:

See Also:



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

def update(metric_id, params = {})
  parsed, options = Orb::MetricUpdateParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["metrics/%1$s", metric_id],
    body: parsed,
    model: Orb::BillableMetric,
    options: options
  )
end