Module: Median::Aleph::Hold

Included in:
Median::Aleph
Defined in:
lib/median/aleph/hold.rb

Instance Method Summary collapse

Instance Method Details

#cancel_hold(patron_id, hold_id) ⇒ Object



67
68
69
70
71
72
# File 'lib/median/aleph/hold.rb', line 67

def cancel_hold(patron_id, hold_id)
  url = "#{Median.config.aleph_rest_service_base_url}/patron/#{patron_id}/circulationActions/requests/holds/#{hold_id}"
  xml = delete_url(url)
  result = xml.at_xpath('//reply-text').try(:content).try(:downcase)
  return result == 'ok'
end

#create_hold(patron_id, record_id) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/median/aleph/hold.rb', line 38

def create_hold(patron_id, record_id)
  # First, get the group list and fetch the ID for group 0
  group0_id = get_hold_group0_id(patron_id, record_id)
  if group0_id.present?
    url = "#{Median.config.aleph_rest_service_base_url}/patron/#{patron_id}/record/#{record_id}/holds/#{group0_id}"

    data = <<-XML
      <hold-request-parameters>
        <pickup-location>P0001</pickup-location>
        <start-interest-date>#{Date.today.strftime('%Y%m%d')}</start-interest-date>
        <last-interest-date>#{(Date.today + 1.year).strftime('%Y%m%d')}</last-interest-date>
        <rush>N</rush>
      </hold-request-parameters>
    XML

    # Optional XML Fields for the hold request.
    # <sub-author>Additional Author Information</sub-author>
    # <sub-title>Additional Title Information</sub-title>
    # <pages>Addtional Pages Information</pages>
    # <note-1>Additional Note</note-1>
    # <note-2>Addtional Note</note-2>

    xml    = put_url(url, post_xml: data)
    result = xml.at_xpath('//reply-text').try(:content).try(:downcase)
    return result == 'ok'
  end
  false
end

#get_holds(patron_id) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/median/aleph/hold.rb', line 4

def get_holds(patron_id)
  # patron_id = 'COPA99001517'

  holds = []

  # load holds
  url = "#{Median.config.aleph_rest_service_base_url}/patron/#{patron_id}/circulationActions/requests/holds"
  xml = get_url(url, view: 'full')

  # Rails.logger.info xml

  # parse holds
  holds = xml.xpath('//hold-request').collect do |hold_xml|
    hold            = OpenStruct.new()
    hold.id         = hold_xml.attribute('href').try(:content).try(:split, '/').try(:last)
    hold.can_cancel = (hold_xml.attribute('delete').try(:content).try(:upcase) == 'Y') ? true : false
    open_date       = hold_xml.at_xpath('./z37/z37-open-date').try(:content)
    hold.open_date  = open_date.present? ? Date.strptime(open_date, '%Y%m%d') : nil
    queue_pos       = hold_xml.at_xpath('./status').try(:content).try(:match, /position ([0-9]+)/i).try(:[], 1).to_i
    hold.queue_pos  = queue_pos
    due_date        = hold_xml.at_xpath('./status').try(:content).try(:match, /due date ([0-9]+\/[0-9]+\/[0-9]+)/i).try(:[], 1)
    hold.due_date   = due_date.present? ? Date.strptime(due_date, '%d/%m/%y') : nil
    hold.doc_id     = hold_xml.at_xpath('./z13/z13-doc-number').try(:content)
    hold.author     = hold_xml.at_xpath('./z13/z13-author').try(:content)
    hold.title      = hold_xml.at_xpath('./z13/z13-title').try(:content)
    hold.year       = hold_xml.at_xpath('./z13/z13-year').try(:content)
    hold.signature  = hold_xml.at_xpath('./z13/z13-call-no').try(:content)

    hold
  end

  return holds
end