class Iterable::Lists

Interact with /lists API endpoints

@example Creating list endpoint object

# With default config
lists = Iterable::Lists.new
lists.all

# With custom config
conf = Iterable::Config.new(token: 'new-token')
lists = Iterable::Lists.new(config)

Public Instance Methods

all() click to toggle source

Get all lists

@return [Iterable::Response] A response object

# File lib/iterable/lists.rb, line 20
def all
  Iterable.request(conf, '/lists').get
end
create(name) click to toggle source

Create a new list with a name

@param name [String] The name of the list to create

@return [Iterable::Response] A response object

# File lib/iterable/lists.rb, line 31
def create(name)
  Iterable.request(conf, '/lists').post(name: name)
end
delete(list_id) click to toggle source

Delete an existing list given a list id

@param name [String|Integer] The id of the list to delete

@return [Iterable::Response] A response object

# File lib/iterable/lists.rb, line 42
def delete(list_id)
  Iterable.request(conf, "/lists/#{list_id}").delete
end
subscribe(list_id, subscribers = []) click to toggle source

Subscribe users to a list

@param list_id [String|Integer] The id of the list @param subscribes [Array] An array of hashes of user emails and data fields

@return [Iterable::Response] A response object

# File lib/iterable/lists.rb, line 65
def subscribe(list_id, subscribers = [])
  attrs = {
    listId: list_id,
    subscribers: subscribers
  }
  Iterable.request(conf, '/lists/subscribe').post(attrs)
end
unsubscribe(list_id, subscribers = []) click to toggle source

Subscribe users to a list

@param list_id [String|Integer] The id of the list @param subscribes [Array] An array of hashes with an email

@return [Iterable::Response] A response object

# File lib/iterable/lists.rb, line 81
def unsubscribe(list_id, subscribers = [])
  attrs = {
    listId: list_id,
    subscribers: subscribers
  }
  Iterable.request(conf, '/lists/unsubscribe').post(attrs)
end
users(list_id) click to toggle source

Get users for a list

@param list_id [String|Integer] The id of the list

@return [Iterable::Response] A response object

# File lib/iterable/lists.rb, line 53
def users(list_id)
  Iterable.request(conf, '/lists/getUsers', listId: list_id).get
end