lib/folio_client.rb in folio_client-0.6.0 vs lib/folio_client.rb in folio_client-0.6.1
- old
+ new
@@ -56,22 +56,26 @@
# Send an authenticated get request
# @param path [String] the path to the Folio API request
# @param request [Hash] params to get to the API
def get(path, params = {})
- response = connection.get(path, params, {"x-okapi-token": config.token})
+ response = TokenWrapper.refresh(config, connection) do
+ connection.get(path, params, {"x-okapi-token": config.token})
+ end
UnexpectedResponse.call(response) unless response.success?
JSON.parse(response.body)
end
# Send an authenticated post request
# @param path [String] the path to the Folio API request
# @param request [json] request body to post to the API
def post(path, request = nil)
- response = connection.post(path, request, {"x-okapi-token": config.token})
+ response = TokenWrapper.refresh(config, connection) do
+ connection.post(path, request, {"x-okapi-token": config.token})
+ end
UnexpectedResponse.call(response) unless response.success?
JSON.parse(response.body)
end
@@ -83,27 +87,20 @@
headers: DEFAULT_HEADERS.merge(config.okapi_headers || {})
)
end
# Public methods available on the FolioClient below
- # Wrap methods in `TokenWrapper` to ensure a new token is fetched automatically if expired
def fetch_hrid(...)
- TokenWrapper.refresh(config, connection) do
- inventory = Inventory.new(self)
- inventory.fetch_hrid(...)
- end
+ inventory = Inventory.new(self)
+ inventory.fetch_hrid(...)
end
def fetch_marc_hash(...)
- TokenWrapper.refresh(config, connection) do
- source_storage = SourceStorage.new(self)
- source_storage.fetch_marc_hash(...)
- end
+ source_storage = SourceStorage.new(self)
+ source_storage.fetch_marc_hash(...)
end
def has_instance_status?(...)
- TokenWrapper.refresh(config, connection) do
- inventory = Inventory.new(self)
- inventory.has_instance_status?(...)
- end
+ inventory = Inventory.new(self)
+ inventory.has_instance_status?(...)
end
end