Class: Courier::BrandsClient

Inherits:
Object
  • Object
show all
Defined in:
lib/trycourier/brands/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_client:) ⇒ BrandsClient

Parameters:



17
18
19
20
# File 'lib/trycourier/brands/client.rb', line 17

def initialize(request_client:)
  # @type [RequestClient]
  @request_client = request_client
end

Instance Attribute Details

#request_clientObject (readonly)

Returns the value of attribute request_client.



13
14
15
# File 'lib/trycourier/brands/client.rb', line 13

def request_client
  @request_client
end

Instance Method Details

#create(request:, request_options: nil) ⇒ Brands::Brand

Parameters:

  • request (Hash)

    Request of type Brands::BrandParameters, as a Hash

    • :id (String)

    • :name (String)

    • :settings (Hash)

      • :colors (Hash)

        • :primary (String)

        • :secondary (String)

        • :tertiary (String)

      • :inapp (Object)

      • :email (Hash)

        • :footer (Object)

        • :header (Object)

    • :snippets (Hash)

      • :items (Array<Brands::BrandSnippet>)

  • request_options (IdempotencyRequestOptions) (defaults to: nil)

Returns:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/trycourier/brands/client.rb', line 38

def create(request:, request_options: nil)
  response = @request_client.conn.post("/brands") do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    unless request_options&.authorization_token.nil?
      req.headers["Authorization"] =
        request_options.authorization_token
    end
    req.headers["Idempotency-Key"] = request_options.idempotency_key unless request_options&.idempotency_key.nil?
    unless request_options&.idempotency_expiry.nil?
      req.headers["X-Idempotency-Expiration"] = request_options.idempotency_expiry
    end
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = { **(request || {}), **(request_options&.additional_body_parameters || {}) }.compact
  end
  Brands::Brand.from_json(json_object: response.body)
end

#delete(brand_id:, request_options: nil) ⇒ Void

Delete a brand by brand ID.

Parameters:

  • brand_id (String)

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

  • request_options (RequestOptions) (defaults to: nil)

Returns:

  • (Void)


95
96
97
98
99
100
101
102
103
104
# File 'lib/trycourier/brands/client.rb', line 95

def delete(brand_id:, request_options: nil)
  @request_client.conn.delete("/brands/#{brand_id}") do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    unless request_options&.authorization_token.nil?
      req.headers["Authorization"] =
        request_options.authorization_token
    end
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
  end
end

#get(brand_id:, request_options: nil) ⇒ Brands::Brand

Fetch a specific brand by brand ID.

Parameters:

  • brand_id (String)

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

  • request_options (RequestOptions) (defaults to: nil)

Returns:



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/trycourier/brands/client.rb', line 60

def get(brand_id:, request_options: nil)
  response = @request_client.conn.get("/brands/#{brand_id}") do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    unless request_options&.authorization_token.nil?
      req.headers["Authorization"] =
        request_options.authorization_token
    end
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
  end
  Brands::Brand.from_json(json_object: response.body)
end

#list(cursor: nil, request_options: nil) ⇒ Brands::BrandsResponse

Get the list of brands.

Parameters:

  • cursor (String) (defaults to: nil)

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

  • request_options (RequestOptions) (defaults to: nil)

Returns:



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/trycourier/brands/client.rb', line 77

def list(cursor: nil, request_options: nil)
  response = @request_client.conn.get("/brands") do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    unless request_options&.authorization_token.nil?
      req.headers["Authorization"] =
        request_options.authorization_token
    end
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.params = { **(request_options&.additional_query_parameters || {}), "cursor": cursor }.compact
  end
  Brands::BrandsResponse.from_json(json_object: response.body)
end

#replace(brand_id:, name:, settings: nil, snippets: nil, request_options: nil) ⇒ Brands::Brand

Replace an existing brand with the supplied values.

Parameters:

  • brand_id (String)

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

  • name (String)

    The name of the brand.

  • settings (Hash) (defaults to: nil)

    Request of type Brands::BrandSettings, as a Hash

    • :colors (Hash)

      • :primary (String)

      • :secondary (String)

      • :tertiary (String)

    • :inapp (Object)

    • :email (Hash)

      • :footer (Object)

      • :header (Object)

  • snippets (Hash) (defaults to: nil)

    Request of type Brands::BrandSnippets, as a Hash

    • :items (Array<Brands::BrandSnippet>)

  • request_options (RequestOptions) (defaults to: nil)

Returns:



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/trycourier/brands/client.rb', line 123

def replace(brand_id:, name:, settings: nil, snippets: nil, request_options: nil)
  response = @request_client.conn.put("/brands/#{brand_id}") do |req|
    req.options.timeout = request_options.timeout_in_seconds unless request_options&.timeout_in_seconds.nil?
    unless request_options&.authorization_token.nil?
      req.headers["Authorization"] =
        request_options.authorization_token
    end
    req.headers = { **req.headers, **(request_options&.additional_headers || {}) }.compact
    req.body = {
      **(request_options&.additional_body_parameters || {}),
      name: name,
      settings: settings,
      snippets: snippets
    }.compact
  end
  Brands::Brand.from_json(json_object: response.body)
end