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
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.15.0"
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
82
83
84
|
# File 'lib/folio_client.rb', line 82
def config
@config
end
|
Class Method Details
Returns the configured Singleton class.
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/folio_client.rb', line 52
def configure(url:, login_params:, okapi_headers:, timeout: default_timeout)
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
)
self
end
|
Instance Method Details
#connection ⇒ Object
the base connection to the Folio API
142
143
144
145
146
147
148
|
# File 'lib/folio_client.rb', line 142
def connection
@connection ||= Faraday.new(
url: config.url,
headers: DEFAULT_HEADERS.merge(config. || {}),
request: {timeout: config.timeout}
)
end
|
#data_import ⇒ Object
195
196
197
198
199
|
# File 'lib/folio_client.rb', line 195
def data_import(...)
DataImport
.new(self)
.import(...)
end
|
#default_timeout ⇒ Object
250
251
252
|
# File 'lib/folio_client.rb', line 250
def default_timeout
120
end
|
#edit_marc_json ⇒ Object
209
210
211
212
213
|
# File 'lib/folio_client.rb', line 209
def edit_marc_json(...)
RecordsEditor
.new(self)
.edit_marc_json(...)
end
|
#fetch_external_id ⇒ Object
160
161
162
163
164
|
# File 'lib/folio_client.rb', line 160
def fetch_external_id(...)
Inventory
.new(self)
.fetch_external_id(...)
end
|
#fetch_hrid ⇒ Object
153
154
155
156
157
|
# File 'lib/folio_client.rb', line 153
def fetch_hrid(...)
Inventory
.new(self)
.fetch_hrid(...)
end
|
#fetch_instance_info ⇒ Object
167
168
169
170
171
|
# File 'lib/folio_client.rb', line 167
def fetch_instance_info(...)
Inventory
.new(self)
.fetch_instance_info(...)
end
|
#fetch_marc_hash ⇒ Object
174
175
176
177
178
|
# File 'lib/folio_client.rb', line 174
def fetch_marc_hash(...)
SourceStorage
.new(self)
.fetch_marc_hash(...)
end
|
#fetch_marc_xml ⇒ Object
181
182
183
184
185
|
# File 'lib/folio_client.rb', line 181
def fetch_marc_xml(...)
SourceStorage
.new(self)
.fetch_marc_xml(...)
end
|
#get(path, params = {}) ⇒ Object
Send an authenticated get request
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/folio_client.rb', line 87
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
188
189
190
191
192
|
# File 'lib/folio_client.rb', line 188
def has_instance_status?(...)
Inventory
.new(self)
.has_instance_status?(...)
end
|
#interface_details ⇒ Object
230
231
232
233
234
|
# File 'lib/folio_client.rb', line 230
def interface_details(...)
Organizations
.new(self)
.fetch_interface_details(...)
end
|
#job_profiles ⇒ Object
@ see DataImport#job_profiles
202
203
204
205
206
|
# File 'lib/folio_client.rb', line 202
def job_profiles(...)
DataImport
.new(self)
.job_profiles(...)
end
|
#organization_interfaces ⇒ Object
223
224
225
226
227
|
# File 'lib/folio_client.rb', line 223
def organization_interfaces(...)
Organizations
.new(self)
.fetch_interface_list(...)
end
|
#organizations ⇒ Object
216
217
218
219
220
|
# File 'lib/folio_client.rb', line 216
def organizations(...)
Organizations
.new(self)
.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/folio_client.rb', line 103
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/folio_client.rb', line 124
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
244
245
246
247
248
|
# File 'lib/folio_client.rb', line 244
def user_details(...)
Users
.new(self)
.fetch_user_details(...)
end
|
#users ⇒ Object
237
238
239
240
241
|
# File 'lib/folio_client.rb', line 237
def users(...)
Users
.new(self)
.fetch_list(...)
end
|