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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7ff536f92f06403a2d47dd9ede2dab90d0f20d8b6ad52f9c2bd047dd7eb0650
4
- data.tar.gz: 3ba0ff3343cbf79bfb383254d18f8cad2bd0c74b0251e4c76bf69b26d6d75ed4
3
+ metadata.gz: 38e080519e200ca466c29ce2aff8f3e1d9940a7d6f4ea0b5eb559e6a75b4b44c
4
+ data.tar.gz: a92ff5b5fa997ab8515cab2669914c4c283e323db39bb3c2ae2c3c1ee7a6aac4
5
5
  SHA512:
6
- metadata.gz: 6e5e9f3c4b84168f41b6afaacffebcaba29bc732ea338a3834a01621dec956e568d5863789da54b4df297bda2915e9119164c0fbf3e4de1c703fc5317df0c4fb
7
- data.tar.gz: c9bde04bd107cb50213b2beb8019251dd1cf2452ce842f926420576202df65ee3d54ea1a665afb441ff5d47a367fab8230de0612d88767b73bc9454a35cd9218
6
+ metadata.gz: 27b02c487f0179288265f738c2ba674b7670e0f1a0859152ffff5a934b10a1bfdf6a1152b235126ce6e60a71584b333d5b19c8f792fc3aa3015bdbb1d810551e
7
+ data.tar.gz: 43b31dccad99d032255cd3376d281e558674baf69f6bb486cc118a621f0453dba652f969e610c931a7ddb0903ce6578c8bf455d37842aceafd91a4659fe1ea69
data/.rubocop.yml CHANGED
@@ -22,6 +22,8 @@ RSpec/MultipleExpectations:
22
22
  Max: 3
23
23
  RSpec/ExampleLength:
24
24
  Max: 15
25
+ RSpec/NestedGroups:
26
+ Enabled: false
25
27
 
26
28
  RSpec/BeEq: # new in 2.9.0
27
29
  Enabled: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- folio_client (1.0.0)
4
+ folio_client (1.1.0)
5
5
  activesupport (>= 4.2)
6
6
  deprecation
7
7
  dry-monads
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 or POST, or more commonly, use the helper methods provided, as described in the section below.
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:
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FolioClient
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: folio_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Mangiafico