Class: Skala::AlephAdapter::RenewUserLoans

Inherits:
Skala::Adapter::RenewUserLoans show all
Includes:
parentparent::ResolveUser
Defined in:
lib/skala/aleph_adapter/renew_user_loans.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(username, loan_ids = nil, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/skala/aleph_adapter/renew_user_loans.rb', line 9

def call(username, loan_ids = nil, options = {})
  resolved_user_id = resolve_user(username)

  if loan_ids.blank? # renew all
    raw_aleph_response = adapter.restful_api.patron(resolved_user_id).circulationActions.loans.post
    successfully_renewed_loans_xpath = "//loan/status[contains(text(), 'success')]/parent::*"

    adapter.class::RenewUserLoans::Result.new(
      renewed_loans: begin
        Nokogiri::XML(raw_aleph_response).xpath(successfully_renewed_loans_xpath).map do |_loan|
          {
            id: _loan.attr("id"),
            due_date: new_due_date(_loan)
          }
        end
      end,
      source: raw_aleph_response
    )
  else
    raise "Unimplemented"
  end
end