Class: Courier::Resources::Brands

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

Overview

Manage the logos, colors, and layout that give the templates you send a consistent look.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Brands

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

Parameters:



145
146
147
# File 'lib/courier/resources/brands.rb', line 145

def initialize(client:)
  @client = client
end

Instance Method Details

#create(name:, settings:, id: nil, snippets: nil, idempotency_key: nil, x_idempotency_expiration: nil, request_options: {}) ⇒ Courier::Models::Brand

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

Creates a brand from a name and settings, including primary and secondary colors. Brands supply the logo, colors, and styling that templates render with.

Parameters:

  • name (String)

    Body param

  • settings (Courier::Models::BrandSettings)

    Body param

  • id (String, nil)

    Body param

  • snippets (Courier::Models::BrandSnippets, nil)

    Body param

  • idempotency_key (String)

    Header param: A unique key that makes this request idempotent. If Courier receiv

  • x_idempotency_expiration (String)

    Header param: How long the idempotency key remains valid, as a Unix epoch timest

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

Returns:

See Also:



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/courier/resources/brands.rb', line 33

def create(params)
  parsed, options = Courier::BrandCreateParams.dump_request(params)
  header_params =
    {idempotency_key: "idempotency-key", x_idempotency_expiration: "x-idempotency-expiration"}
  @client.request(
    method: :post,
    path: "brands",
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Courier::Brand,
    options: options
  )
end

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

Deletes a brand by id. Reassign any template or tenant that references it before deleting to keep their styling intact.

Parameters:

  • brand_id (String)

    A unique identifier associated with the brand you wish to retrieve.

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

Returns:

  • (nil)

See Also:



133
134
135
136
137
138
139
140
# File 'lib/courier/resources/brands.rb', line 133

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

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

Lists the workspace's brands. Every entry carries its name, styling settings, snippets, and published version.

Parameters:

  • cursor (String, nil)

    A unique identifier that allows for fetching the next set of brands.

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

Returns:

See Also:



109
110
111
112
113
114
115
116
117
118
119
# File 'lib/courier/resources/brands.rb', line 109

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

#retrieve(brand_id, request_options: {}) ⇒ Courier::Models::Brand

Returns one brand by id, including its colors, logo and styling settings, Handlebars snippets, and published version.

Parameters:

  • brand_id (String)

    A unique identifier associated with the brand you wish to retrieve.

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

Returns:

See Also:



59
60
61
62
63
64
65
66
# File 'lib/courier/resources/brands.rb', line 59

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

#update(brand_id, name:, settings: nil, snippets: nil, request_options: {}) ⇒ Courier::Models::Brand

Replaces a brand with the values you supply, so send the complete settings and snippets rather than only the fields you want changed.

Parameters:

Returns:

See Also:



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

def update(brand_id, params)
  parsed, options = Courier::BrandUpdateParams.dump_request(params)
  @client.request(
    method: :put,
    path: ["brands/%1$s", brand_id],
    body: parsed,
    model: Courier::Brand,
    options: options
  )
end