Class: Courier::Resources::PreferenceSections

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

Defined Under Namespace

Classes: Topics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ PreferenceSections

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

Parameters:



149
150
151
152
# File 'lib/courier/resources/preference_sections.rb', line 149

def initialize(client:)
  @client = client
  @topics = Courier::Resources::PreferenceSections::Topics.new(client: client)
end

Instance Attribute Details

#topicsCourier::Resources::PreferenceSections::Topics (readonly)



7
8
9
# File 'lib/courier/resources/preference_sections.rb', line 7

def topics
  @topics
end

Instance Method Details

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

Archive a preference section. The section must be empty: delete its topics first, otherwise the request fails with 409.

Parameters:

  • section_id (String)

    Id of the preference section.

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

Returns:

  • (nil)

See Also:



88
89
90
91
92
93
94
95
# File 'lib/courier/resources/preference_sections.rb', line 88

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

#create(name:, has_custom_routing: nil, routing_options: nil, request_options: {}) ⇒ Courier::Models::PreferenceSectionGetResponse

Create a preference section in your workspace. The section id is generated and returned. Topics are created inside a section via POST /preferences/sections/section_id/topics.

Parameters:

  • name (String)

    Human-readable name for the section.

  • has_custom_routing (Boolean, nil)

    Whether the section defines custom routing for its topics.

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

    Default channels for the section. Defaults to empty if omitted.

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

Returns:

See Also:



26
27
28
29
30
31
32
33
34
35
# File 'lib/courier/resources/preference_sections.rb', line 26

def create(params)
  parsed, options = Courier::PreferenceSectionCreateParams.dump_request(params)
  @client.request(
    method: :post,
    path: "preferences/sections",
    body: parsed,
    model: Courier::PreferenceSectionGetResponse,
    options: options
  )
end

#list(request_options: {}) ⇒ Courier::Models::PreferenceSectionListResponse

List the workspace’s preference sections. Each section embeds its topics. Scoped to the workspace of the API key.

Parameters:

Returns:

See Also:



67
68
69
70
71
72
73
74
# File 'lib/courier/resources/preference_sections.rb', line 67

def list(params = {})
  @client.request(
    method: :get,
    path: "preferences/sections",
    model: Courier::PreferenceSectionListResponse,
    options: params[:request_options]
  )
end

#publish(request_options: {}) ⇒ Courier::Models::PublishPreferencesResponse

Publish the workspace’s preferences page. Takes a snapshot of every section with its topics under a new published version, making the current state visible on the hosted preferences page (non-draft).

Parameters:

Returns:

See Also:



108
109
110
111
112
113
114
115
# File 'lib/courier/resources/preference_sections.rb', line 108

def publish(params = {})
  @client.request(
    method: :post,
    path: "preferences/publish",
    model: Courier::PublishPreferencesResponse,
    options: params[:request_options]
  )
end

#replace(section_id, name:, has_custom_routing: nil, routing_options: nil, request_options: {}) ⇒ Courier::Models::PreferenceSectionGetResponse

Replace a preference section. Full document replacement; missing optional fields are cleared. Topics attached to the section are unaffected.

Parameters:

  • section_id (String)

    Id of the preference section.

  • name (String)

    Human-readable name for the section.

  • has_custom_routing (Boolean, nil)

    Whether the section defines custom routing for its topics.

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

    Default channels for the section. Omit to clear.

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

Returns:

See Also:



135
136
137
138
139
140
141
142
143
144
# File 'lib/courier/resources/preference_sections.rb', line 135

def replace(section_id, params)
  parsed, options = Courier::PreferenceSectionReplaceParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["preferences/sections/%1$s", section_id],
    body: parsed,
    model: Courier::PreferenceSectionGetResponse,
    options: options
  )
end

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

Retrieve a preference section by id, including its topics.

Parameters:

  • section_id (String)

    Id of the preference section.

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

Returns:

See Also:



48
49
50
51
52
53
54
55
# File 'lib/courier/resources/preference_sections.rb', line 48

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