Class: Api::V1::Reviews::ProductsController

Inherits:
ActionController::API
  • Object
show all
Defined in:
app/controllers/api/v1/reviews/products_controller.rb

Instance Method Summary collapse

Instance Method Details

#groupingsObject



27
28
29
30
31
32
33
34
# File 'app/controllers/api/v1/reviews/products_controller.rb', line 27

def groupings
  data = Api::ReviewsIo::ProductGroupingGenerator.new.process
  csv_string = CSV.generate do |csv|
    csv << ["SKU", "Group Name"]
    data.each {|row| csv << row}
  end
  render plain: csv_string
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/api/v1/reviews/products_controller.rb', line 9

def index
  # Find the most recent pre-generated feed from S3
  upload = ReviewsIoFeedGeneratorWorker.latest_upload

  if upload.present?
    # Redirect to presigned S3 URL (valid for 1 hour)
    redirect_to upload.presigned_url(expires_in: 1.hour), allow_other_host: true
  else
    # No pre-generated feed exists - generate on demand and queue background job
    # This should only happen on first request or after all uploads were deleted
    ReviewsIoFeedGeneratorWorker.perform_async

    response_xml = Feed::ReviewsIo::ProductCatalogGenerator.new.process[:xml]
    self.content_type = 'text/xml'
    render xml: response_xml
  end
end