Class: Courier::Resources::PreferenceSections::Topics

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/resources/preference_sections/topics.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Topics

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

Parameters:



167
168
169
# File 'lib/courier/resources/preference_sections/topics.rb', line 167

def initialize(client:)
  @client = client
end

Instance Method Details

#archive(topic_id, section_id:, request_options: {}) ⇒ nil

Archive a topic and remove it from its section. Same 404 rules as GET.

Parameters:

  • topic_id (String)

    Id of the subscription preference topic.

  • section_id (String)

    Id of the preference section.

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

Returns:

  • (nil)

See Also:



106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/courier/resources/preference_sections/topics.rb', line 106

def archive(topic_id, params)
  parsed, options = Courier::PreferenceSections::TopicArchiveParams.dump_request(params)
  section_id =
    parsed.delete(:section_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :delete,
    path: ["preferences/sections/%1$s/topics/%2$s", section_id, topic_id],
    model: NilClass,
    options: options
  )
end

#create(section_id, default_status:, name:, allowed_preferences: nil, include_unsubscribe_header: nil, routing_options: nil, topic_data: nil, request_options: {}) ⇒ Courier::Models::PreferenceTopicGetResponse

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

Create a subscription preference topic inside a section. Fails with 404 if the section does not exist. The topic id is generated and returned.

Parameters:

  • section_id (String)

    Id of the preference section to create the topic in.

  • default_status (Symbol, Courier::Models::PreferenceTopicCreateRequest::DefaultStatus)

    The default subscription status applied when a recipient has not set their own.

  • name (String)

    Human-readable name for the preference topic.

  • allowed_preferences (Array<Symbol, Courier::Models::PreferenceTopicCreateRequest::AllowedPreference>, nil)

    Preference controls a recipient may customize for this topic. Defaults to empty

  • include_unsubscribe_header (Boolean, nil)

    Whether to include a list-unsubscribe header on emails for this topic.

  • routing_options (Array<Symbol, Courier::Models::ChannelClassification>, nil)

    Default channels delivered for this topic. Defaults to empty if omitted.

  • topic_data (Hash{Symbol=>Object}, nil)

    Arbitrary metadata associated with the topic.

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

Returns:

See Also:



34
35
36
37
38
39
40
41
42
43
# File 'lib/courier/resources/preference_sections/topics.rb', line 34

def create(section_id, params)
  parsed, options = Courier::PreferenceSections::TopicCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: ["preferences/sections/%1$s/topics", section_id],
    body: parsed,
    model: Courier::PreferenceTopicGetResponse,
    options: options
  )
end

#list(section_id, request_options: {}) ⇒ Courier::Models::PreferenceTopicListResponse

List the topics in a preference section.

Parameters:

  • section_id (String)

    Id of the preference section.

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

Returns:

See Also:



84
85
86
87
88
89
90
91
# File 'lib/courier/resources/preference_sections/topics.rb', line 84

def list(section_id, params = {})
  @client.request(
    method: :get,
    path: ["preferences/sections/%1$s/topics", section_id],
    model: Courier::PreferenceTopicListResponse,
    options: params[:request_options]
  )
end

#replace(topic_id, section_id:, default_status:, name:, allowed_preferences: nil, include_unsubscribe_header: nil, routing_options: nil, topic_data: nil, request_options: {}) ⇒ Courier::Models::PreferenceTopicGetResponse

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

Replace a topic within a section. Full document replacement; missing optional fields are cleared. Same 404 rules as GET.

Parameters:

  • topic_id (String)

    Path param: Id of the subscription preference topic.

  • section_id (String)

    Path param: Id of the preference section.

  • default_status (Symbol, Courier::Models::PreferenceTopicReplaceRequest::DefaultStatus)

    Body param: The default subscription status applied when a recipient has not set

  • name (String)

    Body param: Human-readable name for the preference topic.

  • allowed_preferences (Array<Symbol, Courier::Models::PreferenceTopicReplaceRequest::AllowedPreference>, nil)

    Body param: Preference controls a recipient may customize. Omit to clear.

  • include_unsubscribe_header (Boolean, nil)

    Body param: Whether to include a list-unsubscribe header on emails for this topi

  • routing_options (Array<Symbol, Courier::Models::ChannelClassification>, nil)

    Body param: Default channels delivered for this topic. Omit to clear.

  • topic_data (Hash{Symbol=>Object}, nil)

    Body param: Arbitrary metadata associated with the topic. Omit to clear.

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

Returns:

See Also:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/courier/resources/preference_sections/topics.rb', line 149

def replace(topic_id, params)
  parsed, options = Courier::PreferenceSections::TopicReplaceParams.dump_request(params)
  section_id =
    parsed.delete(:section_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :put,
    path: ["preferences/sections/%1$s/topics/%2$s", section_id, topic_id],
    body: parsed,
    model: Courier::PreferenceTopicGetResponse,
    options: options
  )
end

#retrieve(topic_id, section_id:, request_options: {}) ⇒ Courier::Models::PreferenceTopicGetResponse

Retrieve a topic within a section. Returns 404 if the section does not exist, the topic does not exist, or the topic belongs to a different section.

Parameters:

  • topic_id (String)

    Id of the subscription preference topic.

  • section_id (String)

    Id of the preference section.

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

Returns:

See Also:



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/courier/resources/preference_sections/topics.rb', line 59

def retrieve(topic_id, params)
  parsed, options = Courier::PreferenceSections::TopicRetrieveParams.dump_request(params)
  section_id =
    parsed.delete(:section_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["preferences/sections/%1$s/topics/%2$s", section_id, topic_id],
    model: Courier::PreferenceTopicGetResponse,
    options: options
  )
end