Class: Whop_sdk::Events::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



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

def initialize(client:)
  @client = client
end

Instance Method Details

#create(request_options: {}, **params) ⇒ Whop_sdk::Events::Types::CreateEventsResponse

Tracks a conversion or engagement event for an account.

Examples:

client.events.create(
  account_id: "biz_xxxxxxxxxxxxxx",
  event_name: "coating_deposit_paid"
)

Parameters:

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:



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/whop_sdk/events/client.rb', line 117

def create(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "events",
    body: Whop_sdk::Events::Types::CreateEventsRequest.new(params).to_h,
    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::Events::Types::CreateEventsResponse.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::Events::Types::ListEventsResponse

Lists identity-linked events, most recent first by default. Pass identifier for one person's journey, or omit it to list events for an account within an explicit time range. Pass direction=asc to read a journey forwards from where it starts. Events are shaped like the POST /events intake: attribution in context, identity in user.

Examples:

client.events.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)

Options Hash (**params):

Returns:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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/events/client.rb', line 48

def list(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["identifier"] = params[:identifier] if params.key?(:identifier)
  query_params["account_id"] = params[:account_id] if params.key?(:account_id)
  query_params["from"] = params[:from] if params.key?(:from)
  query_params["to"] = params[:to] if params.key?(:to)
  query_params["first"] = params[:first] if params.key?(:first)
  query_params["after"] = params[:after] if params.key?(:after)
  query_params["before"] = params[:before] if params.key?(:before)
  query_params["direction"] = params[:direction] if params.key?(:direction)
  query_params["event"] = params[:event] if params.key?(:event)
  query_params["source"] = params[:source] if params.key?(:source)
  query_params["attribution_model"] = params[:attribution_model] if params.key?(:attribution_model)
  query_params["country"] = params[:country] if params.key?(:country)
  query_params["city"] = params[:city] if params.key?(:city)
  query_params["device"] = params[:device] if params.key?(:device)
  query_params["browser"] = params[:browser] if params.key?(:browser)
  query_params["os"] = params[:os] if params.key?(:os)
  query_params["utm_source"] = params[:utm_source] if params.key?(:utm_source)
  query_params["hostname"] = params[:hostname] if params.key?(:hostname)
  query_params["page"] = params[:page] if params.key?(:page)

  Whop_sdk::Internal::CursorItemIterator.new(
    cursor_field: :end_cursor,
    item_field: :data,
    initial_cursor: query_params["after"]
  ) do |next_cursor|
    query_params["after"] = next_cursor
    request = Whop_sdk::Internal::JSON::Request.new(
      base_url: request_options[:base_url],
      method: "GET",
      path: "events",
      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)
      parsed_response = Whop_sdk::Events::Types::ListEventsResponse.load(response.body)
      [parsed_response, response]
    else
      error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
      raise error_class.new(response.body, code: code)
    end
  end
end

#pulse(request_options: {}, **params) ⇒ Whop_sdk::Events::Types::PulseEventsResponse

Returns a fully anonymized feed of recent platform-wide money movement, most recent first: purchases, affiliate commissions, card and ad spend, app revenue, off-platform sales, wallet deposits, card loads, claimed drops, transfers between accounts, and referral bonuses. Items carry only a type, the underlying event name, a USD amount, a coarse location under user, and a timestamp coarsened to the start of the minute; missing fields are omitted, not nulled. The payload is identical for every caller; no auth is required.

Examples:

client.events.pulse

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):

  • :event (String, nil)
  • :first (Integer, nil)
  • :after (String, nil)
  • :before (String, nil)

Returns:



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/whop_sdk/events/client.rb', line 162

def pulse(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["event"] = params[:event] if params.key?(:event)
  query_params["first"] = params[:first] if params.key?(:first)
  query_params["after"] = params[:after] if params.key?(:after)
  query_params["before"] = params[:before] if params.key?(:before)

  Whop_sdk::Internal::CursorItemIterator.new(
    cursor_field: :end_cursor,
    item_field: :data,
    initial_cursor: query_params["after"]
  ) do |next_cursor|
    query_params["after"] = next_cursor
    request = Whop_sdk::Internal::JSON::Request.new(
      base_url: request_options[:base_url],
      method: "GET",
      path: "events/pulse",
      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)
      parsed_response = Whop_sdk::Events::Types::PulseEventsResponse.load(response.body)
      [parsed_response, response]
    else
      error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
      raise error_class.new(response.body, code: code)
    end
  end
end

#validate_pixel(request_options: {}, **params) ⇒ Whop_sdk::Types::PixelValidation

Checks whether the Whop pixel is installed for an account. Recent pixel events count as proof on their own, so an account that has sent data lately comes back installed without a url. Pass a url and events from that page settle it; conversion events are also read across the hostname because they commonly fire on a later confirmation page. If the requested page hasn't sent any events lately, it is fetched and read for the pixel and conversion events wired on it. installed is only true when the pixel was actually seen — in the account's events or in the page.

Examples:

client.events.validate_pixel

Parameters:

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:



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/whop_sdk/events/client.rb', line 218

def validate_pixel(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "events/validate_pixel",
    body: Whop_sdk::Events::Types::ValidatePixelEventsRequest.new(params).to_h,
    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::Types::PixelValidation.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end