Class: Pago::V2026_04::Services::Metrics

Inherits:
Service
  • Object
show all
Defined in:
lib/pago/v2026_04/services/metrics.rb,
sig/pago/v2026_04/generated.rbs

Instance Attribute Summary

Attributes inherited from Service

#client

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from Pago::Service

Instance Method Details

#create_dashboard(body: {}) ⇒ Models::MetricDashboardSchema

Create a user-defined metric dashboard.

Scopes: metrics:write

Parameters:

Returns:

Raises:



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/pago/v2026_04/services/metrics.rb', line 110

def create_dashboard(body: {})
  data = client.request(
    http_method: "POST",
    path: "/v1/metrics/dashboards",
    path_params: {},
    query: {},
    body: body,
    response_type: :json,
    errors: { 422 => Errors::HTTPValidationError }
  )
  Models::MetricDashboardSchema.from_json(data)
end

#delete_dashboard(id) ⇒ nil

Delete a user-defined metric dashboard.

Scopes: metrics:write

Parameters:

  • id (String)

    The metric dashboard ID.

Returns:

  • (nil)

Raises:



151
152
153
154
155
156
157
158
159
160
# File 'lib/pago/v2026_04/services/metrics.rb', line 151

def delete_dashboard(id)
  client.request(
    http_method: "DELETE",
    path: "/v1/metrics/dashboards/{id}",
    path_params: { "id" => id },
    query: {},
    response_type: :none,
    errors: { 422 => Errors::HTTPValidationError }
  )
end

#export(start_date:, end_date:, timezone: "UTC", interval:, organization_id: nil, product_id: nil, billing_type: nil, customer_id: nil, metrics: nil) ⇒ String

Export metrics as a CSV file.

Scopes: metrics:read

Parameters:

  • start_date (String)

    Start date.

  • end_date (String)

    End date.

  • timezone (String) (defaults to: "UTC")

    Timezone to use for the timestamps. Default is UTC.

  • interval (String)

    Interval between two timestamps.

  • organization_id (String, Array<String>, nil) (defaults to: nil)

    Filter by organization ID.

  • product_id (String, Array<String>, nil) (defaults to: nil)

    Filter by product ID.

  • billing_type (String, Array<String>, nil) (defaults to: nil)

    Filter by billing type. recurring will filter data corresponding to subscriptions creations or renewals. one_time will filter data corresponding to one-time purchases.

  • customer_id (String, Array<String>, nil) (defaults to: nil)

    Filter by customer ID.

  • metrics (Array<String>, nil) (defaults to: nil)

    List of metric slugs to include in the export. If not provided, all metrics are exported.

  • start_date: (String)
  • end_date: (String)
  • timezone: (String, nil) (defaults to: "UTC")
  • interval: (String)
  • organization_id: (Object) (defaults to: nil)
  • product_id: (Object) (defaults to: nil)
  • billing_type: (Object) (defaults to: nil)
  • customer_id: (Object) (defaults to: nil)
  • metrics: (Array[String], nil) (defaults to: nil)

Returns:

  • (String)

Raises:



53
54
55
56
57
58
59
60
61
62
# File 'lib/pago/v2026_04/services/metrics.rb', line 53

def export(start_date:, end_date:, timezone: "UTC", interval:, organization_id: nil, product_id: nil, billing_type: nil, customer_id: nil, metrics: nil)
  client.request(
    http_method: "GET",
    path: "/v1/metrics/export",
    path_params: {},
    query: { "start_date" => start_date, "end_date" => end_date, "timezone" => timezone, "interval" => interval, "organization_id" => organization_id, "product_id" => product_id, "billing_type" => billing_type, "customer_id" => customer_id, "metrics" => metrics },
    response_type: :text,
    errors: { 422 => Errors::HTTPValidationError }
  )
end

#get(start_date:, end_date:, timezone: "UTC", interval:, organization_id: nil, product_id: nil, billing_type: nil, customer_id: nil, metrics: nil) ⇒ Models::MetricsResponse

Get metrics about your orders and subscriptions.

Currency values are output in cents.

Scopes: metrics:read

