Class: Skala::AlephAdapter::RenewUserLoan

Inherits:
Skala::Adapter::RenewUserLoan show all
Includes:
parentparent::ResolveUser
Defined in:
lib/skala/aleph_adapter/renew_user_loan.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_id, options = {}) ⇒ Object



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

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

  raw_aleph_response = adapter.restful_api.patron(resolved_user_id).circulationActions.loans(loan_id).post
  reply_code = Nokogiri::XML(raw_aleph_response).at_xpath("//reply-code").try(:content).try(:to_i)

  if reply_code == 0
    adapter.class::RenewUserLoan::Result.new(
      source: raw_aleph_response
    )
  else
    if reply_code == 28
      raise self.class::RenewFailedError
    else
      raise adapter.class::RequestFailedError
    end
  end
end