folio_client 0.13.0 → 0.15.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: c3b597d27e912d256a895af940e312d24e85acf5c234f48788c6716a4e8947de
4
- data.tar.gz: 9700fb07ff086e5b6c833897abd921adaa8efd19e173c8948484ad5d554614a2
3
+ metadata.gz: d0d61214a5547fd8ff28b9e79cef6eae123bddea9b060039163a1d8d7e3a8b91
4
+ data.tar.gz: f343f324c6bd48998394d3bc3badeff7aa010cdafcf171d53c076df44c341756
5
5
  SHA512:
6
- metadata.gz: a8256c90e8c80390e5536d4c988140d30074481d6d8b958a3e8321b81e6dc0f2f7634f3e5253abe7c9b60b22fbebb5246fe6f9052c93b658d621a108a1598ff9
7
- data.tar.gz: 99e52e340c66cc0233e577e73840880c2a0f9b2eea758b42418784124a524d1c7d1fc73ede20dd8bdd77aa0d69f44843eebd0f82e08067306b687b0082dc326b
6
+ metadata.gz: ba5f952cf9c4449adece5c15496832bb89a73cba6fcc866e4f7024c393f22fedab0be86c4a8a394c4d893b8c9a224e38305dc79e3d0a657c76c8413658600a88
7
+ data.tar.gz: c747fa00a2e6f51ba219116bc197922fab303bda976fc0945d9e906d3160813206ae434c2d8c791f66c41a92781d288eaaae40401ed03db83d4eded7783d17a1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- folio_client (0.13.0)
4
+ folio_client (0.15.0)
5
5
  activesupport (>= 4.2, < 8)
6
6
  dry-monads
7
7
  faraday
@@ -11,21 +11,30 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activesupport (7.0.8)
14
+ activesupport (7.1.2)
15
+ base64
16
+ bigdecimal
15
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
+ connection_pool (>= 2.2.5)
19
+ drb
16
20
  i18n (>= 1.6, < 2)
17
21
  minitest (>= 5.1)
22
+ mutex_m
18
23
  tzinfo (~> 2.0)
19
24
  addressable (2.8.5)
20
25
  public_suffix (>= 2.0.2, < 6.0)
21
26
  ast (2.4.2)
22
- base64 (0.1.1)
27
+ base64 (0.2.0)
28
+ bigdecimal (3.1.4)
23
29
  byebug (11.1.3)
24
30
  concurrent-ruby (1.2.2)
31
+ connection_pool (2.4.1)
25
32
  crack (0.4.5)
26
33
  rexml
27
34
  diff-lcs (1.5.0)
28
35
  docile (1.4.0)
36
+ drb (2.2.0)
37
+ ruby2_keywords
29
38
  dry-core (1.0.1)
30
39
  concurrent-ruby (~> 1.0)
31
40
  zeitwerk (~> 2.6)
@@ -33,7 +42,7 @@ GEM
33
42
  concurrent-ruby (~> 1.0)
34
43
  dry-core (~> 1.0, < 2)
35
44
  zeitwerk (~> 2.6)
36
- faraday (2.7.11)
45
+ faraday (2.7.12)
37
46
  base64
38
47
  faraday-net_http (>= 2.0, < 3.1)
39
48
  ruby2_keywords (>= 0.0.4)
@@ -49,15 +58,16 @@ GEM
49
58
  scrub_rb (>= 1.0.1, < 2)
50
59
  unf
51
60
  minitest (5.20.0)
61
+ mutex_m (0.2.0)
52
62
  parallel (1.23.0)
53
- parser (3.2.2.3)
63
+ parser (3.2.2.4)
54
64
  ast (~> 2.4.1)
55
65
  racc
56
- public_suffix (5.0.3)
57
- racc (1.7.1)
66
+ public_suffix (5.0.4)
67
+ racc (1.7.3)
58
68
  rainbow (3.1.1)
59
- rake (13.0.6)
60
- regexp_parser (2.8.1)
69
+ rake (13.1.0)
70
+ regexp_parser (2.8.2)
61
71
  rexml (3.2.6)
62
72
  rspec (3.12.0)
