Class: Trycourier::Resources::Lists::Subscriptions

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/resources/lists/subscriptions.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Subscriptions

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 Subscriptions.

Parameters:



145
146
147
# File 'lib/trycourier/resources/lists/subscriptions.rb', line 145

def initialize(client:)
  @client = client
end

Instance Method Details

#add(list_id, recipients: , request_options: {}) ⇒ nil

Subscribes additional users to the list, without modifying existing subscriptions. If the list does not exist, it will be automatically created.

Parameters:

Returns:

  • (nil)

See Also:



45
46
47
48
49
50
51
52
53
54
# File 'lib/trycourier/resources/lists/subscriptions.rb', line 45

def add(list_id, params)
  parsed, options = Trycourier::Lists::SubscriptionAddParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["lists/%1$s/subscriptions", list_id],
    body: parsed,
    model: NilClass,
    options: options
  )
end

#list(list_id, cursor: nil, request_options: {}) ⇒ Trycourier::Models::Lists::SubscriptionListResponse

Get the list’s subscriptions.

Parameters:

  • list_id (String)

    A unique identifier representing the list you wish to retrieve.

  • cursor (String, nil)

    A unique identifier that allows for fetching the next set of list subscriptions

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

Returns:

See Also:



20
21
22
23
24
25
26
27
28
29
# File 'lib/trycourier/resources/lists/subscriptions.rb', line 20

def list(list_id, params = {})
  parsed, options = Trycourier::Lists::SubscriptionListParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["lists/%1$s/subscriptions", list_id],
    query: parsed,
    model: Trycourier::Models::Lists::SubscriptionListResponse,
    options: options
  )
end

#subscribe(list_id, recipients: , request_options: {}) ⇒ nil

Subscribes the users to the list, overwriting existing subscriptions. If the list does not exist, it will be automatically created.

Parameters:

Returns:

  • (nil)

See Also:



70
71
72
73
74
75
76
77
78
79
# File 'lib/trycourier/resources/lists/subscriptions.rb', line 70

def subscribe(list_id, params)
  parsed, options = Trycourier::Lists::SubscriptionSubscribeParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["lists/%1$s/subscriptions", list_id],
    body: parsed,
    model: NilClass,
    options: options
  )
end

#subscribe_user(user_id, list_id: , preferences: nil, request_options: {}) ⇒ nil

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

Subscribe a user to an existing list (note: if the List does not exist, it will be automatically created).

Parameters:

  • user_id (String)

    Path param: A unique identifier representing the recipient associated with the l

  • list_id (String)

    Path param: A unique identifier representing the list you wish to retrieve.

  • preferences (Trycourier::Models::RecipientPreferences, nil)

    Body param:

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

Returns:

  • (nil)

See Also:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/trycourier/resources/lists/subscriptions.rb', line 100

def subscribe_user(user_id, params)
  parsed, options = Trycourier::Lists::SubscriptionSubscribeUserParams.dump_request(params)
  list_id =
    parsed.delete(:list_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["lists/%1$s/subscriptions/%2$s", list_id, user_id],
    body: parsed,
    model: NilClass,
    options: options
  )
end

#unsubscribe_user(user_id, list_id: , request_options: {}) ⇒ nil

Delete a subscription to a list by list ID and user ID.

Parameters:

  • user_id (String)

    A unique identifier representing the recipient associated with the list

  • list_id (String)

    A unique identifier representing the list you wish to retrieve.

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

Returns:

  • (nil)

See Also:



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/trycourier/resources/lists/subscriptions.rb', line 128

def unsubscribe_user(user_id, params)
  parsed, options = Trycourier::Lists::SubscriptionUnsubscribeUserParams.dump_request(params)
  list_id =
    parsed.delete(:list_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["lists/%1$s/subscriptions/%2$s", list_id, user_id],
    model: NilClass,
    options: options
  )
end