Class: Blueticks::Resources::AudiencesResource
Instance Attribute Summary
Attributes inherited from BaseResource
#client
Instance Method Summary
collapse
-
#append_contacts(audience_id, contacts:) ⇒ Object
-
#create(name:, contacts: nil) ⇒ Object
-
#delete(audience_id) ⇒ Object
-
#delete_contact(audience_id, contact_id) ⇒ Object
-
#get(audience_id, page: nil) ⇒ Object
-
#list(limit: nil, cursor: nil) ⇒ Object
List audiences, newest first.
-
#update(audience_id, name:) ⇒ Object
-
#update_contact(audience_id, contact_id, to: nil, variables: nil) ⇒ Object
#initialize
Instance Method Details
43
44
45
46
47
48
49
50
|
# File 'lib/blueticks/resources/audiences.rb', line 43
def append_contacts(audience_id, contacts:)
data = client.request(
"POST",
"/v1/audiences/#{audience_id}/contacts",
body: { "contacts" => contacts }
)
Types::AppendContactsResult.from_hash(data)
end
|
#create(name:, contacts: nil) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/blueticks/resources/audiences.rb', line 11
def create(name:, contacts: nil)
body = { "name" => name }
body["contacts"] = contacts unless contacts.nil?
data = client.request("POST", "/v1/audiences", body: body)
Types::Audience.from_hash(data)
end
|
#delete(audience_id) ⇒ Object
38
39
40
41
|
# File 'lib/blueticks/resources/audiences.rb', line 38
def delete(audience_id)
data = client.request("DELETE", "/v1/audiences/#{audience_id}")
Types::DeletedResource.from_hash(data)
end
|
64
65
66
67
|
# File 'lib/blueticks/resources/audiences.rb', line 64
def delete_contact(audience_id, contact_id)
client.request("DELETE", "/v1/audiences/#{audience_id}/contacts/#{contact_id}")
nil
end
|
#get(audience_id, page: nil) ⇒ Object
27
28
29
30
31
|
# File 'lib/blueticks/resources/audiences.rb', line 27
def get(audience_id, page: nil)
params = page.nil? ? nil : { "page" => page }
data = client.request("GET", "/v1/audiences/#{audience_id}", params: params)
Types::Audience.from_hash(data)
end
|
#list(limit: nil, cursor: nil) ⇒ Object
List audiences, newest first. Cursor-paginated.
19
20
21
22
23
24
25
|
# File 'lib/blueticks/resources/audiences.rb', line 19
def list(limit: nil, cursor: nil)
params = {}
params["limit"] = limit unless limit.nil?
params["cursor"] = cursor unless cursor.nil?
data = client.request("GET", "/v1/audiences", params: params.empty? ? nil : params)
Types::Page.from_hash(data, item_type: Types::Audience)
end
|
#update(audience_id, name:) ⇒ Object
33
34
35
36
|
# File 'lib/blueticks/resources/audiences.rb', line 33
def update(audience_id, name:)
data = client.request("PATCH", "/v1/audiences/#{audience_id}", body: { "name" => name })
Types::Audience.from_hash(data)
end
|
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/blueticks/resources/audiences.rb', line 52
def update_contact(audience_id, contact_id, to: nil, variables: nil)
body = {}
body["to"] = to unless to.nil?
body["variables"] = variables unless variables.nil?
data = client.request(
"PATCH",
"/v1/audiences/#{audience_id}/contacts/#{contact_id}",
body: body
)
Types::Contact.from_hash(data)
end
|