alma 0.4.1 → 0.5.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/.circleci/config.yml +1 -1
- data/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/README.md +17 -0
- data/lib/alma/bib.rb +1 -1
- data/lib/alma/bib_holding.rb +1 -1
- data/lib/alma/bib_item.rb +3 -3
- data/lib/alma/config.rb +31 -0
- data/lib/alma/course.rb +1 -1
- data/lib/alma/fine.rb +1 -1
- data/lib/alma/item_request_options.rb +1 -1
- data/lib/alma/library.rb +2 -2
- data/lib/alma/loan.rb +1 -1
- data/lib/alma/loan_set.rb +7 -2
- data/lib/alma/location.rb +2 -2
- data/lib/alma/net.rb +9 -0
- data/lib/alma/request.rb +4 -2
- data/lib/alma/request_options.rb +1 -1
- data/lib/alma/user.rb +5 -5
- data/lib/alma/user_request.rb +1 -1
- data/lib/alma/version.rb +1 -1
- data/lib/alma.rb +1 -2
- metadata +3 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: b6269246a05d81573e9b8037da0f8d4149a51acdf6635951efe80b96c5d30458
         | 
| 4 | 
            +
              data.tar.gz: 81d9cbb84cb1c7899b1b60c4b2dc4c5fbafa6f7c8d250b0a960d0fa72b245469
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5289a52394d811d85a5fac07224484e4df005e4f14e6854df5326d1bb096279e19991d2a7289f1e268a0d6e66fc76a3f56799460395da1efc1c1539e81fae358
         | 
| 7 | 
            +
              data.tar.gz: adcb02a15f418c088f70e933979946e522ceb72417b05c428a499fc500cc793a7caca76c15a0cd02080075e881e4af68184644e17740a253ce90b9b7e7331251
         | 
    
        data/.circleci/config.yml
    CHANGED
    
    
    
        data/.rubocop.yml
    CHANGED
    
    | @@ -2,7 +2,7 @@ require: | |
| 2 2 | 
             
              - rubocop-rails
         | 
| 3 3 |  | 
| 4 4 | 
             
            AllCops:
         | 
| 5 | 
            -
              TargetRubyVersion: 3. | 
| 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 | 
            +
            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
    
    
    
        data/lib/alma/bib_holding.rb
    CHANGED
    
    
    
        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 =  | 
| 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 =  | 
| 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 =  | 
| 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
    
    
    
        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 =  | 
| 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 =  | 
| 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 =  | 
| 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 =  | 
| 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
    
    
    
        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 | 
| 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 | 
            -
                       | 
| 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 =  | 
| 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 =  | 
| 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
    
    
    
        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 =  | 
| 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 =  | 
| 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"
         | 
    
        data/lib/alma/request_options.rb
    CHANGED
    
    | @@ -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 =  | 
| 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 =  | 
| 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 =  | 
| 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 =  | 
| 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 =  | 
| 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 =  | 
| 178 | 
            +
                    response = Net.post("#{users_base_path}/#{user_id}/fees/all", query: params, headers:)
         | 
| 179 179 | 
             
                    PaymentResponse.new(response)
         | 
| 180 180 | 
             
                  end
         | 
| 181 181 |  | 
    
        data/lib/alma/user_request.rb
    CHANGED
    
    
    
        data/lib/alma/version.rb
    CHANGED
    
    
    
        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 | 
            +
              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:  | 
| 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
         |