Class: RatingUrlService
- Inherits:
-
Object
- Object
- RatingUrlService
- Includes:
- ElasticAPM::SpanHelpers
- Defined in:
- app/services/rating_url_service.rb
Overview
Service object for generating rating/review URLs
This service centralizes the business logic for generating rating URLs for both signed users (members) and guests. It replaces the RatingUrlHelper module to better align with service-oriented architecture principles.
Benefits over helper module:
-
Clear single responsibility
-
Easier to test in isolation
-
Better dependency injection
-
More maintainable and extensible
Usage:
# In mailers, serializers, or other services
service = RatingUrlService.new(reservation)
url = service.url_for
# Or for specific URL types
member_url = service.member_url
guest_url = service.guest_url(rate: 5)
# With rate parameter for pre-selecting star rating
member_url_with_rate = service.member_url(rate: 4)
Instance Attribute Summary collapse
-
#reservation ⇒ Object
readonly
Returns the value of attribute reservation.
Instance Method Summary collapse
-
#guest_url(rate: nil, only_path: true) ⇒ String
Generates a rating URL for a guest (non-signed user).
-
#initialize(reservation) ⇒ RatingUrlService
constructor
Initializes the service with a reservation.
-
#member_url(rate: nil) ⇒ String
Generates a rating URL for a signed user (member).
-
#url_for(rate: nil) ⇒ String
Generates the appropriate rating URL based on user type.
Constructor Details
#initialize(reservation) ⇒ RatingUrlService
Initializes the service with a reservation
36 37 38 |
# File 'app/services/rating_url_service.rb', line 36 def initialize(reservation) @reservation = reservation end |
Instance Attribute Details
#reservation ⇒ Object (readonly)
Returns the value of attribute reservation.
31 32 33 |
# File 'app/services/rating_url_service.rb', line 31 def reservation @reservation end |
Instance Method Details
#guest_url(rate: nil, only_path: true) ⇒ String
Generates a rating URL for a guest (non-signed user)
Uses the legacy format with encrypted hash: /reservations/rating/hash?rate=rate
117 118 119 120 121 122 123 124 125 |
# File 'app/services/rating_url_service.rb', line 117 def guest_url(rate: nil, only_path: true) hash = encoded_reservation_hash url = build_guest_url(hash, rate, only_path) log_guest_url_generation(url, rate, only_path) url end |
#member_url(rate: nil) ⇒ String
Generates a rating URL for a signed user (member)
Uses the new rating frontend with format: rating_frontend_host/language/review/reservation_id?rate=rate
90 91 92 93 94 95 96 97 98 99 |
# File 'app/services/rating_url_service.rb', line 90 def member_url(rate: nil) user = reservation.user language = user&.language.presence || MyLocaleManager.default_locale base_url = "#{AdminSetting.}/#{language}/review/#{reservation.id}" url = append_rate_param(base_url, rate) log_member_url_generation(url, language, user, rate) url end |
#url_for(rate: nil) ⇒ String
Generates the appropriate rating URL based on user type
Automatically determines if the reservation is for a signed user or guest and returns the corresponding URL format.
Routes to member URL only if user association is present and loaded. This prevents routing to member_url for orphaned user_ids.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/services/rating_url_service.rb', line 63 def url_for(rate: nil) user_type = reservation.user.present? ? 'member' : 'guest' log_routing_decision(user_type, rate) if reservation.user.present? member_url(rate: rate) else guest_url(rate: rate) end end |