Class: Leal::Posters::Client
- Inherits:
-
Object
- Object
- Leal::Posters::Client
- Defined in:
- lib/leal/posters/client.rb
Instance Method Summary collapse
-
#create(request_options: {}, **params) ⇒ Leal::Posters::Types::CreatePostersResponse
Creates a new printable QR code poster for customer signup.
-
#delete(request_options: {}, **params) ⇒ untyped
Permanently deletes a poster.
-
#get(request_options: {}, **params) ⇒ Leal::Posters::Types::GetPostersResponse
Returns a single poster by ID, including generated signup and display URLs.
- #initialize(client:) ⇒ void constructor
-
#list(request_options: {}, **params) ⇒ Array[Leal::Posters::Types::ListPostersResponseItem]
Returns all posters for the store.
-
#update(request_options: {}, **params) ⇒ Leal::Posters::Types::UpdatePostersResponse
Updates an existing poster.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/leal/posters/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#create(request_options: {}, **params) ⇒ Leal::Posters::Types::CreatePostersResponse
Creates a new printable QR code poster for customer signup. The poster will automatically
generate a unique public signup URL and QR code. The card_id is required on create to
associate the poster with a loyalty card.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/leal/posters/client.rb', line 77 def create(request_options: {}, **params) params = Leal::Internal::Types::Utils.normalize_keys(params) request_data = Leal::Posters::Types::CreatePostersRequest.new(params).to_h non_body_param_names = %w[account_id] body = request_data.except(*non_body_param_names) request = Leal::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/posters", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Leal::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Leal::Posters::Types::CreatePostersResponse.load(response.body) else error_class = Leal::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#delete(request_options: {}, **params) ⇒ untyped
Permanently deletes a poster. The public signup URL will stop working.
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/leal/posters/client.rb', line 164 def delete(request_options: {}, **params) params = Leal::Internal::Types::Utils.normalize_keys(params) request = Leal::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/posters/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Leal::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Leal::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#get(request_options: {}, **params) ⇒ Leal::Posters::Types::GetPostersResponse
Returns a single poster by ID, including generated signup and display URLs.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/leal/posters/client.rb', line 123 def get(request_options: {}, **params) params = Leal::Internal::Types::Utils.normalize_keys(params) request = Leal::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/posters/#{URI.encode_uri_component(params[:id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Leal::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Leal::Posters::Types::GetPostersResponse.load(response.body) else error_class = Leal::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#list(request_options: {}, **params) ⇒ Array[Leal::Posters::Types::ListPostersResponseItem]
Returns all posters for the store. Optionally filter by card or active status.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/leal/posters/client.rb', line 30 def list(request_options: {}, **params) params = Leal::Internal::Types::Utils.normalize_keys(params) query_params = {} query_params["card_id"] = params[:card_id] if params.key?(:card_id) query_params["active"] = params[:active] if params.key?(:active) request = Leal::Internal::JSON::Request.new( base_url: [:base_url], method: "GET", path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/posters", query: query_params, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Leal::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Leal::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |
#update(request_options: {}, **params) ⇒ Leal::Posters::Types::UpdatePostersResponse
Updates an existing poster. The card_id cannot be changed after creation.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/leal/posters/client.rb', line 204 def update(request_options: {}, **params) params = Leal::Internal::Types::Utils.normalize_keys(params) request_data = Leal::Posters::Types::UpdatePostersRequest.new(params).to_h non_body_param_names = %w[account_id id] body = request_data.except(*non_body_param_names) request = Leal::Internal::JSON::Request.new( base_url: [:base_url], method: "PATCH", path: "api/v1/accounts/#{URI.encode_uri_component(params[:account_id].to_s)}/posters/#{URI.encode_uri_component(params[:id].to_s)}", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Leal::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Leal::Posters::Types::UpdatePostersResponse.load(response.body) else error_class = Leal::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |