Class: Courier::BrandsClient
- Inherits:
-
Object
- Object
- Courier::BrandsClient
- Defined in:
- lib/trycourier/brands/client.rb
Instance Attribute Summary collapse
-
#request_client ⇒ Object
readonly
Returns the value of attribute request_client.
Instance Method Summary collapse
- #create(request:, request_options: nil) ⇒ Brands::Brand
-
#delete(brand_id:, request_options: nil) ⇒ Void
Delete a brand by brand ID.
-
#get(brand_id:, request_options: nil) ⇒ Brands::Brand
Fetch a specific brand by brand ID.
- #initialize(request_client:) ⇒ BrandsClient constructor
-
#list(cursor: nil, request_options: nil) ⇒ Brands::BrandsResponse
Get the list of brands.
-
#replace(brand_id:, name:, settings: nil, snippets: nil, request_options: nil) ⇒ Brands::Brand
Replace an existing brand with the supplied values.
Constructor Details
#initialize(request_client:) ⇒ BrandsClient
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_client ⇒ Object (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
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers["Idempotency-Key"] = .idempotency_key unless &.idempotency_key.nil? unless &.idempotency_expiry.nil? req.headers["X-Idempotency-Expiration"] = .idempotency_expiry end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.body = { **(request || {}), **(&.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.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact end end |
#get(brand_id:, request_options: nil) ⇒ Brands::Brand
Fetch a specific brand by brand ID.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.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.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.params = { **(&.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.
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..timeout = .timeout_in_seconds unless &.timeout_in_seconds.nil? unless &..nil? req.headers["Authorization"] = . end req.headers = { **req.headers, **(&.additional_headers || {}) }.compact req.body = { **(&.additional_body_parameters || {}), name: name, settings: settings, snippets: snippets }.compact end Brands::Brand.from_json(json_object: response.body) end |