alma 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8abf09ab18832b9e07c6ff3f19f55579799558aeeb94434757f4295d3e15be1
4
- data.tar.gz: aa9956de6794d3a2d7e1690aab759e80cb62dd1c6a4c6525132ff57b5f82d5d9
3
+ metadata.gz: b6269246a05d81573e9b8037da0f8d4149a51acdf6635951efe80b96c5d30458
4
+ data.tar.gz: 81d9cbb84cb1c7899b1b60c4b2dc4c5fbafa6f7c8d250b0a960d0fa72b245469
5
5
  SHA512:
6
- metadata.gz: 27a32ba65c33fb1d78dfc9a0cf13b504661667ed4eacf3d80136cb0ad2eeedb1ef20bed4cc5a2109c75984b6f276443aee9de21561e845f5950f6ea0690a337a
7
- data.tar.gz: 28b451a986c72c7e9564f0f1933f5ba356863c14871176a0da50a83ad4de9a38da7ec9c9466aeb172408f0331228dc756a66fec6fc7a509e03e5cc9b696d30b4
6
+ metadata.gz: 5289a52394d811d85a5fac07224484e4df005e4f14e6854df5326d1bb096279e19991d2a7289f1e268a0d6e66fc76a3f56799460395da1efc1c1539e81fae358
7
+ data.tar.gz: adcb02a15f418c088f70e933979946e522ceb72417b05c428a499fc500cc793a7caca76c15a0cd02080075e881e4af68184644e17740a253ce90b9b7e7331251
data/.circleci/config.yml CHANGED
@@ -17,7 +17,7 @@ workflows:
17
17
  jobs:
18
18
  build:
19
19
  docker:
20
- - image: cimg/ruby:3.1-browsers
20
+ - image: cimg/ruby:3.3.0-browsers
21
21
  auth:
22
22
  username: $DOCKERHUB_USER
23
23
  password: $DOCKERHUB_PASSWORD
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ require:
2
2
  - rubocop-rails
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 3.1
5
+ TargetRubyVersion: 3.3
6
6
  # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
7
7
  # to ignore them, so only the ones explicitly set in this file are enabled.
