Class: Skala::AlephAdapter::GetRecordItems

Inherits:
Skala::Adapter::GetRecordItems show all
Includes:
parentparent::ResolveUser
Defined in:
lib/skala/aleph_adapter/get_record_items.rb

Instance Attribute Summary

Attributes inherited from Skala::Adapter::Operation

#adapter

Instance Method Summary collapse

Methods inherited from Skala::Adapter::Operation

#initialize

Constructor Details

This class inherits a constructor from Skala::Adapter::Operation

Instance Method Details

#call(document_number, options = {}) ⇒ Object



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
37
38
39
40
# File 'lib/skala/aleph_adapter/get_record_items.rb', line 9

def call(document_number, options = {})
  document_base = options[:document_base] || @adapter.default_document_base
  record_id = "#{document_base}#{document_number}"
  resolved_user_id = resolve_user(options[:username]) if options[:username]

  aleph_options = { patron: resolved_user_id, view: :full }.compact
  raw_aleph_response = adapter.restful_api.record(record_id).items.get(aleph_options)

  if raw_aleph_response.include?("<error>")
    return nil
  else
    self.class::Result.new(
      items: Nokogiri::XML(raw_aleph_response).xpath("//item").map do |_item|
        {
          id: id(_item),
          availability: availability(_item),
          due_date: due_date(_item),
          expected_date: expected_date(_item),
          hold_request_can_be_created: hold_request_can_be_created(_item),
          item_status: item_status(_item),
          number_of_hold_requests: number_of_hold_requests(_item),
          note: note(_item),
          record: {
            id: document_number
          },
          status: status(_item)
        }
      end,
      source: raw_aleph_response
    )
  end
end