Class: ReviewsIoClient

Inherits:
BaseService show all
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

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.

Parameters:

  • sku (String)

    product SKU being reviewed

  • name (String)

    reviewer's name

  • email (String)

    reviewer's email address

  • rating (String, Integer)

    numeric rating (1–5)

  • review (String)

    review body text

  • ip_address (String, nil) (defaults to: nil)

    submitter's IP for spam detection

Returns:

  • (Hash)

    { success: true } or { success: false, error: "message" }



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: 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.message}")
  { success: false, error: 'Failed to submit review' }
end