Class: Whop_sdk::Accounts::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



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

def initialize(client:)
  @client = client
end

Instance Method Details

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

Creates an account. User tokens create business accounts; Account API keys create connected accounts. Tax fields (tax_remitted_by, tax_type, product_tax_code_id, business_address, tax_identifiers) are configured with Update Account, not at creation.

Examples:

client.accounts.create

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:



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/whop_sdk/accounts/client.rb', line 104

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: "accounts",
    body: Whop_sdk::Accounts::Types::CreateAccountsRequest.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::Account.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#form_company(request_options: {}, **params) ⇒ Whop_sdk::Accounts::Types::FormCompanyAccountsResponse

Starts an LLC or C-Corp formation for a business account. Defaults to an LLC; set entity_type to c_corp to form a C-Corp, which additionally requires share_structure and officer roles on every founder. On submission, the application is validated and the response returns a hosted checkout URL. Once paid, the filing is submitted. Track progress through the account's company_formation field on Retrieve Account.

Examples:

client.accounts.form_company(
  id: "id",
  business_address: {
    city: "Austin",
    country: "US",
    line1: "4180 Burnet Rd",
    line2: "Suite 2",
    postal_code: "78756",
    state: "TX"
  },
  business_name: "Shine Time Auto Detailing",
  business_phone: "+15125550142",
  business_type: "brick_and_mortar",
  business_website: "https://shinetime.example",
  entity_suffix: "LLC",
  entity_type: "llc",
  expedite_ein: true,
  formation_state: "TX",
  founders: [{
    address: {
      city: "Austin",
      country: "US",
      line1: "907 Ridgemont Dr",
      line2: "Apt 4",
      postal_code: "78704",
      state: "TX"
    },
    date_of_birth: "1988-03-14",
    email: "marcus@shinetime.example",
    first_name: "Marcus",
    is_primary: true,
    last_name: "Webb",
    ownership_percentage: 100,
    phone: "+15125550142",
    roles: ["president"],
    ssn: "123-45-6789"
  }],
  industry_group: "automotive",
  industry_type: "car_wash",
  share_structure: {
    number_of_shares: 123,
    value: 123
  },
  use_registered_agent: true
)

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)

Returns:



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
# File 'lib/whop_sdk/accounts/client.rb', line 308

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

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "accounts/#{URI.encode_uri_component(params[:id].to_s)}/form_company",
    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::Accounts::Types::FormCompanyAccountsResponse.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::Accounts::Types::ListAccountsResponse

Lists accounts visible to the credential. User tokens return the user's business accounts; Account API keys return the requesting account and its connected accounts. Pass parent_account_id to return only that parent account's connected accounts.

Examples:

client.accounts.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:



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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/whop_sdk/accounts/client.rb', line 42

def list(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  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)
  query_params["order"] = params[:order] if params.key?(:order)
  query_params["direction"] = params[:direction] if params.key?(:direction)
  query_params["status"] = params[:status] if params.key?(:status)
  query_params["query"] = params[:query] if params.key?(:query)
  query_params["created_after"] = params[:created_after] if params.key?(:created_after)
  query_params["created_before"] = params[:created_before] if params.key?(:created_before)
  query_params["volume_min"] = params[:volume_min] if params.key?(:volume_min)
  query_params["volume_max"] = params[:volume_max] if params.key?(:volume_max)
  query_params["parent_account_id"] = params[:parent_account_id] if params.key?(:parent_account_id)

  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: "accounts",
      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::Accounts::Types::ListAccountsResponse.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::Account

Retrieves the account associated with the current Account API key.

Examples:

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

Returns:



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/whop_sdk/accounts/client.rb', line 141

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

#preferencesWhop_sdk::Preferences::Client

Returns:

  • (Whop_sdk::Preferences::Client)


383
384
385
# File 'lib/whop_sdk/accounts/client.rb', line 383

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

#reservesWhop_sdk::Reserves::Client

Returns:

  • (Whop_sdk::Reserves::Client)


388
389
390
# File 'lib/whop_sdk/accounts/client.rb', line 388

def reserves
  @reserves ||= Whop_sdk::Accounts::Reserves::Client.new(client: @client)
end

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

Retrieves a single account by ID or public route when it is visible to the credential, including its crypto wallet. The reserved id me retrieves the account associated with the current Account API key; user tokens have no single account, so they must address one by ID or route.

Examples:

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

  • :id (String)

Returns:



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/whop_sdk/accounts/client.rb', line 179

def retrieve(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: "accounts/#{URI.encode_uri_component(params[: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::Types::Account.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#transfer_ownership(request_options: {}, **params) ⇒ Whop_sdk::Accounts::Types::TransferOwnershipAccountsResponse

Transfers ownership of the account to another user, identified by user ID or email address. If the recipient already holds the owner role, ownership moves immediately; otherwise they get an invite and ownership moves when they accept.

Examples:

client.accounts.transfer_ownership(
  id: "id",
  identifier: "marcus@shinetime.example"
)

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)

Returns:



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/whop_sdk/accounts/client.rb', line 355

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

  request = Whop_sdk::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "accounts/#{URI.encode_uri_component(params[:id].to_s)}/transfer_ownership",
    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::Accounts::Types::TransferOwnershipAccountsResponse.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::Account

Updates an account. User tokens can update business accounts; Account API keys can update connected accounts. The reserved id me — accepted on Retrieve Account — resolves to the requesting account, which an Account API key cannot edit, so updates must name the connected account by its biz_ id.

Examples:

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

Returns:



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

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

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