Sha256: 407380ce723d3802b5f61b468327f0edfef8558f47aa0b527bb93a33b896571d

Contents?: true

Size: 929 Bytes

Versions: 4

Compression:

Stored size: 929 Bytes

Contents

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

module BerkeleyLibrary
  module Location
    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

4 entries across 4 versions & 1 rubygems

Version Path
berkeley_library-location-4.1.0 lib/berkeley_library/location/hathi_trust/record_url_request_base.rb
berkeley_library-location-4.0.0 lib/berkeley_library/location/hathi_trust/record_url_request_base.rb
berkeley_library-location-3.0.0 lib/berkeley_library/location/hathi_trust/record_url_request_base.rb
berkeley_library-location-2.0.0 lib/berkeley_library/location/hathi_trust/record_url_request_base.rb