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
Create an audience from a customer list, your account's Whop People data, or engagement with videos, lead forms, Instagram profiles, or Facebook pages.
-
#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
List custom and lookalike 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.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/whop_sdk/audiences/client.rb', line 220 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
Create an audience from a customer list, your account's Whop People data, or engagement with videos, lead forms,
Instagram profiles, or Facebook pages. Create lookalike audiences to reach people similar to an existing
audience. Processing runs asynchronously. Custom creation returns one audience; lookalike creation returns the
requested similarity bands in data.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/whop_sdk/audiences/client.rb', line 97 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.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/whop_sdk/audiences/client.rb', line 135 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
List custom and lookalike 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.
174 175 176 177 178 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/audiences/client.rb', line 174 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 |