Class: Api::ReviewsIo::InvitationSender
- Inherits:
-
BaseService
- Object
- BaseService
- Api::ReviewsIo::InvitationSender
- Defined in:
- app/services/api/reviews_io/invitation_sender.rb
Overview
Service object: invitation sender.
Constant Summary collapse
- RESULT_SUCCESS =
Result success.
:success- RESULT_SKIPPED =
Result skipped.
:skipped- RESULT_FAILED =
Result failed.
:failed
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#support_case ⇒ Object
readonly
Returns the value of attribute support_case.
Attributes inherited from BaseService
Instance Method Summary collapse
-
#initialize(order: nil, support_case: nil, client: Client.new, logger: Rails.logger) ⇒ InvitationSender
constructor
A new instance of InvitationSender.
- #process ⇒ Object
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger
Constructor Details
#initialize(order: nil, support_case: nil, client: Client.new, logger: Rails.logger) ⇒ InvitationSender
Returns a new instance of InvitationSender.
16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/api/reviews_io/invitation_sender.rb', line 16 def initialize(order: nil, support_case: nil, client: Client.new, logger: Rails.logger) super(logger:) @order = order @support_case = support_case @client = client validate_resource! rescue Client::MissingCredentialsError => e log_warning("Reviews.io invitation skipped due to missing credentials: #{e.}") @missing_credentials = true end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
14 15 16 |
# File 'app/services/api/reviews_io/invitation_sender.rb', line 14 def client @client end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
14 15 16 |
# File 'app/services/api/reviews_io/invitation_sender.rb', line 14 def order @order end |
#support_case ⇒ Object (readonly)
Returns the value of attribute support_case.
14 15 16 |
# File 'app/services/api/reviews_io/invitation_sender.rb', line 14 def support_case @support_case end |
Instance Method Details
#process ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/services/api/reviews_io/invitation_sender.rb', line 27 def process return RESULT_SKIPPED unless Rails.env.production? return RESULT_SKIPPED if missing_credentials? return RESULT_SKIPPED unless eligible? email = reviewer_email name = reviewer_name if email.blank? log_debug("Skipping Reviews.io invitation for #{resource_identifier} (no reviewer email)") return RESULT_SKIPPED end response = client.queue_invitation(build_payload(email:, name:)) if invitation_successful?(response) mark_review_request! log_info("Queued Reviews.io invitation for #{resource_identifier} (#{email})") RESULT_SUCCESS else log_error("Reviews.io invitation failed for #{resource_identifier}: status=#{response.status} body=#{response.body}") RESULT_FAILED end rescue Client::Error => e log_error("Reviews.io client error for #{resource_identifier}: #{e.}") RESULT_FAILED rescue StandardError => e log_error("Unhandled Reviews.io error for #{resource_identifier}: #{e.class} - #{e.}") RESULT_FAILED end |