Class: Whop_sdk::Stats::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/whop_sdk/stats/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



9
10
11
# File 'lib/whop_sdk/stats/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#describe_stats(request_options: {}, **params) ⇒ Whop_sdk::Stats::Types::DescribeStatsResponse

Describe available stats schema. Without resource returns root nodes and metrics. With resource returns node columns, associations, and available metrics.

Required permissions:

  • stats:read

Examples:

client.stats.describe_stats(
  company_id: "biz_xxxxxxxxxxxxxx",
  user_id: "user_xxxxxxxxxxxxx"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :resource (String, nil)
  • :company_id (String, nil)
  • :user_id (String, nil)

Returns:



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/whop_sdk/stats/client.rb', line 72

def describe_stats(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["resource"] = params[:resource] if params.key?(:resource)
  query_params["company_id"] = params[:company_id] if params.key?(:company_id)
  query_params["user_id"] = params[:user_id] if params.key?(:user_id)

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "stats/describe",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Whop_sdk::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Whop_sdk::Stats::Types::DescribeStatsResponse.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list(request_options: {}, **_params) ⇒ Whop_sdk::Stats::Types::ListStatsResponse

Lists every metric you can query, with its unit and the properties you can filter or break it down by.

Examples:

client.stats.list

Parameters:

  • request_options (Hash) (defaults to: {})
  • _params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/whop_sdk/stats/client.rb', line 27

def list(request_options: {}, **_params)
  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "stats",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Whop_sdk::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Whop_sdk::Stats::Types::ListStatsResponse.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#metric_stats(request_options: {}, **params) ⇒ Whop_sdk::Stats::Types::MetricStatsResponse

Query an aggregated metric. Returns data grouped by period with optional breakdowns.

Required permissions:

  • stats:read

Examples:

client.stats.metric_stats(
  resource: "resource",
  from: "2023-12-01T05:00:00Z",
  to: "2023-12-01T05:00:00Z",
  company_id: "biz_xxxxxxxxxxxxxx",
  user_id: "user_xxxxxxxxxxxxx"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :resource (String)
  • :granularity (String, nil)
  • :breakdowns (String, nil)
  • :filters (Hash[String, Object], nil)
  • :time_zone (String, nil)
  • :from (String, nil)
  • :to (String, nil)
  • :company_id (String, nil)
  • :user_id (String, nil)

Returns:



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/whop_sdk/stats/client.rb', line 132

def metric_stats(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["resource"] = params[:resource] if params.key?(:resource)
  query_params["granularity"] = params[:granularity] if params.key?(:granularity)
  query_params["breakdowns"] = params[:breakdowns] if params.key?(:breakdowns)
  query_params["filters"] = params[:filters] if params.key?(:filters)
  query_params["time_zone"] = params[:time_zone] if params.key?(:time_zone)
  query_params["from"] = params[:from] if params.key?(:from)
  query_params["to"] = params[:to] if params.key?(:to)
  query_params["company_id"] = params[:company_id] if params.key?(:company_id)
  query_params["user_id"] = params[:user_id] if params.key?(:user_id)

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "stats/metric",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Whop_sdk::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Whop_sdk::Stats::Types::MetricStatsResponse.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#raw_stats(request_options: {}, **params) ⇒ Whop_sdk::Stats::Types::RawStatsResponse

Query raw data from a resource. Returns paginated rows with all columns.

Required permissions:

  • stats:read

Examples:

client.stats.raw_stats(
  resource: "resource",
  from: "2023-12-01T05:00:00Z",
  to: "2023-12-01T05:00:00Z",
  limit: 42,
  company_id: "biz_xxxxxxxxxxxxxx",
  user_id: "user_xxxxxxxxxxxxx"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :resource (String)
  • :from (String, nil)
  • :to (String, nil)
  • :limit (Integer, nil)
  • :cursor (String, nil)
  • :sort (String, nil)
  • :sort_direction (Whop_sdk::Types::Direction, nil)
  • :company_id (String, nil)
  • :user_id (String, nil)

Returns:



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/whop_sdk/stats/client.rb', line 199

def raw_stats(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["resource"] = params[:resource] if params.key?(:resource)
  query_params["from"] = params[:from] if params.key?(:from)
  query_params["to"] = params[:to] if params.key?(:to)
  query_params["limit"] = params[:limit] if params.key?(:limit)
  query_params["cursor"] = params[:cursor] if params.key?(:cursor)
  query_params["sort"] = params[:sort] if params.key?(:sort)
  query_params["sort_direction"] = params[:sort_direction] if params.key?(:sort_direction)
  query_params["company_id"] = params[:company_id] if params.key?(:company_id)
  query_params["user_id"] = params[:user_id] if params.key?(:user_id)

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "stats/raw",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Whop_sdk::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Whop_sdk::Stats::Types::RawStatsResponse.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#retrieve(request_options: {}, **params) ⇒ Whop_sdk::Stats::Types::RetrieveStatsResponse

Retrieves a metric as a time series of points for an account or user over a time range. The market_prices metric is public and requires no authentication.

Examples:

client.stats.retrieve(
  metric: "metric",
  from: "from",
  to: "to",
  ad_campaign_ids: ["adcamp_xxxxxxxxxxxxxx"],
  ad_group_ids: ["adgrp_xxxxxxxxxxxxxx"],
  ad_ids: ["ad_xxxxxxxxxxxxxx"]
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :metric (String)
  • :account_id (String, nil)
  • :user_id (String, nil)
  • :from (String)
  • :to (String)
  • :interval (Whop_sdk::Stats::Types::RetrieveStatsRequestInterval, nil)
  • :breakdown_by (String, nil)
  • :convert_to (String, nil)
  • :currency (String, nil)
  • :time_zone (String, nil)
  • :payment_method (String, nil)
  • :card_network (String, nil)
  • :dispute_reason (String, nil)
  • :source (String, nil)
  • :hostname (String, nil)
  • :page (String, nil)
  • :device_type (String, nil)
  • :country_code (String, nil)
  • :event_name (String, nil)
  • :event_type (Whop_sdk::Stats::Types::RetrieveStatsRequestEventType, nil)
  • :custom_name (String, nil)
  • :segment (String, nil)
  • :category (String, nil)
  • :merchant (String, nil)
  • :fee_type (String, nil)
  • :product (String, nil)
  • :status (String, nil)
  • :access_level (String, nil)
  • :most_recent_action (String, nil)
  • :referred_user_id (String, nil)
  • :ad_campaign_ids (String, nil)
  • :ad_group_ids (String, nil)
  • :ad_ids (String, nil)
  • :snapshot_window (Whop_sdk::Stats::Types::RetrieveStatsRequestSnapshotWindow, nil)
  • :event (String, nil)

Returns:



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/whop_sdk/stats/client.rb', line 290

def retrieve(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["account_id"] = params[:account_id] if params.key?(:account_id)
  query_params["user_id"] = params[:user_id] if params.key?(:user_id)
  query_params["from"] = params[:from] if params.key?(:from)
  query_params["to"] = params[:to] if params.key?(:to)
  query_params["interval"] = params[:interval] if params.key?(:interval)
  query_params["breakdown_by"] = params[:breakdown_by] if params.key?(:breakdown_by)
  query_params["convert_to"] = params[:convert_to] if params.key?(:convert_to)
  query_params["currency"] = params[:currency] if params.key?(:currency)
  query_params["time_zone"] = params[:time_zone] if params.key?(:time_zone)
  query_params["payment_method"] = params[:payment_method] if params.key?(:payment_method)
  query_params["card_network"] = params[:card_network] if params.key?(:card_network)
  query_params["dispute_reason"] = params[:dispute_reason] if params.key?(:dispute_reason)
  query_params["source"] = params[:source] if params.key?(:source)
  query_params["hostname"] = params[:hostname] if params.key?(:hostname)
  query_params["page"] = params[:page] if params.key?(:page)
  query_params["device_type"] = params[:device_type] if params.key?(:device_type)
  query_params["country_code"] = params[:country_code] if params.key?(:country_code)
  query_params["event_name"] = params[:event_name] if params.key?(:event_name)
  query_params["event_type"] = params[:event_type] if params.key?(:event_type)
  query_params["custom_name"] = params[:custom_name] if params.key?(:custom_name)
  query_params["segment"] = params[:segment] if params.key?(:segment)
  query_params["category"] = params[:category] if params.key?(:category)
  query_params["merchant"] = params[:merchant] if params.key?(:merchant)
  query_params["fee_type"] = params[:fee_type] if params.key?(:fee_type)
  query_params["product"] = params[:product] if params.key?(:product)
  query_params["status"] = params[:status] if params.key?(:status)
  query_params["access_level"] = params[:access_level] if params.key?(:access_level)
  query_params["most_recent_action"] = params[:most_recent_action] if params.key?(:most_recent_action)
  query_params["referred_user_id"] = params[:referred_user_id] if params.key?(:referred_user_id)
  query_params["ad_campaign_ids"] = params[:ad_campaign_ids] if params.key?(:ad_campaign_ids)
  query_params["ad_group_ids"] = params[:ad_group_ids] if params.key?(:ad_group_ids)
  query_params["ad_ids"] = params[:ad_ids] if params.key?(:ad_ids)
  query_params["snapshot_window"] = params[:snapshot_window] if params.key?(:snapshot_window)
  query_params["event"] = params[:event] if params.key?(:event)

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "stats/#{URI.encode_uri_component(params[:metric].to_s)}",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Whop_sdk::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Whop_sdk::Stats::Types::RetrieveStatsResponse.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end