63
73
  rspec-core (~> 3.12.0)
@@ -72,19 +82,18 @@ GEM
72
82
  diff-lcs (>= 1.2.0, < 2.0)
73
83
  rspec-support (~> 3.12.0)
74
84
  rspec-support (3.12.1)
75
- rubocop (1.56.4)
76
- base64 (~> 0.1.1)
85
+ rubocop (1.57.2)
77
86
  json (~> 2.3)
78
87
  language_server-protocol (>= 3.17.0)
79
88
  parallel (~> 1.10)
80
- parser (>= 3.2.2.3)
89
+ parser (>= 3.2.2.4)
81
90
  rainbow (>= 2.2.2, < 4.0)
82
91
  regexp_parser (>= 1.8, < 3.0)
83
92
  rexml (>= 3.2.5, < 4.0)
84
93
  rubocop-ast (>= 1.28.1, < 2.0)
85
94
  ruby-progressbar (~> 1.7)
86
95
  unicode-display_width (>= 2.4.0, < 3.0)
87
- rubocop-ast (1.29.0)
96
+ rubocop-ast (1.30.0)
88
97
  parser (>= 3.2.1.0)
89
98
  rubocop-capybara (2.19.0)
90
99
  rubocop (~> 1.41)
@@ -93,8 +102,8 @@ GEM
93
102
  rubocop-performance (1.19.1)
94
103
  rubocop (>= 1.7.0, < 2.0)
95
104
  rubocop-ast (>= 0.4.0)
96
- rubocop-rspec (2.24.1)
97
- rubocop (~> 1.33)
105
+ rubocop-rspec (2.25.0)
106
+ rubocop (~> 1.40)
98
107
  rubocop-capybara (~> 2.17)
99
108
  rubocop-factory_bot (~> 2.22)
100
109
  ruby-progressbar (1.13.0)
@@ -106,23 +115,23 @@ GEM
106
115
  simplecov_json_formatter (~> 0.1)
107
116
  simplecov-html (0.12.3)
108
117
  simplecov_json_formatter (0.1.4)
109
- standard (1.31.1)
118
+ standard (1.32.0)
110
119
  language_server-protocol (~> 3.17.0.2)
111
120
  lint_roller (~> 1.0)
112
- rubocop (~> 1.56.2)
121
+ rubocop (~> 1.57.2)
113
122
  standard-custom (~> 1.0.0)
114
123
  standard-performance (~> 1.2)
115
124
  standard-custom (1.0.2)
116
125
  lint_roller (~> 1.0)
117
126
  rubocop (~> 1.50)
118
- standard-performance (1.2.0)
127
+ standard-performance (1.2.1)
119
128
  lint_roller (~> 1.1)
120
- rubocop-performance (~> 1.19.0)
129
+ rubocop-performance (~> 1.19.1)
121
130
  tzinfo (2.0.6)
122
131
  concurrent-ruby (~> 1.0)
123
132
  unf (0.1.4)
124
133
  unf_ext
125
- unf_ext (0.0.8.2)
134
+ unf_ext (0.0.9.1)
126
135
  unicode-display_width (2.5.0)
127
136
  webmock (3.19.1)
128
137
  addressable (>= 2.8.0)
data/README.md CHANGED
@@ -123,6 +123,47 @@ client.interface_details(id: 'c6f7470e-6229-45ce-b3f9-32006e9affcf')
123
123
  "createdByUserId"=>"38524916-598d-4edf-a2ef-04bba7e78ad6",
124
124
  "updatedDate"=>"2023-02-16T22:27:51.515+00:00",
125
125
  "updatedByUserId"=>"38524916-598d-4edf-a2ef-04bba7e78ad6"}}
