Class: Courier::Resources::Lists

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/lists.rb,
lib/courier/resources/lists/subscriptions.rb,
sig/courier/resources/lists.rbs,
sig/courier/resources/lists/subscriptions.rbs

Overview

Manage static groups of users that you subscribe explicitly, and send to them by list id or list pattern.

Defined Under Namespace

Classes: Subscriptions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Lists

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Lists.

Parameters:



135
136
137
138
# File 'lib/courier/resources/lists.rb', line 135

def initialize(client:)
  @client = client
  @subscriptions = Courier::Resources::Lists::Subscriptions.new(client: client)
end

Instance Attribute Details

#subscriptionsCourier::Resources::Lists::Subscriptions (readonly)

Manage static groups of users that you subscribe explicitly, and send to them by list id or list pattern.



11
12
13
# File 'lib/courier/resources/lists.rb', line 11

def subscriptions
  @subscriptions
end

Instance Method Details

#delete(list_id, request_options: {}) ⇒ nil

Deletes a list, halting sends that target it. A previously deleted list can be brought back with the companion restore endpoint.

Parameters:

  • list_id (String)

    A unique identifier representing the list you wish to retrieve.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



102
103
104
105
106
107
108
109
# File 'lib/courier/resources/lists.rb', line 102

def delete(list_id, params = {})
  @client.request(
    method: :delete,
    path: ["lists/%1$s", list_id],
    model: NilClass,
    options: params[:request_options]
  )
end

#list(cursor: nil, pattern: nil, request_options: {}) ⇒ Courier::Models::ListListResponse

Some parameter documentations has been truncated, see Models::ListListParams for more details.

Returns the workspace's lists, filterable by a pattern to fetch a subset such as every regional list. Paged by cursor.

Parameters:

  • cursor (String, nil)

    A unique identifier that allows for fetching the next page of lists.

  • pattern (String, nil)

    "A pattern used to filter the list items returned. Pattern types supported: exac

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/courier/resources/lists.rb', line 78

def list(params = {})
  parsed, options = Courier::ListListParams.dump_request(params)
  query = Courier::Internal::Util.encode_query_params(parsed)
  @client.request(
    method: :get,
    path: "lists",
    query: query,
    model: Courier::Models::ListListResponse,
    options: options
  )
end

#restore(list_id, request_options: {}) ⇒ nil

Restores a previously deleted list along with its subscribers, so a list removed by mistake can be brought back rather than rebuilt.

Parameters:

  • list_id (String)

    A unique identifier representing the list you wish to retrieve.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



123
124
125
126
127
128
129
130
# File 'lib/courier/resources/lists.rb', line 123

def restore(list_id, params = {})
  @client.request(
    method: :put,
    path: ["lists/%1$s/restore", list_id],
    model: NilClass,
    options: params[:request_options]
  )
end

#retrieve(list_id, request_options: {}) ⇒ Courier::Models::SubscriptionList

Returns one list by id with its name and created and updated timestamps. Fetch its subscribers separately with the subscriptions endpoint.

Parameters:

  • list_id (String)

    A unique identifier representing the list you wish to retrieve.

  • request_options (Courier::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



25
26
27
28
29
30
31
32
# File 'lib/courier/resources/lists.rb', line 25

def retrieve(list_id, params = {})
  @client.request(
    method: :get,
    path: ["lists/%1$s", list_id],
    model: Courier::SubscriptionList,
    options: params[:request_options]
  )
end

#update(list_id, name:, preferences: nil, request_options: {}) ⇒ nil

Creates or replaces a list from a name and preferences. Subscribers are managed through the separate subscriptions endpoints.

Parameters:

Returns:

  • (nil)

See Also:



50
51
52
53
54
55
56
57
58
59
# File 'lib/courier/resources/lists.rb', line 50

def update(list_id, params)
  parsed, options = Courier::ListUpdateParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["lists/%1$s", list_id],
    body: parsed,
    model: NilClass,
    options: options
  )
end