8
8
  DisabledByDefault: true
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-3.1.3
1
+ ruby-3.3.0
data/README.md CHANGED
@@ -250,10 +250,27 @@ item.public_note
250
250
  ```
251
251
 
252
252
  ### Logging
253
+
254
+ #### Using :enable_loggable
253
255
  This gem exposes a loggable interface to responses. Thus a response will respond to `loggable` and return a hash with state values that may be of use to log.
254
256
 
255
257
  As a bonus, when we enable this feature using the `enable_loggable` configuration, error messages will contain the loggable values and be formatted as JSON.
256
258
 
259
+ #### Using logging configuration.
260
+ You can configure logging via the following configurations:
261
+ * `enable_log_requests`: (`true/false`)
262
+ * `log_level`
263
+ * `log_format`
264
+ * `logger`
265
+
266
+ The logger can be any logger including the Rails.logger. This logging feature is provided through [HTTParty](https://www.rubydoc.info/github/jnunemaker/httparty/HTTParty/ClassMethods#logger-instance_method).
267
+
268
+ ### Debugging requests
269
+ You can configure debugging requests by setting the `enable_debug_output` configuration which is false by default. This feature is also provided through [HTTParty](https://www.rubydoc.info/github/jnunemaker/httparty/HTTParty/ClassMethods#debug_output-instance_method).
270
+
271
+ You can configure the `debug_output_stream` which is set to `$stderr` by default.
272
+
273
+
257
274
  ## Development
258
275
 
259
276
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/alma/bib.rb CHANGED
@@ -10,7 +10,7 @@ module Alma
10
10
  end
11
11
 
12
12
  def self.get_bibs(ids, args = {})
13
- response = HTTParty.get(
13
+ response = Net.get(
14
14
  self.bibs_base_path,
15
15
  query: { mms_id: ids_from_array(ids) }.merge(args),
16
16
  headers:,
@@ -7,7 +7,7 @@ module Alma
7
7
 
8
8
  def self.find(mms_id:, holding_id:)
9
9
  url = "#{bibs_base_path}/#{mms_id}/holdings/#{holding_id}"
10
- response = HTTParty.get(url, headers:, timeout:)
10
+ response = Net.get(url, headers:, timeout:)
11
11
  new(response)
12
12
  end
13
13
 
data/lib/alma/bib_item.rb CHANGED
@@ -18,18 +18,18 @@ module Alma
18
18
  holding_id = options.delete(:holding_id) || "ALL"
19
19
  options.select! { |k, _| PERMITTED_ARGS.include? k }
20
20
  url = "#{bibs_base_path}/#{mms_id}/holdings/#{holding_id}/items"
21
- response = HTTParty.get(url, headers:, query: options, timeout:)
21
+ response = Net.get(url, headers:, query: options, timeout:)
22
22
  BibItemSet.new(response, options.merge({ mms_id:, holding_id: }))
23
23
  end
24
24
 
25
25
  def self.find_by_barcode(barcode)
26
- response = HTTParty.get(items_base_path, headers:, query: { item_barcode: barcode }, timeout:, follow_redirects: true)
26
+ response = Net.get(items_base_path, headers:, query: { item_barcode: barcode }, timeout:, follow_redirects: true)
27
27
  new(response)
28
28
  end
29
29
 
30
30
  def self.scan(mms_id:, holding_id:, item_pid:, options: {})
31
31
  url = "#{bibs_base_path}/#{mms_id}/holdings/#{holding_id}/items/#{item_pid}"
32
- response = HTTParty.post(url, headers:, query: options)
32
+ response = Net.post(url, headers:, query: options)
33
33
  new(response)
34
34
  end
35
35
 
data/lib/alma/config.rb CHANGED
@@ -8,11 +8,35 @@ module Alma
8
8
  def self.configure()
9
9
  self.configuration ||= Configuration.new
10
10
  yield(configuration) if block_given?
11
+ on_configure
12
+ end
13
+
14
+ def self.on_configure
15
+ _configure_logging
16
+ _configure_debugging
17
+ end
18
+
19
+ def self._configure_logging
20
+ if configuration.enable_log_requests
21
+ primo_logger = configuration.logger
22
+ log_level = Alma.configuration.log_level
23
+ log_format = Alma.configuration.log_format
24
+ Net.logger primo_logger, log_level, log_format
25
+ end
26
+ end
27
+
28
+ def self._configure_debugging
29
+ if configuration.enable_debug_output
30
+ Net.debug_output configuration.debug_output_stream
31
+ end
11
32
  end
12
33
 
13
34
  class Configuration
14
35
  attr_accessor :apikey, :region, :enable_loggable
15
36
  attr_accessor :timeout, :http_retries, :logger
37
+ attr_accessor :timeout, :http_retries, :logger
38
+ attr_accessor :log_level, :log_format, :debug_output_stream
39
+ attr_accessor :enable_log_requests, :enable_debug_output
16
40
 
17
41
  def initialize
18
42
  @apikey = "TEST_API_KEY"
@@ -20,7 +44,14 @@ module Alma
20
44
  @enable_loggable = false
21
45
  @timeout = 5
22
46
  @http_retries = 3
47
+ @log_level = :info
48
+ @log_format = :logstash
23
49
  @logger = Logger.new(STDOUT)
50
+ @enable_log_requests = false
51
+ @enable_debug_output = false
52
+ @log_level = :info
53
+ @log_format = :logstash
54
+ @debug_output_stream = $stderr
24
55
  end
25
56
  end
26
57
  end
data/lib/alma/course.rb CHANGED
@@ -6,7 +6,7 @@ module Alma
6
6
  extend Forwardable
7
7
 
8
8
  def self.all_courses(args: {})
9
- response = HTTParty.get("#{courses_base_path}/courses",
9
+ response = Net.get("#{courses_base_path}/courses",
10
10
  query: args,
11
11
  headers:,
12
12
  timeout:)
data/lib/alma/fine.rb CHANGED
@@ -5,7 +5,7 @@ module Alma
5
5
  extend Alma::ApiDefaults
6
6
 
7
7
  def self.where_user(user_id, args = {})
8
- response = HTTParty.get("#{users_base_path}/#{user_id}/fees", query: args, headers:, timeout:)
8
+ response = Net.get("#{users_base_path}/#{user_id}/fees", query: args, headers:, timeout:)
9
9
  if response.code == 200
10
10
  Alma::FineSet.new(response)
11
11
  else
@@ -8,7 +8,7 @@ module Alma
8
8
  def self.get(mms_id, holding_id = nil, item_pid = nil, options = {})
9
9
  url = "#{bibs_base_path}/#{mms_id}/holdings/#{holding_id}/items/#{item_pid}/request-options"
10
10
  options.select! { |k, _| REQUEST_OPTIONS_PERMITTED_ARGS.include? k }
11
- response = HTTParty.get(url, headers:, query: options, timeout:)
11
+ response = Net.get(url, headers:, query: options, timeout:)
12
12
  new(response)
13
13
  end
14
14
 
data/lib/alma/library.rb CHANGED
@@ -5,7 +5,7 @@ module Alma
5
5
  extend Alma::ApiDefaults
6
6
 
7
7
  def self.all(args: {})
8
- response = HTTParty.get("#{configuration_base_path}/libraries", query: args, headers:, timeout:)
8
+ response = Net.get("#{configuration_base_path}/libraries", query: args, headers:, timeout:)
9
9
  if response.code == 200
10
10
  LibrarySet.new(response)
11
11
  else
@@ -14,7 +14,7 @@ module Alma
14
14
  end
15
15
 
16
16
  def self.find(library_code:, args: {})
17
- response = HTTParty.get("#{configuration_base_path}/libraries/#{library_code}", query: args, headers:, timeout:)
17
+ response = Net.get("#{configuration_base_path}/libraries/#{library_code}", query: args, headers:, timeout:)
18
18
  if response.code == 200
19
19
  AlmaRecord.new(response)
20
20
  else
data/lib/alma/loan.rb CHANGED
@@ -26,7 +26,7 @@ module Alma
26
26
  args[:expand] ||= "renewable"
27
27
  # Default to upper limit
28
28
  args[:limit] ||= 100
29
- response = HTTParty.get(
29
+ response = Net.get(
30
30
  "#{users_base_path}/#{user_id}/loans",
31
31
  query: args,
32
32
  headers:,
data/lib/alma/loan_set.rb CHANGED
@@ -39,8 +39,9 @@ module Alma
39
39
  def all
40
40
  Enumerator.new do |yielder|
41
41
  offset = 0
42
+ limit = 100
42
43
  loop do
43
- extra_args = @search_args.merge({ limit: 100, offset: })
44
+ extra_args = @search_args.merge({ limit:, offset: })
44
45
  r = (offset == 0) ? self : single_record_class.where_user(user_id, extra_args)
45
46
 
46
47
  unless r.empty?
@@ -48,7 +49,11 @@ module Alma
48
49
  offset += 100
49
50
  end
50
51
 
51
- if r.empty? || r.count < extra_args[:limit]
52
+ # TODO: r.count greater than "limit" doesn't make any sense unless the ALMA User/Loan API is broken.
53
+ # We should remove this qualification in October once Alma fixes the bug they introduced in their
54
+ # September release.
55
+ # @see https://developers.exlibrisgroup.com/forums/topic/limit-and-offset-not-being-applied-to-retrieve-user-loans-api/
56
+ if r.empty? || r.count < limit || r.count > limit
52
57
  raise StopIteration
53
58
  end
54
59
  end
data/lib/alma/location.rb CHANGED
@@ -5,7 +5,7 @@ module Alma
5
5
  extend Alma::ApiDefaults
6
6
 
7
7
  def self.all(library_code:, args: {})
8
- response = HTTParty.get("#{configuration_base_path}/libraries/#{library_code}/locations", query: args, headers:, timeout:)
8
+ response = Net.get("#{configuration_base_path}/libraries/#{library_code}/locations", query: args, headers:, timeout:)
9
9
  if response.code == 200
10
10
  LocationSet.new(response)
11
11
  else
@@ -14,7 +14,7 @@ module Alma
14
14
  end
15
15
 
16
16
  def self.find(library_code:, location_code:, args: {})
17
- response = HTTParty.get("#{configuration_base_path}/libraries/#{library_code}/locations/#{location_code}", query: args, headers:, timeout:)
17
+ response = Net.get("#{configuration_base_path}/libraries/#{library_code}/locations/#{location_code}", query: args, headers:, timeout:)
18
18
  if response.code == 200
19
19
  AlmaRecord.new(response)
20
20
  else
data/lib/alma/net.rb ADDED
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+
5
+ module Alma
6
+ class Net
7
+ include HTTParty
8
+ end
9
+ end
data/lib/alma/request.rb CHANGED
@@ -11,7 +11,7 @@ module Alma
11
11
 
12
12
  def self.submit(args)
13
13
  request = new(args)
14
- response = HTTParty.post(
14
+ response = Net.post(
15
15
  "#{bibs_base_path}/#{request.mms_id}/requests",
16
16
  query: { user_id: request.user_id },
17
17
  headers:,
@@ -140,7 +140,7 @@ module Alma
140
140
  class ItemRequest < BibRequest
141
141
  def self.submit(args)
142
142
  request = new(args)
143
- response = HTTParty.post(
143
+ response = Net.post(
144
144
  "#{bibs_base_path}/#{request.mms_id}/holdings/#{request.holding_id}/items/#{request.item_pid}/requests",
145
145
  query: { user_id: request.user_id },
146
146
  headers:,
@@ -157,6 +157,8 @@ module Alma
157
157
  end
158
158
 
159
159
  def additional_validation!(args)
160
+ return unless args.fetch(:request_type) == "DIGITIZATION"
161
+
160
162
  args.fetch(:description) do
161
163
  raise ArgumentError.new(
162
164
  ":description option must be specified when request_type is DIGITIZATION"
@@ -23,7 +23,7 @@ module Alma
23
23
  def self.get(mms_id, options = {})
24
24
  url = "#{bibs_base_path}/#{mms_id}/request-options"
25
25
  options.select! { |k, _| REQUEST_OPTIONS_PERMITTED_ARGS.include? k }
26
- response = HTTParty.get(url, headers:, query: options, timeout:)
26
+ response = Net.get(url, headers:, query: options, timeout:)
27
27
  new(response)
28
28
  end
29
29
 
data/lib/alma/user.rb CHANGED
@@ -9,7 +9,7 @@ module Alma
9
9
 
10
10
  def self.find(user_id, args = {})
11
11
  args[:expand] ||= "fees,requests,loans"
12
- response = HTTParty.get("#{self.users_base_path}/#{user_id}", query: args.compact_blank, headers:, timeout:)
12
+ response = Net.get("#{self.users_base_path}/#{user_id}", query: args.compact_blank, headers:, timeout:)
13
13
 
14
14
  Alma::User.new response
15
15
  end
@@ -22,7 +22,7 @@ module Alma
22
22
  def self.authenticate(args)
23
23
  user_id = args.delete(:user_id) { raise ArgumentError }
24
24
  args.merge!({ op: "auth" })
25
- response = HTTParty.post("#{users_base_path}/#{user_id}", query: args, headers:, timeout:)
25
+ response = Net.post("#{users_base_path}/#{user_id}", query: args, headers:, timeout:)
26
26
  response.code == 204
27
27
  end
28
28
 
@@ -80,7 +80,7 @@ module Alma
80
80
 
81
81
  # Persist the user in it's current state back to Alma
82
82
  def save!
83
- response = HTTParty.put("#{users_base_path}/#{id}", timeout:, headers:, body: to_json)
83
+ response = Net.put("#{users_base_path}/#{id}", timeout:, headers:, body: to_json)
84
84
  get_body_from(response)
85
85
  end
86
86
 
@@ -154,7 +154,7 @@ module Alma
154
154
  loan_id = args.delete(:loan_id) { raise ArgumentError }
155
155
  user_id = args.delete(:user_id) { raise ArgumentError }
156
156
  params = { op: "renew" }
157
- response = HTTParty.post("#{users_base_path}/#{user_id}/loans/#{loan_id}", query: params, headers:)
157
+ response = Net.post("#{users_base_path}/#{user_id}/loans/#{loan_id}", query: params, headers:)
158
158
  RenewalResponse.new(response)
159
159
  end
160
160
 
@@ -175,7 +175,7 @@ module Alma
175
175
  def self.send_payment(args)
176
176
  user_id = args.delete(:user_id) { raise ArgumentError }
177
177
  params = { op: "pay", amount: "ALL", method: "ONLINE" }
178
- response = HTTParty.post("#{users_base_path}/#{user_id}/fees/all", query: params, headers:)
178
+ response = Net.post("#{users_base_path}/#{user_id}/fees/all", query: params, headers:)
179
179
  PaymentResponse.new(response)
180
180
  end
181
181
 
@@ -7,7 +7,7 @@ module Alma
7
7
  def self.where_user(user_id, args = {})
8
8
  # Default to upper limit
9
9
  args[:limit] ||= 100
10
- response = HTTParty.get(
10
+ response = Net.get(
11
11
  "#{users_base_path}/#{user_id}/requests",
12
12
  query: args,
13
13
  headers:,
data/lib/alma/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Alma
4
- VERSION = "0.4.1"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/alma.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "alma/version"
4
+ require "alma/net"
4
5
  require "alma/config"
5
6
  require "alma/api_defaults"
6
7
  require "alma/error"
@@ -34,7 +35,5 @@ require "alma/course_set"
34
35
  require "alma/course"
35
36
 
36
37
  module Alma
37
- require "httparty"
38
-
39
38
  ROOT = File.dirname __dir__
40
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jennifer Anton
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2023-09-06 00:00:00.000000000 Z
13
+ date: 2024-04-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
@@ -246,6 +246,7 @@ files:
246
246
  - lib/alma/loan_set.rb
247
247
  - lib/alma/location.rb
248
248
  - lib/alma/location_set.rb
249
+ - lib/alma/net.rb
249
250
  - lib/alma/payment_response.rb
250
251
  - lib/alma/renewal_response.rb
251
252
  - lib/alma/request.rb