Sha256: ef0ea21ebbcf39c928ec398dd00c8232c3154e3a2bd5dc6e8149d3090f3dcd90
Contents?: true
Size: 1.83 KB
Versions: 1
Compression:
Stored size: 1.83 KB
Contents
require "nokogiri" require "skala/adapter/get_user_inter_library_loans" require_relative "./resolve_user" require_relative "../aleph_adapter" class Skala::AlephAdapter::GetUserInterLibraryLoans < Skala::Adapter::GetUserInterLibraryLoans include parent::ResolveUser def call(username, options = {}) resolved_user_id = resolve_user(username) raw_aleph_response = adapter.restful_api.patron(resolved_user_id).circulationActions.requests.ill.get(view: :brief) if raw_aleph_response.include?("<error>") return nil else self.class::Result.new( inter_library_loans: Nokogiri::XML(raw_aleph_response).xpath("//ill-request").map do |_ill_request| { id: id(_ill_request), due_date: due_date(_ill_request), record: { creator: creator(_ill_request), id: record_id(_ill_request), title: title(_ill_request), year_of_publication: year_of_publication(_ill_request) }, renewable: renewable(_ill_request) } end, source: raw_aleph_response ) end end private def creator(element) element.at_xpath(".//z13-author").try(:content).presence.try(:split, ";").try(:map, &:strip) end def id(element) element.attr("href")[/[^\/]+\Z/][/\A[^?]+/] end def due_date(element) if _due_date = element.at_xpath(".//z36-due-date|.//z36h-due-date").try(:content) Date.strptime(_due_date, "%Y%m%d") end end def record_id(element) element.at_xpath(".//z410-doc-number").try(:content).presence end def renewable(element) element.attr("renew") == "Y" end def title(element) element.at_xpath(".//z13-title").try(:content).presence end def year_of_publication(element) element.at_xpath(".//z13-year").try(:content).presence end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
skala-1.1.0 | lib/skala/aleph_adapter/get_user_inter_library_loans.rb |