Class: Apologist::CtAs::Client
- Inherits:
-
Object
- Object
- Apologist::CtAs::Client
- Defined in:
- lib/Apologist/ct_as/client.rb
Instance Method Summary collapse
- #initialize(client:) ⇒ void constructor
-
#log_cta_click(request_options: {}, **params) ⇒ Apologist::Types::SuccessResponse
Records that a user clicked on a specific CTA.
-
#match_ctas(request_options: {}, **params) ⇒ Apologist::CtAs::Types::MatchCtasResponse
Finds matching CTAs based on conversation context, user, session, device, or messages.
Constructor Details
#initialize(client:) ⇒ void
9 10 11 |
# File 'lib/Apologist/ct_as/client.rb', line 9 def initialize(client:) @client = client end |
Instance Method Details
#log_cta_click(request_options: {}, **params) ⇒ Apologist::Types::SuccessResponse
Records that a user clicked on a specific CTA
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/Apologist/ct_as/client.rb', line 70 def log_cta_click(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) request_data = Apologist::CtAs::Types::CtaClickRequest.new(params).to_h non_body_param_names = %w[id] body = request_data.except(*non_body_param_names) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "ctas/#{URI.encode_uri_component(params[:id].to_s)}/click", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Apologist::Types::SuccessResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#match_ctas(request_options: {}, **params) ⇒ Apologist::CtAs::Types::MatchCtasResponse
Finds matching CTAs based on conversation context, user, session, device, or messages
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/Apologist/ct_as/client.rb', line 29 def match_ctas(request_options: {}, **params) params = Apologist::Internal::Types::Utils.normalize_keys(params) request = Apologist::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "ctas/match", body: Apologist::Types::CtaMatchRequest.new(params).to_h, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Apologist::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Apologist::CtAs::Types::MatchCtasResponse.load(response.body) else error_class = Apologist::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |