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.
5 6 7 8 9 |
# File 'lib/alma/renewal_response.rb', line 5 def initialize(response) @raw_response = response @response = response.parsed_response @success = response.has_key?("loan_id") end |
Instance Method Details
#due_date ⇒ Object
24 25 26 |
# File 'lib/alma/renewal_response.rb', line 24 def due_date @response.fetch("due_date", "") end |
#due_date_pretty ⇒ Object
29 30 31 |
# File 'lib/alma/renewal_response.rb', line 29 def due_date_pretty Time.parse(due_date).strftime("%m-%e-%y %H:%M") end |
#error_message ⇒ Object
49 50 51 |
# File 'lib/alma/renewal_response.rb', line 49 def @response unless renewed? end |
#has_error? ⇒ Boolean
20 21 22 |
# File 'lib/alma/renewal_response.rb', line 20 def has_error? !renewed? end |
#item_title ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/alma/renewal_response.rb', line 33 def item_title if renewed? @response["title"] else "This Item" end end |
#loggable ⇒ Object
11 12 13 14 |
# File 'lib/alma/renewal_response.rb', line 11 def loggable { uri: @raw_response&.request&.uri.to_s }.select { |k, v| !(v.nil? || v.empty?) } end |
#message ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/alma/renewal_response.rb', line 41 def if renewed? "#{item_title} is now due #{due_date}" else "#{item_title} could not be renewed." end end |
#renewed? ⇒ Boolean
16 17 18 |
# File 'lib/alma/renewal_response.rb', line 16 def renewed? @success end |