Class: FolioClient
- Inherits:
-
Object
- Object
- FolioClient
- Extended by:
- Deprecation
- Includes:
- Singleton
- Defined in:
- lib/folio_client.rb,
lib/folio_client/users.rb,
lib/folio_client/version.rb,
lib/folio_client/inventory.rb,
lib/folio_client/job_status.rb,
lib/folio_client/data_import.rb,
lib/folio_client/authenticator.rb,
lib/folio_client/organizations.rb,
lib/folio_client/records_editor.rb,
lib/folio_client/source_storage.rb,
lib/folio_client/unexpected_response.rb
Overview
Client for interacting with the Folio API.
Defined Under Namespace
Classes: Authenticator, BadRequestError, Config, ConflictError, DataImport, Error, ForbiddenError, Inventory, JobStatus, MultipleResourcesFound, Organizations, RecordsEditor, ResourceNotFound, ServiceUnavailable, SourceStorage, UnauthorizedError, UnexpectedResponse, Users, ValidationError
Constant Summary collapse
- VERSION =
'1.0.0'
Instance Attribute Summary collapse
-
#config ⇒ FolioClient::Config?
Active runtime configuration.
Class Method Summary collapse
-
.configure(url:, login_params:, tenant_id: nil, user_agent: nil, timeout: nil) ⇒ Class<FolioClient>
Configure the singleton FolioClient instance.
Instance Method Summary collapse
-
#connection ⇒ Faraday::Connection
Build (or memoize) the base Faraday connection.
-
#cookie_jar ⇒ HTTP::CookieJar
Build (or memoize) the cookie jar used by Faraday to store authentication cookies.
-
#create_holdings ⇒ Object
Create a new holdings record.
-
#data_import ⇒ Object
Run an inventory data import workflow.
-
#default_timeout ⇒ Integer
Default HTTP timeout in seconds.
-
#default_user_agent ⇒ String
Default user-agent string used for outbound requests.
-
#edit_marc_json ⇒ Object
Edit MARC-in-JSON records.
-
#fetch_external_id ⇒ Object
Fetch the Folio external id for a matching record.
-
#fetch_holdings ⇒ Object
Fetch holdings associated with a record.
-
#fetch_hrid ⇒ Object
Fetch a Folio HRID by instance identifier or query context.
-
#fetch_instance_info ⇒ Object
Fetch inventory instance details.
-
#fetch_location ⇒ Object
Fetch location details from inventory.
-
#fetch_marc_hash ⇒ Object
Fetch MARC data as a Ruby hash.
-
#fetch_marc_xml ⇒ Object
Fetch MARC data as XML.
-
#force_token_refresh! ⇒ Object
Force a refresh of the current auth token.
-
#get(path, params = {}) ⇒ Hash, ...
Send an authenticated GET request.
-
#has_instance_status? ⇒ Boolean
Determine whether an instance has the requested status.
-
#interface_details ⇒ Object
Fetch detailed interface information for an organization interface.
-
#job_profiles ⇒ Object
List available data-import job profiles.
-
#organization_interfaces ⇒ Object
List interfaces for organizations.
-
#organizations ⇒ Object
List organizations.
-
#post(path, body = nil, content_type: 'application/json') ⇒ Hash, ...
Send an authenticated POST request.
-
#put(path, body = nil, content_type: 'application/json', **exception_args) ⇒ Hash, ...
Send an authenticated PUT request.
-
#update_holdings ⇒ Object
Update an existing holdings record.
-
#user_details ⇒ Object
Fetch details for a user.
-
#users ⇒ Object
List users.
Instance Attribute Details
#config ⇒ FolioClient::Config?
Returns active runtime configuration.
100 101 102 |
# File 'lib/folio_client.rb', line 100 def config @config end |
Class Method Details
.configure(url:, login_params:, tenant_id: nil, user_agent: nil, timeout: nil) ⇒ Class<FolioClient>
Configure the singleton FolioClient instance.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/folio_client.rb', line 78 def configure(url:, login_params:, tenant_id: nil, user_agent: nil, timeout: nil) instance.config = Config.new( url: url, login_params: login_params, tenant_id: tenant_id, timeout: timeout || default_timeout, user_agent: user_agent || default_user_agent ) self end |
Instance Method Details
#connection ⇒ Faraday::Connection
Build (or memoize) the base Faraday connection.
158 159 160 161 162 163 164 165 166 167 |
# File 'lib/folio_client.rb', line 158 def connection @connection ||= Faraday.new( url: config.url, headers: config.headers, request: { timeout: config.timeout } ) do |faraday| faraday.use :cookie_jar, jar: faraday.adapter Faraday.default_adapter end end |
#cookie_jar ⇒ HTTP::CookieJar
Build (or memoize) the cookie jar used by Faraday to store authentication cookies.
171 172 173 |
# File 'lib/folio_client.rb', line 171 def @cookie_jar ||= HTTP::CookieJar.new end |
#create_holdings ⇒ Object
Create a new holdings record.
220 221 222 |
# File 'lib/folio_client.rb', line 220 def create_holdings(...) inventory.create_holdings(...) end |
#data_import ⇒ Object
Run an inventory data import workflow.
248 249 250 |
# File 'lib/folio_client.rb', line 248 def data_import(...) data_import_service.import(...) end |
#default_timeout ⇒ Integer
Default HTTP timeout in seconds.
311 312 313 |
# File 'lib/folio_client.rb', line 311 def default_timeout 180 end |
#default_user_agent ⇒ String
Default user-agent string used for outbound requests.
318 319 320 |
# File 'lib/folio_client.rb', line 318 def default_user_agent "folio_client #{VERSION}" end |
#edit_marc_json ⇒ Object
Edit MARC-in-JSON records.
262 263 264 |
# File 'lib/folio_client.rb', line 262 def edit_marc_json(...) records_editor.edit_marc_json(...) end |
#fetch_external_id ⇒ Object
Fetch the Folio external id for a matching record.
185 186 187 |
# File 'lib/folio_client.rb', line 185 def fetch_external_id(...) inventory.fetch_external_id(...) end |
#fetch_holdings ⇒ Object
Fetch holdings associated with a record.
206 207 208 |
# File 'lib/folio_client.rb', line 206 def fetch_holdings(...) inventory.fetch_holdings(...) end |
#fetch_hrid ⇒ Object
Fetch a Folio HRID by instance identifier or query context.
178 179 180 |
# File 'lib/folio_client.rb', line 178 def fetch_hrid(...) inventory.fetch_hrid(...) end |
#fetch_instance_info ⇒ Object
Fetch inventory instance details.
192 193 194 |
# File 'lib/folio_client.rb', line 192 def fetch_instance_info(...) inventory.fetch_instance_info(...) end |
#fetch_location ⇒ Object
Fetch location details from inventory.
199 200 201 |
# File 'lib/folio_client.rb', line 199 def fetch_location(...) inventory.fetch_location(...) end |
#fetch_marc_hash ⇒ Object
Fetch MARC data as a Ruby hash.
227 228 229 |
# File 'lib/folio_client.rb', line 227 def fetch_marc_hash(...) source_storage.fetch_marc_hash(...) end |
#fetch_marc_xml ⇒ Object
Fetch MARC data as XML.
234 235 236 |
# File 'lib/folio_client.rb', line 234 def fetch_marc_xml(...) source_storage.fetch_marc_xml(...) end |
#force_token_refresh! ⇒ Object
Force a refresh of the current auth token.
304 305 306 |
# File 'lib/folio_client.rb', line 304 def force_token_refresh! Authenticator.refresh_token! end |
#get(path, params = {}) ⇒ Hash, ...
Send an authenticated GET request.
107 108 109 110 111 112 113 114 115 |
# File 'lib/folio_client.rb', line 107 def get(path, params = {}) response = do connection.get(path, params) end UnexpectedResponse.call(response) unless response.success? JSON.parse(response.body) if response.body.present? end |
#has_instance_status? ⇒ Boolean
Determine whether an instance has the requested status.
241 242 243 |
# File 'lib/folio_client.rb', line 241 def has_instance_status?(...) # rubocop:disable Naming/PredicatePrefix inventory.has_instance_status?(...) end |
#interface_details ⇒ Object
Fetch detailed interface information for an organization interface.
283 284 285 |
# File 'lib/folio_client.rb', line 283 def interface_details(...) organizations_service.fetch_interface_details(...) end |
#job_profiles ⇒ Object
List available data-import job profiles.
255 256 257 |
# File 'lib/folio_client.rb', line 255 def job_profiles(...) data_import_service.job_profiles(...) end |
#organization_interfaces ⇒ Object
List interfaces for organizations.
276 277 278 |
# File 'lib/folio_client.rb', line 276 def organization_interfaces(...) organizations_service.fetch_interface_list(...) end |
#organizations ⇒ Object
List organizations.
269 270 271 |
# File 'lib/folio_client.rb', line 269 def organizations(...) organizations_service.fetch_list(...) end |
#post(path, body = nil, content_type: 'application/json') ⇒ Hash, ...
Send an authenticated POST request. If content_type is application/json, body is serialized with to_json. Otherwise body is sent unchanged.
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/folio_client.rb', line 125 def post(path, body = nil, content_type: 'application/json') req_body = content_type == 'application/json' ? body&.to_json : body response = do connection.post(path, req_body, { content_type: content_type }) end UnexpectedResponse.call(response) unless response.success? JSON.parse(response.body) if response.body.present? end |
#put(path, body = nil, content_type: 'application/json', **exception_args) ⇒ Hash, ...
Send an authenticated PUT request. If content_type is application/json, body is serialized with to_json. Otherwise body is sent unchanged.
145 146 147 148 149 150 151 152 153 154 |
# File 'lib/folio_client.rb', line 145 def put(path, body = nil, content_type: 'application/json', **exception_args) req_body = content_type == 'application/json' ? body&.to_json : body response = do connection.put(path, req_body, { content_type: content_type }) end UnexpectedResponse.call(response, **exception_args) unless response.success? JSON.parse(response.body) if response.body.present? end |
#update_holdings ⇒ Object
Update an existing holdings record.
213 214 215 |
# File 'lib/folio_client.rb', line 213 def update_holdings(...) inventory.update_holdings(...) end |
#user_details ⇒ Object
Fetch details for a user.
297 298 299 |
# File 'lib/folio_client.rb', line 297 def user_details(...) users_service.fetch_user_details(...) end |
#users ⇒ Object
List users.
290 291 292 |
# File 'lib/folio_client.rb', line 290 def users(...) users_service.fetch_list(...) end |