Class: ReviewsIoClient
- Inherits:
-
BaseService
- Object
- BaseService
- ReviewsIoClient
- Defined in:
- app/services/reviews_io_client.rb
Overview
Faraday-backed client for the Reviews.io Product Reviews API.
Abstracts the HTTP transport so controllers and background workers
never hold raw Net::HTTP / URL knowledge.
Constant Summary collapse
- BASE_URL =
'https://api.reviews.io'
Instance Method Summary collapse
-
#submit_product_review(sku:, name:, email:, rating:, review:, ip_address: nil) ⇒ Hash
Submit a product review to Reviews.io.
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #process, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#submit_product_review(sku:, name:, email:, rating:, review:, ip_address: nil) ⇒ Hash
Submit a product review to Reviews.io.
21 22 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 |
# File 'app/services/reviews_io_client.rb', line 21 def submit_product_review(sku:, name:, email:, rating:, review:, ip_address: nil) payload = { sku: sku, name: name, email: email, rating: .to_s, review: review } payload[:ip_address] = ip_address if ip_address.present? response = connection.post('product/review/new') do |req| req.params['store'] = store_id req.params['apikey'] = api_key if api_key.present? req.body = payload.to_json end if response.success? { success: true } else body = safe_parse(response.body) error = body['message'] || body['error'] || "HTTP #{response.status}" Rails.logger.warn("[ReviewsIoClient] API error: #{error}") { success: false, error: error } end rescue Faraday::TimeoutError { success: false, error: 'Review service temporarily unavailable' } rescue Faraday::Error => e Rails.logger.error("[ReviewsIoClient] Connection error: #{e.}") { success: false, error: 'Failed to submit review' } end |