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
-
#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
172 173 174 |
# File 'lib/pinnacle/audiences/client.rb', line 172 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.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/pinnacle/audiences/client.rb', line 69 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.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/pinnacle/audiences/client.rb', line 106 def delete(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[id] query_params = {} query_params["id"] = params[:id] if params.key?(:id) params.except(*query_param_names) 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 54 55 |
# File 'lib/pinnacle/audiences/client.rb', line 27 def get(request_options: {}, **params) params = Pinnacle::Internal::Types::Utils.normalize_keys(params) query_param_names = %i[id page limit] 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) params.except(*query_param_names) 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 |
#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.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/pinnacle/audiences/client.rb', line 148 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 |