Class: Whop_sdk::Audiences::Client
- Inherits:
-
Object
- Object
- Whop_sdk::Audiences::Client
- Defined in:
- lib/whop_sdk/audiences/client.rb
Instance Method Summary collapse
-
#add_people(request_options: {}, **params) ⇒ Whop_sdk::Types::Audience
Adds users from a new CSV file to an existing uploaded custom audience.
-
#create(request_options: {}, **params) ⇒ Whop_sdk::Audiences::Types::CreateAudiencesResponse
Creates an audience.
-
#delete(request_options: {}, **params) ⇒ Whop_sdk::Audiences::Types::DeleteAudiencesResponse
Deletes an audience so it is no longer available for targeting.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Whop_sdk::Audiences::Types::ListAudiencesResponse
Lists uploaded customer-list audiences for an account.
-
#update(request_options: {}, **params) ⇒ Whop_sdk::Types::Audience
Renames an audience.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/whop_sdk/audiences/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#add_people(request_options: {}, **params) ⇒ Whop_sdk::Types::Audience
Adds users from a new CSV file to an existing uploaded custom audience. The file uses the audience's saved column mapping, processing happens in the background, and existing audience members remain unchanged.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/whop_sdk/audiences/client.rb', line 216 def add_people(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::Audiences::Types::AddPeopleAudiencesRequest.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: [:base_url], method: "POST", path: "audiences/#{URI.encode_uri_component(params[:id].to_s)}/add_people", body: body, 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::Audience.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#create(request_options: {}, **params) ⇒ Whop_sdk::Audiences::Types::CreateAudiencesResponse
Creates an audience. Default (audience_type omitted or custom): creates one audience from an uploaded
customer identity CSV file (name, column_mapping, and file_id required) and starts processing it; responds
with the audience object. With filters: creates an audience from saved People filters (name required) —
membership is built from the account's People data, and auto_refresh decides whether it keeps tracking the
filters or keeps whoever matched at creation. With audience_type: lookalike: creates a ladder of Meta
lookalike audiences from an existing ready custom audience (source_audience_id, count, and percentage
required) — count equal similarity bands slicing the top percentage% (3 audiences at 6% = 0–2%, 2–4%, 4–6%),
each returned as its own audience in a { data: [...] } envelope.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/whop_sdk/audiences/client.rb', line 93 def create(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "audiences", body: Whop_sdk::Audiences::Types::CreateAudiencesRequest.new(params).to_h, 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::Audiences::Types::CreateAudiencesResponse.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Whop_sdk::Audiences::Types::DeleteAudiencesResponse
Deletes an audience so it is no longer available for targeting.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/whop_sdk/audiences/client.rb', line 131 def delete(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request = Whop_sdk::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "audiences/#{URI.encode_uri_component(params[:id].to_s)}", 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::Audiences::Types::DeleteAudiencesResponse.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::Audiences::Types::ListAudiencesResponse
Lists uploaded customer-list audiences for an account. Pass audience_id to return a specific audience.
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 70 |
# File 'lib/whop_sdk/audiences/client.rb', line 33 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["audience_id"] = params[:audience_id] if params.key?(:audience_id) query_params["audience_type"] = params[:audience_type] if params.key?(:audience_type) query_params["source_type"] = params[:source_type] if params.key?(:source_type) query_params["first"] = params[:first] if params.key?(:first) query_params["after"] = params[:after] if params.key?(:after) 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: [:base_url], method: "GET", path: "audiences", query: query_params, 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::Audiences::Types::ListAudiencesResponse.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::Audience
Renames an audience. For an audience built from People filters that keeps itself up to date, pass filters to
replace them, which rebuilds membership immediately. Whether an audience auto refreshes is set when it is
created.
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 |
# File 'lib/whop_sdk/audiences/client.rb', line 170 def update(request_options: {}, **params) params = Whop_sdk::Internal::Types::Utils.normalize_keys(params) request_data = Whop_sdk::Audiences::Types::UpdateAudiencesRequest.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: [:base_url], method: "PATCH", path: "audiences/#{URI.encode_uri_component(params[:id].to_s)}", body: body, 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::Audience.load(response.body) else error_class = Whop_sdk::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |