mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-07 22:46:06 +00:00
The current implementation of the FDC is not adhering to the DFC standard. The difference is added in this compatibility layer. This should be temporary code. The FDC dev team should change their API in their next development cycle.
34 lines
820 B
Ruby
34 lines
820 B
Ruby
# frozen_string_literal: true
|
|
|
|
require "private_address_check"
|
|
require "private_address_check/tcpsocket_ext"
|
|
|
|
# Request a JSON document from the FDC API with authentication.
|
|
#
|
|
# Currently, the API doesn't quite comply with the DFC standard and we need
|
|
# to authenticate a little bit differently.
|
|
#
|
|
# And then we get slightly different data as well.
|
|
class FdcRequest < DfcRequest
|
|
# Override main method to POST authorization data.
|
|
def call(url, data = {})
|
|
response = request(url, auth_data.merge(data).to_json)
|
|
|
|
if response.status >= 400 && token_stale?
|
|
refresh_access_token!
|
|
response = request(url, auth_data.merge(data).to_json)
|
|
end
|
|
|
|
response.body
|
|
end
|
|
|
|
private
|
|
|
|
def auth_data
|
|
{
|
|
userId: @user.oidc_account.uid,
|
|
accessToken: @user.oidc_account.token,
|
|
}
|
|
end
|
|
end
|