Class: Sendly::ContactListsResource

Inherits:
Object
  • Object
show all
Defined in:
lib/sendly/contacts_resource.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ContactListsResource

Returns a new instance of ContactListsResource.



102
103
104
# File 'lib/sendly/contacts_resource.rb', line 102

def initialize(client)
  @client = client
end

Instance Method Details

#add_contacts(list_id, contact_ids) ⇒ Object



142
143
144
145
# File 'lib/sendly/contacts_resource.rb', line 142

def add_contacts(list_id, contact_ids)
  response = @client.post("/contact-lists/#{list_id}/contacts", { contact_ids: contact_ids })
  { added_count: response["added_count"] || response["addedCount"] }
end

#create(name:, description: nil) ⇒ Object



121
122
123
124
125
126
127
# File 'lib/sendly/contacts_resource.rb', line 121

def create(name:, description: nil)
  body = { name: name }
  body[:description] = description if description

  response = @client.post("/contact-lists", body)
  ContactList.new(response)
end

#delete(id) ⇒ Object



138
139
140
# File 'lib/sendly/contacts_resource.rb', line 138

def delete(id)
  @client.delete("/contact-lists/#{id}")
end

#get(id, limit: nil, offset: nil) ⇒ Object



112
113
114
115
116
117
118
119
# File 'lib/sendly/contacts_resource.rb', line 112

def get(id, limit: nil, offset: nil)
  params = {}
  params[:limit] = limit if limit
  params[:offset] = offset if offset

  response = @client.get("/contact-lists/#{id}", params)
  ContactList.new(response)
end

#listObject



106
107
108
109
110
# File 'lib/sendly/contacts_resource.rb', line 106

def list
  response = @client.get("/contact-lists")
  lists = (response["lists"] || []).map { |l| ContactList.new(l) }
  { lists: lists }
end

#remove_contact(list_id, contact_id) ⇒ Object



147
148
149
# File 'lib/sendly/contacts_resource.rb', line 147

def remove_contact(list_id, contact_id)
  @client.delete("/contact-lists/#{list_id}/contacts/#{contact_id}")
end

#update(id, name: nil, description: nil) ⇒ Object



129
130
131
132
133
134
135
136
# File 'lib/sendly/contacts_resource.rb', line 129

def update(id, name: nil, description: nil)
  body = {}
  body[:name] = name if name
  body[:description] = description unless description.nil?

  response = @client.patch("/contact-lists/#{id}", body)
  ContactList.new(response)
end