Class: Alma::RenewalResponse
- Inherits:
-
Object
- Object
- Alma::RenewalResponse
- Defined in:
- lib/alma/renewal_response.rb
Instance Method Summary collapse
- #due_date ⇒ Object
- #due_date_pretty ⇒ Object
- #error_message ⇒ Object
- #has_error? ⇒ Boolean
-
#initialize(response) ⇒ RenewalResponse
constructor
A new instance of RenewalResponse.
- #item_title ⇒ Object
- #loggable ⇒ Object
- #message ⇒ Object
- #renewed? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ RenewalResponse
Returns a new instance of RenewalResponse.
4 5 6 7 8 |
# File 'lib/alma/renewal_response.rb', line 4 def initialize(response) @raw_response = response @response = response.parsed_response @success = response.has_key?('loan_id') end |
Instance Method Details
#due_date ⇒ Object
23 24 25 |
# File 'lib/alma/renewal_response.rb', line 23 def due_date @response.fetch('due_date', '') end |
#due_date_pretty ⇒ Object
28 29 30 |
# File 'lib/alma/renewal_response.rb', line 28 def due_date_pretty Time.parse(due_date).strftime('%m-%e-%y %H:%M') end |
#error_message ⇒ Object
48 49 50 |
# File 'lib/alma/renewal_response.rb', line 48 def @response unless renewed? end |
#has_error? ⇒ Boolean
19 20 21 |
# File 'lib/alma/renewal_response.rb', line 19 def has_error? !renewed? end |
#item_title ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/alma/renewal_response.rb', line 32 def item_title if renewed? @response['title'] else 'This Item' end end |
#loggable ⇒ Object
10 11 12 13 |
# File 'lib/alma/renewal_response.rb', line 10 def loggable { uri: @raw_response&.request&.uri.to_s }.select { |k, v| !(v.nil? || v.empty?) } end |
#message ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/alma/renewal_response.rb', line 40 def if renewed? "#{item_title} is now due #{due_date}" else "#{item_title} could not be renewed." end end |
#renewed? ⇒ Boolean
15 16 17 |
# File 'lib/alma/renewal_response.rb', line 15 def renewed? @success end |