Class: Api::V1::Google::ProductsController
- Inherits:
-
BaseController
- Object
- BaseController
- Api::V1::Google::ProductsController
- Defined in:
- app/controllers/api/v1/google/products_controller.rb
Overview
Controller: products.
Instance Method Summary collapse
Instance Method Details
#local_inventory ⇒ Object
Note:
the legacy product XML feed (#index, served from GoogleFeed) was removed
when products moved to the Merchant API push (Edi::Google). Only the local
inventory feed remains here.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/api/v1/google/products_controller.rb', line 8 def local_inventory if (locale = get_locale) catalog = Catalog.locale_to_catalog(locale) # Find the most recent pre-generated feed from S3 upload = GoogleLocalInventoryFeedWorker.latest_upload_for(catalog) 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 GoogleLocalInventoryFeedWorker.perform_async(catalog.id) res = Feed::Google::LocalInventoryGenerator.new.process(catalogs: [catalog]) xml = res[:xml] self.content_type = 'text/xml' render xml: xml end else self.response_body = "Locale not set" self.status = 404 end end |