Files
openfoodnetwork/app/services/fdc_url_builder.rb
Maikel Linke 4303f0e974 Build API URLs to work with any FDC Shopify shop
We can extend this service class when there are other APIs. And
hopefully the DFC will provide a standard for this discovery at some
point.
2024-09-25 10:55:40 +10:00

17 lines
666 B
Ruby

# frozen_string_literal: true
# The DFC standard doesn't include endpoint discovery yet.
# So for now we are guessing URLs based on our FDC pilot project.
class FdcUrlBuilder
attr_reader :catalog_url, :orders_url, :sale_session_url
# At the moment, we start with a product link like this:
#
# https://env-0105831.jcloud-ver-jpe.ik-server.com/api/dfc/Enterprises/test-hodmedod/SuppliedProducts/44519466467635
def initialize(semantic_id)
@catalog_url, _slash, _id = semantic_id.rpartition("/")
@orders_url = @catalog_url.sub("/SuppliedProducts", "/Orders")
@sale_session_url = @catalog_url.sub("/SuppliedProducts", "/SalesSession/#")
end
end