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
42
43
44
45
46
47
48
49
|
# File 'lib/blueticks/resources/audiences.rb', line 42
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
10
11
12
13
14
15
|
# File 'lib/blueticks/resources/audiences.rb', line 10
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
37
38
39
40
|
# File 'lib/blueticks/resources/audiences.rb', line 37
def delete(audience_id)
client.request("DELETE", "/v1/audiences/#{audience_id}")
nil
end
|
63
64
65
66
|
# File 'lib/blueticks/resources/audiences.rb', line 63
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
26
27
28
29
30
|
# File 'lib/blueticks/resources/audiences.rb', line 26
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.
18
19
20
21
22
23
24
|
# File 'lib/blueticks/resources/audiences.rb', line 18
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
32
33
34
35
|
# File 'lib/blueticks/resources/audiences.rb', line 32
def update(audience_id, name:)
data = client.request("PATCH", "/v1/audiences/#{audience_id}", body: { "name" => name })
Types::Audience.from_hash(data)
end
|
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/blueticks/resources/audiences.rb', line 51
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
|