Sha256: 47c37b1f8120b0834925513fdf1908088bc25ac7068233920239b5e1b667e239

Contents?: true

Size: 929 Bytes

Versions: 5

Compression:

Stored size: 929 Bytes

Contents

require 'json'
require 'berkeley_library/util'
require 'berkeley_library/holdings/oclc_number'
require 'berkeley_library/holdings/hathi_trust/config'

module BerkeleyLibrary
  module Holdings
    module HathiTrust
      module RecordUrlRequestBase
        include BerkeleyLibrary::Util

        protected

        def volumes_base_uri
          URIs.append(Config.base_uri, 'volumes', 'brief')
        end

        def find_record_url(json_obj, oclc_number)
          return unless (records = json_obj['records'])
          return unless (record = find_record(records, oclc_number))

          record['recordURL']
        end

        def find_record(records, oclc_number)
          return if records.empty?

          records.values.find do |rec|
            (oclc_nums = rec['oclcs']) &&
              oclc_nums.include?(oclc_number) &&
              rec.key?('recordURL')
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
berkeley_library-holdings-1.0.5 lib/berkeley_library/holdings/hathi_trust/record_url_request_base.rb
berkeley_library-holdings-1.0.4 lib/berkeley_library/holdings/hathi_trust/record_url_request_base.rb
berkeley_library-holdings-1.0.3 lib/berkeley_library/holdings/hathi_trust/record_url_request_base.rb
berkeley_library-holdings-1.0.2 lib/berkeley_library/holdings/hathi_trust/record_url_request_base.rb
berkeley_library-holdings-1.0.1 lib/berkeley_library/holdings/hathi_trust/record_url_request_base.rb