Class: Blueticks::Resources::AudiencesResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Blueticks::Resources::AudiencesResource
- Defined in:
- lib/blueticks/resources/audiences.rb
Instance Attribute Summary
Attributes inherited from BaseResource
Instance Method Summary collapse
-
#append_contacts(audience_id, contacts:) ⇒ Object
Append contacts to an audience.
-
#create(name:, contacts: nil) ⇒ Object
Create an audience, optionally seeding it with contacts.
-
#delete(audience_id) ⇒ Object
Delete an audience.
-
#delete_contact(audience_id, contact_id) ⇒ Object
Remove a contact from an audience.
-
#list(order: nil, skip: nil, limit: nil) ⇒ Object
List audiences, newest first.
-
#retrieve(audience_id) ⇒ Object
Retrieve an audience by id.
-
#update(audience_id, name:) ⇒ Object
Rename an audience.
-
#update_contact(audience_id, contact_id, to: nil, variables: nil) ⇒ Object
Update a single contact's recipient and/or merge-field variables.
Methods inherited from BaseResource
Constructor Details
This class inherits a constructor from Blueticks::BaseResource
Instance Method Details
#append_contacts(audience_id, contacts:) ⇒ Object
Append contacts to an audience.
49 50 51 52 53 54 55 56 |
# File 'lib/blueticks/resources/audiences.rb', line 49 def append_contacts(audience_id, contacts:) env = client.request( "POST", "/v1/audiences/#{audience_id}/contacts", body: { "contacts" => contacts } ) Types::AppendContactsResult.from_hash(env && env["data"]) end |
#create(name:, contacts: nil) ⇒ Object
Create an audience, optionally seeding it with contacts.
contacts is an Array of { "to" => ..., "variables" => {...} } hashes.
13 14 15 16 17 18 |
# File 'lib/blueticks/resources/audiences.rb', line 13 def create(name:, contacts: nil) body = { "name" => name } body["contacts"] = contacts unless contacts.nil? env = client.request("POST", "/v1/audiences", body: body) Types::Audience.from_hash(env && env["data"]) end |
#delete(audience_id) ⇒ Object
Delete an audience.
43 44 45 46 |
# File 'lib/blueticks/resources/audiences.rb', line 43 def delete(audience_id) env = client.request("DELETE", "/v1/audiences/#{audience_id}") Types::DeletedResource.from_hash(env && env["data"]) end |
#delete_contact(audience_id, contact_id) ⇒ Object
Remove a contact from an audience.
72 73 74 75 |
# File 'lib/blueticks/resources/audiences.rb', line 72 def delete_contact(audience_id, contact_id) env = client.request("DELETE", "/v1/audiences/#{audience_id}/contacts/#{contact_id}") Types::ContactRemoval.from_hash(env && env["data"]) end |
#list(order: nil, skip: nil, limit: nil) ⇒ Object
List audiences, newest first. Offset-paginated.
21 22 23 24 25 26 27 28 |
# File 'lib/blueticks/resources/audiences.rb', line 21 def list(order: nil, skip: nil, limit: nil) params = {} params["order"] = order unless order.nil? params["skip"] = skip unless skip.nil? params["limit"] = limit unless limit.nil? env = client.request("GET", "/v1/audiences", params: params.empty? ? nil : params) Types::PaginatedPage.from_hash(env, item_type: Types::Audience) end |
#retrieve(audience_id) ⇒ Object
Retrieve an audience by id.
31 32 33 34 |
# File 'lib/blueticks/resources/audiences.rb', line 31 def retrieve(audience_id) env = client.request("GET", "/v1/audiences/#{audience_id}") Types::Audience.from_hash(env && env["data"]) end |
#update(audience_id, name:) ⇒ Object
Rename an audience.
37 38 39 40 |
# File 'lib/blueticks/resources/audiences.rb', line 37 def update(audience_id, name:) env = client.request("PATCH", "/v1/audiences/#{audience_id}", body: { "name" => name }) Types::Audience.from_hash(env && env["data"]) end |
#update_contact(audience_id, contact_id, to: nil, variables: nil) ⇒ Object
Update a single contact's recipient and/or merge-field variables.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/blueticks/resources/audiences.rb', line 59 def update_contact(audience_id, contact_id, to: nil, variables: nil) body = {} body["to"] = to unless to.nil? body["variables"] = variables unless variables.nil? env = client.request( "PATCH", "/v1/audiences/#{audience_id}/contacts/#{contact_id}", body: body ) Types::AudienceContact.from_hash(env && env["data"]) end |