folio_client 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +7 -1
- data/lib/folio_client/version.rb +1 -1
- data/lib/folio_client.rb +28 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 38e080519e200ca466c29ce2aff8f3e1d9940a7d6f4ea0b5eb559e6a75b4b44c
|
|
4
|
+
data.tar.gz: a92ff5b5fa997ab8515cab2669914c4c283e323db39bb3c2ae2c3c1ee7a6aac4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27b02c487f0179288265f738c2ba674b7670e0f1a0859152ffff5a934b10a1bfdf6a1152b235126ce6e60a71584b333d5b19c8f792fc3aa3015bdbb1d810551e
|
|
7
|
+
data.tar.gz: 43b31dccad99d032255cd3376d281e558674baf69f6bb486cc118a621f0453dba652f969e610c931a7ddb0903ce6578c8bf455d37842aceafd91a4659fe1ea69
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -18,7 +18,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
|
18
18
|
|
|
19
19
|
## Usage
|
|
20
20
|
|
|
21
|
-
The gem should be configured first, and then you can either call API endpoints directly using GET
|
|
21
|
+
The gem should be configured first, and then you can either call API endpoints directly using GET, POST, PUT, and DELETE. It may be more convenient to use the helper methods provided, as described in the section below, if your use case is already covered by what's been implemented already.
|
|
22
22
|
|
|
23
23
|
```ruby
|
|
24
24
|
require 'folio_client'
|
|
@@ -34,6 +34,12 @@ client = FolioClient.configure(
|
|
|
34
34
|
response = client.get('/organizations/organizations', {query_string_param: 'abcdef'})
|
|
35
35
|
|
|
36
36
|
response = client.post('/some/post/endpoint', params_hash.to_json)
|
|
37
|
+
|
|
38
|
+
# If you want direct access to the response object for your own handling, you can also
|
|
39
|
+
# pass a block to the get, post, put, and delete methods:
|
|
40
|
+
response = client.post('/some/post/endpoint', params_hash.to_json) do |resp|
|
|
41
|
+
# Do something with resp.status, resp.headers, resp.body, etc.
|
|
42
|
+
end
|
|
37
43
|
```
|
|
38
44
|
|
|
39
45
|
Note that the settings will live in the consumer of this gem and would typically be used like this:
|
data/lib/folio_client/version.rb
CHANGED
data/lib/folio_client.rb
CHANGED
|
@@ -103,6 +103,7 @@ class FolioClient # rubocop:disable Metrics/ClassLength
|
|
|
103
103
|
# @param path [String] API path relative to configured +url+
|
|
104
104
|
# @param params [Hash] query parameters
|
|
105
105
|
# @return [Hash, Array, nil] parsed JSON body, or +nil+ for empty body
|
|
106
|
+
# @yield [Faraday::Response] optional block to receive the raw +Faraday::Response+ object
|
|
106
107
|
# @raise [FolioClient::Error] when Folio responds with an unexpected status
|
|
107
108
|
def get(path, params = {})
|
|
108
109
|
response = with_token_refresh_when_unauthorized do
|
|
@@ -111,6 +112,8 @@ class FolioClient # rubocop:disable Metrics/ClassLength
|
|
|
111
112
|
|
|
112
113
|
UnexpectedResponse.call(response) unless response.success?
|
|
113
114
|
|
|
115
|
+
yield response if block_given?
|
|
116
|
+
|
|
114
117
|
JSON.parse(response.body) if response.body.present?
|
|
115
118
|
end
|
|
116
119
|
|
|
@@ -121,6 +124,7 @@ class FolioClient # rubocop:disable Metrics/ClassLength
|
|
|
121
124
|
# @param body [Hash, String, nil] request payload
|
|
122
125
|
# @param content_type [String] MIME type of request body
|
|
123
126
|
# @return [Hash, Array, nil] parsed JSON body, or +nil+ for empty body
|
|
127
|
+
# @yield [Faraday::Response] optional block to receive the raw +Faraday::Response+ object
|
|
124
128
|
# @raise [FolioClient::Error] when Folio responds with an unexpected status
|
|
125
129
|
def post(path, body = nil, content_type: 'application/json')
|
|
126
130
|
req_body = content_type == 'application/json' ? body&.to_json : body
|
|
@@ -130,6 +134,8 @@ class FolioClient # rubocop:disable Metrics/ClassLength
|
|
|
130
134
|
|
|
131
135
|
UnexpectedResponse.call(response) unless response.success?
|
|
132
136
|
|
|
137
|
+
yield response if block_given?
|
|
138
|
+
|
|
133
139
|
JSON.parse(response.body) if response.body.present?
|
|
134
140
|
end
|
|
135
141
|
|
|
@@ -141,6 +147,7 @@ class FolioClient # rubocop:disable Metrics/ClassLength
|
|
|
141
147
|
# @param content_type [String] MIME type of request body
|
|
142
148
|
# @param exception_args [Hash] supplemental context forwarded to +UnexpectedResponse+
|
|
143
149
|
# @return [Hash, Array, nil] parsed JSON body, or +nil+ for empty body
|
|
150
|
+
# @yield [Faraday::Response] optional block to receive the raw +Faraday::Response+ object
|
|
144
151
|
# @raise [FolioClient::Error] when Folio responds with an unexpected status
|
|
145
152
|
def put(path, body = nil, content_type: 'application/json', **exception_args)
|
|
146
153
|
req_body = content_type == 'application/json' ? body&.to_json : body
|
|
@@ -150,6 +157,27 @@ class FolioClient # rubocop:disable Metrics/ClassLength
|
|
|
150
157
|
|
|
151
158
|
UnexpectedResponse.call(response, **exception_args) unless response.success?
|
|
152
159
|
|
|
160
|
+
yield response if block_given?
|
|
161
|
+
|
|
162
|
+
JSON.parse(response.body) if response.body.present?
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# Send an authenticated DELETE request
|
|
166
|
+
# @note None of the current FolioClient services use this method, but it's provided
|
|
167
|
+
# primarily to accommodate work in folio-tasks
|
|
168
|
+
# @param path [String] API path relative to configured +url+
|
|
169
|
+
# @return [Hash, Array, nil] parsed JSON body, or +nil+ for empty body
|
|
170
|
+
# @yield [Faraday::Response] optional block to receive the raw +Faraday::Response+ object
|
|
171
|
+
# @raise [FolioClient::Error] when Folio responds with an unexpected status
|
|
172
|
+
def delete(path)
|
|
173
|
+
response = with_token_refresh_when_unauthorized do
|
|
174
|
+
connection.delete(path)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
UnexpectedResponse.call(response) unless response.success?
|
|
178
|
+
|
|
179
|
+
yield response if block_given?
|
|
180
|
+
|
|
153
181
|
JSON.parse(response.body) if response.body.present?
|
|
154
182
|
end
|
|
155
183
|
|