Class: Api::ReviewsIo::InvitationSender
- Inherits:
-
BaseService
- Object
- BaseService
- Api::ReviewsIo::InvitationSender
- Defined in:
- app/services/api/reviews_io/invitation_sender.rb
Constant Summary collapse
- RESULT_SUCCESS =
:success- RESULT_SKIPPED =
:skipped- 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.
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, #options, #tagged_logger
Constructor Details
#initialize(order: nil, support_case: nil, client: Client.new, logger: Rails.logger) ⇒ InvitationSender
Returns a new instance of InvitationSender.
12 13 14 15 16 17 18 19 20 21 |
# File 'app/services/api/reviews_io/invitation_sender.rb', line 12 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.
10 11 12 |
# File 'app/services/api/reviews_io/invitation_sender.rb', line 10 def client @client end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
10 11 12 |
# File 'app/services/api/reviews_io/invitation_sender.rb', line 10 def order @order end |
#support_case ⇒ Object (readonly)
Returns the value of attribute support_case.
10 11 12 |
# File 'app/services/api/reviews_io/invitation_sender.rb', line 10 def support_case @support_case end |
Instance Method Details
#process ⇒ Object
23 24 25 26 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 |
# File 'app/services/api/reviews_io/invitation_sender.rb', line 23 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 unless email.present? 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.to_s}") 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 |