Class: Pinnacle::Audiences::Client
- Inherits:
-
Object
- Object
- Pinnacle::Audiences::Client
- Defined in:
- lib/pinnacle/audiences/client.rb
Instance Method Summary collapse
- #contacts ⇒ Pinnacle::Contacts::Client
-
#create(request_options: {}, **params) ⇒ Pinnacle::Types::AudienceCountOnly
Create a new audience with optional initial contacts.
-
#delete(request_options: {}, **params) ⇒ Pinnacle::Types::DeleteAudienceResponse
Permanently delete an audience and all its contact associations.
-
#get(request_options: {}, **params) ⇒ Pinnacle::Audiences::Types::AudiencesGetResponse
Retrieve an audience by ID with optional pagination.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Pinnacle::Types::ListAudiencesResponse
List all audiences with optional filtering and pagination.
-
#update(request_options: {}, **params) ⇒ Pinnacle::Types::AudienceCountOnly
Update audience metadata.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/pinnacle/audiences/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#contacts ⇒ Pinnacle::Contacts::Client
202 203 204 |
# File 'lib/pinnacle/audiences/client.rb', line 202 def contacts @contacts ||= Pinnacle::Audiences::Contacts::Client.new(client: @client) end |
#create(request_options: {}, **params) ⇒ Pinnacle::Types::AudienceCountOnly
Create a new audience with optional initial contacts. Phone numbers that don’t exist will be auto-created as contacts.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/pinnacle/audiences/client.rb', line 67 def create(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "audiences", body: Pinnacle::Audiences::Types::CreateAudienceParams.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Types::AudienceCountOnly.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ Pinnacle::Types::DeleteAudienceResponse
Permanently delete an audience and all its contact associations.
Note: This will NOT delete the contacts themselves, only the audience and its memberships.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/pinnacle/audiences/client.rb', line 104 def delete(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["id"] = params[:id] if params.key?(:id) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "audiences", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Types::DeleteAudienceResponse.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#get(request_options: {}, **params) ⇒ Pinnacle::Audiences::Types::AudiencesGetResponse
Retrieve an audience by ID with optional pagination.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pinnacle/audiences/client.rb', line 27 def get(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["id"] = params[:id] if params.key?(:id) query_params["page"] = params[:page] if params.key?(:page) query_params["limit"] = params[:limit] if params.key?(:limit) request = Pinnacle::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 Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Audiences::Types::AudiencesGetResponse.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Pinnacle::Types::ListAudiencesResponse
List all audiences with optional filtering and pagination. Results are sorted by creation date, newest first.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/pinnacle/audiences/client.rb', line 178 def list(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "audiences/list", body: Pinnacle::Audiences::Types::ListAudiencesParams.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Types::ListAudiencesResponse.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#update(request_options: {}, **params) ⇒ Pinnacle::Types::AudienceCountOnly
Update audience metadata. This endpoint does NOT modify contacts.
To add or remove contacts, use the [Add Contacts](/api-reference/audiences/add-contacts) or [Remove Contacts](/api-reference/audiences/remove-contacts) endpoints.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/pinnacle/audiences/client.rb', line 144 def update(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) request = Pinnacle::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "audiences", body: Pinnacle::Audiences::Types::UpdateAudienceParams.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Pinnacle::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Pinnacle::Types::AudienceCountOnly.load(response.body) else error_class = Pinnacle::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |