Class: Whop_sdk::EconomicIntelligence::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void



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

def initialize(client:)
  @client = client
end

Instance Method Details

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

Generates a recommendation based on your input. Returns immediately; poll the list endpoint until its status is ready.

Examples:

client.economic_intelligence.create(input: "I sell $79 customized gym straps. The number of purchases per day fell from 84 to 66 since June and my ads cost per signup doubled to $38. Half the leads never open the checkout. I want to win back churned visitors and lift conversion without cutting the price, and I can spend up to $500 this month on it.")

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:



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/whop_sdk/economic_intelligence/client.rb', line 88

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: "economic_intelligence",
    body: Whop_sdk::EconomicIntelligence::Types::CreateEconomicIntelligenceRequest.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::EconomicIntelligence.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::EconomicIntelligence::Types::ListEconomicIntelligenceResponse

Lists an account's recommendations and generation requests, newest first. Without an account, signed-out visitors receive a business-setup template and eligible users receive their saved setup recommendation.

Examples:

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



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
70
71
# File 'lib/whop_sdk/economic_intelligence/client.rb', line 34

def list(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["status"] = params[:status] if params.key?(:status)
  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: "economic_intelligence",
      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::EconomicIntelligence::Types::ListEconomicIntelligenceResponse.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

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

Approves or rejects a recommendation and requests replacements.

Examples:

client.economic_intelligence.update(
  id: "id",
  status: "executed"
)

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:



130
131
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
# File 'lib/whop_sdk/economic_intelligence/client.rb', line 130

def update(request_options: {}, **params)
  params = Whop_sdk::Internal::Types::Utils.normalize_keys(params)
  request_data = Whop_sdk::EconomicIntelligence::Types::UpdateEconomicIntelligenceRequest.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: "economic_intelligence/#{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::EconomicIntelligence.load(response.body)
  else
    error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end