Class: Alma::RenewalResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/alma/renewal_response.rb

Instance Method Summary collapse

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_dateObject



24
25
26
# File 'lib/alma/renewal_response.rb', line 24

def due_date
  @response.fetch("due_date", "")
end

#due_date_prettyObject



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_messageObject



49
50
51
# File 'lib/alma/renewal_response.rb', line 49

def error_message
  @response unless renewed?
end

#has_error?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/alma/renewal_response.rb', line 20

def has_error?
  !renewed?
end

#item_titleObject



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

#loggableObject



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

#messageObject



41
42
43
44
45
46
47
# File 'lib/alma/renewal_response.rb', line 41

def message
  if renewed?
    "#{item_title} is now due #{due_date}"
  else
    "#{item_title} could not be renewed."
  end
end

#renewed?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/alma/renewal_response.rb', line 16

def renewed?
  @success
end