Class: FolioClient
- Inherits:
-
Object
show all
- 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 rubocop:disable Metrics/ClassLength
Defined Under Namespace
Classes: Authenticator, ConflictError, DataImport, Error, ForbiddenError, Inventory, JobStatus, MultipleResourcesFound, Organizations, RecordsEditor, ResourceNotFound, ServiceUnavailable, SourceStorage, UnauthorizedError, UnexpectedResponse, Users, ValidationError
Constant Summary
collapse
{
accept: 'application/json, text/plain',
content_type: 'application/json'
}.freeze
- VERSION =
'0.17.0'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
89
90
91
|
# File 'lib/folio_client.rb', line 89
def config
@config
end
|
Class Method Details
Returns the configured Singleton class.
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/folio_client.rb', line 55
def configure(url:, login_params:, okapi_headers:, timeout: default_timeout, legacy_auth: true)
instance.config = OpenStruct.new(
token: 'a temporary dummy token to avoid hitting the API before it is needed',
url: url,
login_params: login_params,
okapi_headers: ,
timeout: timeout,
legacy_auth: legacy_auth )
self
end
|
Instance Method Details
#connection ⇒ Object
the base connection to the Folio API
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/folio_client.rb', line 153
def connection
@connection ||= Faraday.new(
url: config.url,
headers: DEFAULT_HEADERS.merge(config. || {}),
request: { timeout: config.timeout }
) do |faraday|
faraday.use :cookie_jar, jar: cookie_jar
faraday.adapter Faraday.default_adapter
end
end
|
#cookie_jar ⇒ Object
164
165
166
|
# File 'lib/folio_client.rb', line 164
def cookie_jar
@cookie_jar ||= HTTP::CookieJar.new
end
|
#data_import ⇒ Object
213
214
215
216
217
|
# File 'lib/folio_client.rb', line 213
def data_import(...)
DataImport
.new
.import(...)
end
|
#default_timeout ⇒ Object
268
269
270
|
# File 'lib/folio_client.rb', line 268
def default_timeout
120
end
|
#edit_marc_json ⇒ Object
227
228
229
230
231
|
# File 'lib/folio_client.rb', line 227
def edit_marc_json(...)
RecordsEditor
.new
.edit_marc_json(...)
end
|
#fetch_external_id ⇒ Object
178
179
180
181
182
|
# File 'lib/folio_client.rb', line 178
def fetch_external_id(...)
Inventory
.new
.fetch_external_id(...)
end
|
#fetch_hrid ⇒ Object
171
172
173
174
175
|
# File 'lib/folio_client.rb', line 171
def fetch_hrid(...)
Inventory
.new
.fetch_hrid(...)
end
|
#fetch_instance_info ⇒ Object
185
186
187
188
189
|
# File 'lib/folio_client.rb', line 185
def fetch_instance_info(...)
Inventory
.new
.fetch_instance_info(...)
end
|
#fetch_marc_hash ⇒ Object
192
193
194
195
196
|
# File 'lib/folio_client.rb', line 192
def fetch_marc_hash(...)
SourceStorage
.new
.fetch_marc_hash(...)
end
|
#fetch_marc_xml ⇒ Object
199
200
201
202
203
|
# File 'lib/folio_client.rb', line 199
def fetch_marc_xml(...)
SourceStorage
.new
.fetch_marc_xml(...)
end
|
#force_token_refresh! ⇒ Object
272
273
274
|
# File 'lib/folio_client.rb', line 272
def force_token_refresh!
config.token = Authenticator.token
end
|
#get(path, params = {}) ⇒ Object
Send an authenticated get request
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/folio_client.rb', line 94
def get(path, params = {})
response = with_token_refresh_when_unauthorized do
connection.get(path, params, { 'x-okapi-token': config.token })
end
UnexpectedResponse.call(response) unless response.success?
return nil if response.body.blank?
JSON.parse(response.body)
end
|
#has_instance_status? ⇒ Boolean
206
207
208
209
210
|
# File 'lib/folio_client.rb', line 206
def has_instance_status?(...) Inventory
.new
.has_instance_status?(...)
end
|
#interface_details ⇒ Object
248
249
250
251
252
|
# File 'lib/folio_client.rb', line 248
def interface_details(...)
Organizations
.new
.fetch_interface_details(...)
end
|
#job_profiles ⇒ Object
@ see DataImport#job_profiles
220
221
222
223
224
|
# File 'lib/folio_client.rb', line 220
def job_profiles(...)
DataImport
.new
.job_profiles(...)
end
|
#organization_interfaces ⇒ Object
241
242
243
244
245
|
# File 'lib/folio_client.rb', line 241
def organization_interfaces(...)
Organizations
.new
.fetch_interface_list(...)
end
|
#organizations ⇒ Object
234
235
236
237
238
|
# File 'lib/folio_client.rb', line 234
def organizations(...)
Organizations
.new
.fetch_list(...)
end
|
#post(path, body = nil, content_type: 'application/json') ⇒ Object
Send an authenticated post request If the body is JSON, it will be automatically serialized rubocop:disable Metrics/MethodLength
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/folio_client.rb', line 111
def post(path, body = nil, content_type: 'application/json')
req_body = content_type == 'application/json' ? body&.to_json : body
response = with_token_refresh_when_unauthorized do
= {
'x-okapi-token': config.token,
'content-type': content_type
}
connection.post(path, req_body, )
end
UnexpectedResponse.call(response) unless response.success?
return nil if response.body.blank?
JSON.parse(response.body)
end
|
#put(path, body = nil, content_type: 'application/json') ⇒ Object
Send an authenticated put request If the body is JSON, it will be automatically serialized rubocop:disable Metrics/MethodLength
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/folio_client.rb', line 134
def put(path, body = nil, content_type: 'application/json')
req_body = content_type == 'application/json' ? body&.to_json : body
response = with_token_refresh_when_unauthorized do
= {
'x-okapi-token': config.token,
'content-type': content_type
}
connection.put(path, req_body, )
end
UnexpectedResponse.call(response) unless response.success?
return nil if response.body.blank?
JSON.parse(response.body)
end
|
#user_details ⇒ Object
262
263
264
265
266
|
# File 'lib/folio_client.rb', line 262
def user_details(...)
Users
.new
.fetch_user_details(...)
end
|
#users ⇒ Object
255
256
257
258
259
|
# File 'lib/folio_client.rb', line 255
def users(...)
Users
.new
.fetch_list(...)
end
|