Class: Whop_sdk::Users::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



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

def initialize(client:)
  @client = client
end

Instance Method Details

#check_access(request_options: {}, **params) ⇒ Whop_sdk::Users::Types::CheckAccessUsersResponse

Checks whether a user has access to an account, product, or experience the caller can reach.

Examples:

client.users.check_access(
  id: "id",
  resource_id: "resource_id"
)

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

  • :id (String)
  • :resource_id (String)

Returns:



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/whop_sdk/users/client.rb', line 296

def check_access(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: "GET",
    path: "users/#{URI.encode_uri_component(params[:id].to_s)}/access/#{URI.encode_uri_component(params[:resource_id].to_s)}",
    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::Users::Types::CheckAccessUsersResponse.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::Users::Types::ListUsersResponse

Search for users by name or username, ranked by social proximity to the authenticated user. Returns the user's most recently followed users when no query is given.

Examples:

client.users.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):

  • :query (String, nil)
  • :first (Integer, nil)
  • :after (String, nil)
  • :last (Integer, nil)
  • :before (String, nil)

Returns:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/whop_sdk/users/client.rb', line 33

def list(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["query"] = params[:query] if params.key?(:query)
  query_params["first"] = params[:first] if params.key?(:first)
  query_params["after"] = params[:after] if params.key?(:after)
  query_params["last"] = params[:last] if params.key?(:last)
  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: "users",
      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::Users::Types::ListUsersResponse.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

#me(request_options: {}, **params) ⇒ Whop_sdk::Types::User

Retrieves the authenticated user — the self view of the user object. Same shape as GET /users/{id}, with the self-only fields populated: email (email-read scope), staff (Whop staff only, staff-read scope), balance and earnings_usd (balance-read scope), the opt-in balance_history, and every linked social account.

Examples:

client.users.me

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:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/whop_sdk/users/client.rb', line 93

def me(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["include_balance_history"] = params[:include_balance_history] if params.key?(:include_balance_history)
  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["time_zone"] = params[:time_zone] if params.key?(:time_zone)

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "users/me",
    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::Types::User.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#oauth_grantsWhop_sdk::OauthGrants::Client

Returns:

  • (Whop_sdk::OauthGrants::Client)


359
360
361
# File 'lib/whop_sdk/users/client.rb', line 359

def oauth_grants
  @oauth_grants ||= Whop_sdk::Users::OauthGrants::Client.new(client: @client)
end

#passkeysWhop_sdk::Passkeys::Client

Returns:

  • (Whop_sdk::Passkeys::Client)


364
365
366
# File 'lib/whop_sdk/users/client.rb', line 364

def passkeys
  @passkeys ||= Whop_sdk::Users::Passkeys::Client.new(client: @client)
end

#preferencesWhop_sdk::Preferences::Client

Returns:

  • (Whop_sdk::Preferences::Client)


369
370
371
# File 'lib/whop_sdk/users/client.rb', line 369

def preferences
  @preferences ||= Whop_sdk::Users::Preferences::Client.new(client: @client)
end

#recommend_actions(request_options: {}, **params) ⇒ Whop_sdk::Users::Types::RecommendActionsUsersResponse

Lists the recommended actions computed for the user: personal suggestions (e.g. start a business or become an affiliate) pooled with the highest-impact actions across the accounts the user owns. Business actions are tagged with their account_id/account_name; personal actions leave those null. Self-only: id must be me or the authenticated user's own tag/username.

Examples:

client.users.recommend_actions(id: "id")

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

  • :id (String)

Returns:



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/whop_sdk/users/client.rb', line 336

def recommend_actions(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: "GET",
    path: "users/#{URI.encode_uri_component(params[:id].to_s)}/recommend_actions",
    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::Users::Types::RecommendActionsUsersResponse.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::Types::User

Retrieves a user by user_ tag or username, or the authenticated user with the reserved id me. Profiles include linked social accounts — reading your own profile returns every linked account, other profiles only what is public on Whop (the primary Discord and the X account). The self-only fields are populated only when the id is me: email (email-read scope), staff (Whop staff only, staff-read scope), balance and earnings_usd (balance-read scope), and the opt-in balance_history. They are always null when addressing a user by tag or username.

Examples:

client.users.retrieve(id: "id")

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:



197
198
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
# File 'lib/whop_sdk/users/client.rb', line 197

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["include_balance_history"] = params[:include_balance_history] if params.key?(:include_balance_history)
  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["time_zone"] = params[:time_zone] if params.key?(:time_zone)

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "users/#{URI.encode_uri_component(params[:id].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::Types::User.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update(request_options: {}, **params) ⇒ Whop_sdk::Types::User

Updates a user, addressed by user_ tag, username, or the reserved id me for the authenticated user. A user token updates their own global profile; an API key updates the user's account-specific profile override (account_id required).

Examples:

client.users.update(id: "id")

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)

Options Hash (**params):

  • :id (String)
  • :account_id (String, nil)

Returns:



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/whop_sdk/users/client.rb', line 246

def update(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  request_data = Whop_sdk::Users::Types::UpdateUsersRequest.new(params).to_h
  non_body_param_names = %w[id account_id]
  body = request_data.except(*non_body_param_names)

  query_params = {}
  query_params["account_id"] = params[:account_id] if params.key?(:account_id)

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PATCH",
    path: "users/#{URI.encode_uri_component(params[:id].to_s)}",
    query: query_params,
    body: body,
    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::User.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#update_me(request_options: {}, **params) ⇒ Whop_sdk::Types::User

Updates the authenticated user's global profile, or their profile override for an account when account_id is given. Not available to API keys.

Examples:

client.users.update_me

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)

Options Hash (**params):

  • :account_id (String, nil)

Returns:



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
165
166
167
168
169
# File 'lib/whop_sdk/users/client.rb', line 140

def update_me(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  request_data = Whop_sdk::Users::Types::UpdateMeUsersRequest.new(params).to_h
  non_body_param_names = %w[account_id]
  body = request_data.except(*non_body_param_names)

  query_params = {}
  query_params["account_id"] = params[:account_id] if params.key?(:account_id)

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PATCH",
    path: "users/me",
    query: query_params,
    body: body,
    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::User.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end