Class: Iterable::Lists

Inherits:
ApiResource show all
Defined in:
lib/iterable/lists.rb

Overview

Interact with /lists API endpoints

Examples:

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)

Instance Attribute Summary

Attributes inherited from ApiResource

#conf

Instance Method Summary collapse

Methods inherited from ApiResource

#default_config, default_config, #initialize

Constructor Details

This class inherits a constructor from Iterable::ApiResource

Instance Method Details

#allIterable::Response

Get all lists

Returns:



20
21
22
# File 'lib/iterable/lists.rb', line 20

def all
  Iterable.request(conf, '/lists').get
end

#create(name) ⇒ Iterable::Response

Create a new list with a name

Parameters:

  • name (String)

    The name of the list to create

Returns:



31
32
33
# File 'lib/iterable/lists.rb', line 31

def create(name)
  Iterable.request(conf, '/lists').post(name: name)
end

#delete(list_id) ⇒ Iterable::Response

Delete an existing list given a list id

Parameters:

  • name (String|Integer)

    The id of the list to delete

Returns:



42
43
44
# File 'lib/iterable/lists.rb', line 42

def delete(list_id)
  Iterable.request(conf, "/lists/#{list_id}").delete
end

#subscribe(list_id, subscribers = []) ⇒ Iterable::Response

Subscribe users to a list

Parameters:

  • list_id (String|Integer)

    The id of the list

  • subscribes (Array[Hash])

    An array of hashes of user emails and data fields

Returns:



65
66
67
68
69
70
71
# 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 = []) ⇒ Iterable::Response

Subscribe users to a list

Parameters:

  • list_id (String|Integer)

    The id of the list

  • subscribes (Array[Hash])

    An array of hashes with an email

Returns:



81
82
83
84
85
86
87
# 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) ⇒ Iterable::Response

Get users for a list

Parameters:

  • list_id (String|Integer)

    The id of the list

Returns:



53
54
55
# File 'lib/iterable/lists.rb', line 53

def users(list_id)
  Iterable.request(conf, '/lists/getUsers', listId: list_id).get
end