Class: Orb::Resources::Metrics

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

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:



136
137
138
# File 'lib/orb/resources/metrics.rb', line 136

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](/core-concepts###metric) using a SQL string. See [SQL support](/extensibility/advanced-metrics#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:



30
31
32
33
34
35
36
37
38
39
# File 'lib/orb/resources/metrics.rb', line 30

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 list [metrics](/core-concepts#metric). It returns information about the metrics including its name, description, and item.

Parameters:

Returns:

See Also:



124
125
126
127
128
129
130
131
# File 'lib/orb/resources/metrics.rb', line 124

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 fetch [metric](/core-concepts##metric) details given a metric identifier. 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:



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

def list(params = {})
  parsed, options = Orb::MetricListParams.dump_request(params)
  @client.request(
    method: :get,
    path: "metrics",
    query: parsed.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:



59
60
61
62
63
64
65
66
67
68
# File 'lib/orb/resources/metrics.rb', line 59

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