126
+
127
+ # Get list of users (filtered with an optional query)
128
+ # see https://s3.amazonaws.com/foliodocs/api/mod-users/r/users.html#users_get
129
+ client.users(query: 'username=="test*"')
130
+ => {"users"=>
131
+ [{"username"=>"testing",
132
+ "id"=>"bbbadd51-c2f1-4107-a54d-52b39087725c",
133
+ "externalSystemId"=>"00324439",
134
+ "barcode"=>"2559202566",
135
+ "active"=>false,
136
+ "departments"=>[],
137
+ "proxyFor"=>[],
138
+ "personal"=>
139
+ {"lastName"=>"Testing",
140
+ "firstName"=>"Test",
141
+ "email"=>"foliotesting@lists.stanford.edu",
142
+ "addresses"=>
143
+ [{"countryId"=>"US",
144
+ "addressLine1"=>"13 Fake St",
145
+ "city"=>"Palo Alto",
146
+ "region"=>"California",
147
+ "postalCode"=>"94301",
148
+ "addressTypeId"=>"93d3d88d-499b-45d0-9bc7-ac73c3a19880",
149
+ "primaryAddress"=>true}]},
150
+ "createdDate"=>"2023-10-01T08:50:37.203+00:00",
151
+ "updatedDate"=>"2023-10-01T08:50:37.203+00:00",
152
+ "metadata"=>
153
+ {"createdDate"=>"2023-09-02T02:51:43.448+00:00",
154
+ "createdByUserId"=>"58d0aaf6-dcda-4d5e-92da-012e6b7dd766",
155
+ "updatedDate"=>"2023-10-01T08:50:37.196+00:00",
156
+ "updatedByUserId"=>"58d0aaf6-dcda-4d5e-92da-012e6b7dd766"},
157
+ "customFields"=>{"affiliation"=>"affiliate:sponsored"}}],
158
+ "totalRecords"=>1,
159
+ "resultInfo"=>{"totalRecords"=>1, "facets"=>[], "diagnostics"=>[]}}
160
+
161
+ # Get specific user info
162
+ # see https://s3.amazonaws.com/foliodocs/api/mod-users/r/users.html#users_get
163
+ client.user_details(id: 'bbbadd51-c2f1-4107-a54d-52b39087725c')
164
+ => {"username"=>"testing",
165
+ "id"=>"bbbadd51-c2f1-4107-a54d-52b39087725c",
166
+ "externalSystemId"=>"00324439", ... # same response as above, but for single user
126
167
  ```
127
168
 
128
169
  ## Development
data/api_test.rb CHANGED
@@ -23,6 +23,8 @@ pp(client.fetch_marc_hash(instance_hrid: "a666"))
23
23
  puts client.fetch_marc_xml(instance_hrid: "a666")
24
24
  puts client.fetch_marc_xml(barcode: "20503330279")
25
25
 
26
+ puts client.users(query: 'username=="pet*"')
27
+
26
28
  records = marc_files.flat_map do |marc_file_path|
27
29
  MARC::Reader.new(marc_file_path).to_a
28
30
  end
@@ -35,8 +35,8 @@ class FolioClient
35
35
  Failure(:not_found)
36
36
  end
37
37
 
38
- def wait_until_complete(wait_secs: default_wait_secs, timeout_secs: default_timeout_secs)
39
- wait_with_timeout(wait_secs: wait_secs, timeout_secs: timeout_secs) { status }
38
+ def wait_until_complete(wait_secs: default_wait_secs, timeout_secs: default_timeout_secs, max_checks: default_max_checks)
39
+ wait_with_timeout(wait_secs: wait_secs, timeout_secs: timeout_secs, max_checks: max_checks) { status }
40
40
  end
41
41
 
42
42
  def instance_hrids
@@ -66,13 +66,18 @@ class FolioClient
66
66
  10 * 60
67
67
  end
68
68
 
69
- def wait_with_timeout(wait_secs: default_wait_secs, timeout_secs: default_timeout_secs)
69
+ def default_max_checks
70
+ # arbitrary best guess at number of times to check for job status before erroring
71
+ 10
72
+ end
73
+
74
+ def wait_with_timeout(wait_secs: default_wait_secs, timeout_secs: default_timeout_secs, max_checks: default_max_checks)
70
75
  Timeout.timeout(timeout_secs) do
71
76
  loop.with_index do |_, i|
72
77
  result = yield
73
78
 
74
79
  # If a 404, wait a bit longer before raising an error.
75
- check_not_found(result, i)
80
+ check_not_found(result, i, max_checks)
76
81
  return result if done_waiting?(result)
77
82
 
78
83
  sleep(wait_secs)
@@ -86,10 +91,10 @@ class FolioClient
86
91
  result.success? || (result.failure? && result.failure == :error)
87
92
  end
88
93
 
89
- def check_not_found(result, index)
90
- return unless result.failure? && result.failure == :not_found && index > 2
94
+ def check_not_found(result, index, max_checks)
95
+ return unless result.failure? && result.failure == :not_found && index > max_checks
91
96
 
92
- raise ResourceNotFound, "Job #{job_execution_id} not found after #{index} retries"
97
+ raise ResourceNotFound, "Job #{job_execution_id} not found after #{index} retries. The data import job may still have completed."
93
98
  end
94
99
  end
95
100
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FolioClient
4
+ # Query user records in Folio; see
5
+ # https://s3.amazonaws.com/foliodocs/api/mod-users/r/users.html
6
+ class Users
7
+ attr_accessor :client
8
+
9
+ # @param client [FolioClient] the configured client
10
+ def initialize(client)
11
+ @client = client
12
+ end
13
+
14
+ # @param query [String] an optional query to limit the number of users returned
15
+ # @param limit [Integer] the number of results to return (defaults to 10,000)
16
+ # @param offset [Integer] the offset for results returned (defaults to 0)
17
+ # @param lang [String] language code for returned results (defaults to 'en')
18
+ def fetch_list(query: nil, limit: 10000, offset: 0, lang: "en")
19
+ params = {limit: limit, offset: offset, lang: lang}
20
+ params[:query] = query if query
21
+ client.get("/users", params)
22
+ end
23
+
24
+ # @param id [String] id for requested user
25
+ # @param lang [String] language code for returned results (defaults to 'en')
26
+ def fetch_user_details(id:, lang: "en")
27
+ client.get("/users/#{id}", {
28
+ lang: lang
29
+ })
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class FolioClient
4
- VERSION = "0.13.0"
4
+ VERSION = "0.15.0"
5
5
  end
data/lib/folio_client.rb CHANGED
@@ -75,7 +75,8 @@ class FolioClient
75
75
  :edit_marc_json, :fetch_external_id, :fetch_hrid, :fetch_instance_info,
76
76
  :fetch_marc_hash, :fetch_marc_xml, :get, :has_instance_status?,
77
77
  :http_get_headers, :http_post_and_put_headers, :interface_details,
78
- :job_profiles, :organization_interfaces, :organizations, :post, :put, to:
78
+ :job_profiles, :organization_interfaces, :organizations, :users, :user_details,
79
+ :post, :put, to:
79
80
  :instance end
80
81
 
81
82
  attr_accessor :config
@@ -232,6 +233,20 @@ class FolioClient
232
233
  .fetch_interface_details(...)
233
234
  end
234
235
 
236
+ # @see Users#fetch_list
237
+ def users(...)
238
+ Users
239
+ .new(self)
240
+ .fetch_list(...)
241
+ end
242
+
243
+ # @see Users#fetch_user_details
244
+ def user_details(...)
245
+ Users
246
+ .new(self)
247
+ .fetch_user_details(...)
248
+ end
249
+
235
250
  def default_timeout
236
251
  120
237
252
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: folio_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Mangiafico
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-04 00:00:00.000000000 Z
11
+ date: 2023-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -198,6 +198,7 @@ files:
198
198
  - lib/folio_client/records_editor.rb
199
199
  - lib/folio_client/source_storage.rb
200
200
  - lib/folio_client/unexpected_response.rb
201
+ - lib/folio_client/users.rb
201
202
  - lib/folio_client/version.rb
202
203
  homepage: https://github.com/sul-dlss/folio_client
203
204
  licenses: []
@@ -221,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
221
222
  - !ruby/object:Gem::Version
222
223
  version: '0'
223
224
  requirements: []
224
- rubygems_version: 3.4.19
225
+ rubygems_version: 3.4.10
225
226
  signing_key:
226
227
  specification_version: 4
227
228
  summary: Interface for interacting with the Folio ILS API.