Parameters:

  • start_date (String)

    Start date.

  • end_date (String)

    End date.

  • timezone (String) (defaults to: "UTC")

    Timezone to use for the timestamps. Default is UTC.

  • interval (String)

    Interval between two timestamps.

  • organization_id (String, Array<String>, nil) (defaults to: nil)

    Filter by organization ID.

  • product_id (String, Array<String>, nil) (defaults to: nil)

    Filter by product ID.

  • billing_type (String, Array<String>, nil) (defaults to: nil)

    Filter by billing type. recurring will filter data corresponding to subscriptions creations or renewals. one_time will filter data corresponding to one-time purchases.

  • customer_id (String, Array<String>, nil) (defaults to: nil)

    Filter by customer ID.

  • metrics (Array<String>, nil) (defaults to: nil)

    List of metric slugs to focus on. When provided, only the queries needed for these metrics will be executed, improving performance. If not provided, all metrics are returned.

  • start_date: (String)
  • end_date: (String)
  • timezone: (String, nil) (defaults to: "UTC")
  • interval: (String)
  • organization_id: (Object) (defaults to: nil)
  • product_id: (Object) (defaults to: nil)
  • billing_type: (Object) (defaults to: nil)
  • customer_id: (Object) (defaults to: nil)
  • metrics: (Array[String], nil) (defaults to: nil)

Returns:

Raises:



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/pago/v2026_04/services/metrics.rb', line 25

def get(start_date:, end_date:, timezone: "UTC", interval:, organization_id: nil, product_id: nil, billing_type: nil, customer_id: nil, metrics: nil)
  data = client.request(
    http_method: "GET",
    path: "/v1/metrics/",
    path_params: {},
    query: { "start_date" => start_date, "end_date" => end_date, "timezone" => timezone, "interval" => interval, "organization_id" => organization_id, "product_id" => product_id, "billing_type" => billing_type, "customer_id" => customer_id, "metrics" => metrics },
    response_type: :json,
    errors: { 422 => Errors::HTTPValidationError }
  )
  Models::MetricsResponse.from_json(data)
end

#get_dashboard(id) ⇒ Models::MetricDashboardSchema

Get a user-defined metric dashboard by ID.

Scopes: metrics:read

Parameters:

  • id (String)

    The metric dashboard ID.

Returns:

Raises:



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/pago/v2026_04/services/metrics.rb', line 131

def get_dashboard(id)
  data = client.request(
    http_method: "GET",
    path: "/v1/metrics/dashboards/{id}",
    path_params: { "id" => id },
    query: {},
    response_type: :json,
    errors: { 422 => Errors::HTTPValidationError }
  )
  Models::MetricDashboardSchema.from_json(data)
end

#limitsModels::MetricsLimits

Get the interval limits for the metrics endpoint.

Scopes: metrics:read

Returns:

Raises:



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/pago/v2026_04/services/metrics.rb', line 70

def limits()
  data = client.request(
    http_method: "GET",
    path: "/v1/metrics/limits",
    path_params: {},
    query: {},
    response_type: :json,
    errors: {  }
  )
  Models::MetricsLimits.from_json(data)
end

#list_dashboards(organization_id: nil) ⇒ Array<Models::MetricDashboardSchema>

List user-defined metric dashboards.

Scopes: metrics:read

Parameters:

  • organization_id (String, Array<String>, nil) (defaults to: nil)

    Filter by organization ID.

  • organization_id: (Object) (defaults to: nil)

Returns:

Raises:



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/pago/v2026_04/services/metrics.rb', line 90

def list_dashboards(organization_id: nil)
  data = client.request(
    http_method: "GET",
    path: "/v1/metrics/dashboards",
    path_params: {},
    query: { "organization_id" => organization_id },
    response_type: :json,
    errors: { 422 => Errors::HTTPValidationError }
  )
  ::Pago::Serde.array(data) { |item0| Models::MetricDashboardSchema.from_json(item0) }
end

#update_dashboard(id, body: {}) ⇒ Models::MetricDashboardSchema

Update a user-defined metric dashboard.

Scopes: metrics:write

Parameters:

  • id (String)

    The metric dashboard ID.

  • body (Hash, Models::MetricDashboardUpdate) (defaults to: {})

    the request body.

  • body: (Object) (defaults to: {})

Returns:

Raises:



171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/pago/v2026_04/services/metrics.rb', line 171

def update_dashboard(id, body: {})
  data = client.request(
    http_method: "PATCH",
    path: "/v1/metrics/dashboards/{id}",
    path_params: { "id" => id },
    query: {},
    body: body,
    response_type: :json,
    errors: { 422 => Errors::HTTPValidationError }
  )
  Models::MetricDashboardSchema.from_json(data)
end