Class: Api::V1::Google::ProductsController
- Inherits:
-
BaseController
- Object
- BaseController
- Api::V1::Google::ProductsController
- Defined in:
- app/controllers/api/v1/google/products_controller.rb
Instance Method Summary collapse
Instance Method Details
#index ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/api/v1/google/products_controller.rb', line 3 def index if locale = get_locale catalog = Catalog.locale_to_catalog(locale) xml_data = GoogleFeed.full_xml(catalog) self.content_type = 'text/xml' render xml: xml_data else self.response_body = "Locale not set" self.status = 404 end end |
#local_inventory ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/api/v1/google/products_controller.rb', line 15 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 |