alma 0.4.2 → 0.5.1

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: ffe7f9e2bafe164f38d89d6ca0c4b97d13eb778e9e59dbe7995aa6622fe0dfb5
4
- data.tar.gz: e887790912286f3750b83f34435a2e9870a57ca56f9cb85de971c64682967964
3
+ metadata.gz: dc037cc120cbf6b68ed5a42c6bfbb15e319f1e6fddea7f66ca93c11be2df5397
4
+ data.tar.gz: 3627c391a4512585d23fbd97f126fe3ce7e05801fdc927b5dc0dd0c3351cfe2f
5
5
  SHA512:
6
- metadata.gz: 2e7d1d3246dda68dc81d5ab05356d73969421053b20a830181d937239d3e6446cba8f7e6f9ff805673693b287a0b6549a1f6c54ac0b11b172bcaa85449f844d6
7
- data.tar.gz: cf3ba3362fd3809039df685cffe2b4b9d3b8a9f02bbd0968fca761c8d72bf3bb41e0be542574d6acef3bfc81e246b097596db26a974acb1f8fda444cb85a8257
6
+ metadata.gz: 8d115b3cb161939836de8527c9365619b1399004a12e98ac69fed5a097639fff6c670ac9ddf15e234dd8dcea78665dd6400dfd08891a3b733311757c4e4b94e3
7
+ data.tar.gz: 30deded89f0cfaf86844ea872ad883f13a248753838998ab10b3bf46cf24c44533d346b7813bd135c20cf181343da0601207b872eb71f5708552804804a63f74
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,24 @@ 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
+ def self.find_one(mms_id:, holding_id:, item_pid:, options: {})
26
+ url = "#{bibs_base_path}/#{mms_id}/holdings/#{holding_id}/items/#{item_pid}"
27
+ response = Net.get(url, headers:, query: options, timeout:)
28
+ new(response)
29
+ end
30
+
25
31
  def self.find_by_barcode(barcode)
26
- response = HTTParty.get(items_base_path, headers:, query: { item_barcode: barcode }, timeout:, follow_redirects: true)
32
+ response = Net.get(items_base_path, headers:, query: { item_barcode: barcode }, timeout:, follow_redirects: true)
27
33
  new(response)
28
34
  end
29
35
 
30
36
  def self.scan(mms_id:, holding_id:, item_pid:, options: {})
31
37
  url = "#{bibs_base_path}/#{mms_id}/holdings/#{holding_id}/items/#{item_pid}"
32
- response = HTTParty.post(url, headers:, query: options)
38
+ response = Net.post(url, headers:, query: options)
33
39
  new(response)
34
40
  end
35
41
 
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/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.2"
4
+ VERSION = "0.5.1"
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.2
4
+ version: 0.5.1
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-29 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
@@ -279,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
279
280
  - !ruby/object:Gem::Version
280
281
  version: '0'
281
282
  requirements: []
282
- rubygems_version: 3.4.19
283
+ rubygems_version: 3.5.9
283
284
  signing_key:
284
285
  specification_version: 4
285
286
  summary: Client for Ex Libris Alma Web Services