alma 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 210d45982a6c339d9b8c170a73077be4f56bcf4eaa989debe95d2f9d97897c0e
4
- data.tar.gz: 1b988140c47bc0974e617cc1131aee0b82dfbcd50ce20d408fbd2a969cf180c7
3
+ metadata.gz: 55ea295ada19c46e1c3c157ded8cdf0997d62e744913b513a288c45f2239cdce
4
+ data.tar.gz: 213034074451c8d5388abdf9a6ee6385b56432adab463fa3e9a5d39b8e3dd953
5
5
  SHA512:
6
- metadata.gz: 1667314072be96beb05c3f389c5240142ff5e0f44be0eed44d2240653ad4dd38f07a221b2ab3235921e37e7620e4518128e1b8806880daadffc9f570bbccd773
7
- data.tar.gz: b98783202cf24c6a33c0c249f70d9f55a715b611c89a3249d4cf14a1352f2dca476123315649f9d3f624b1533fa0547d285605af309cfab8c537a1b6d81db85b
6
+ metadata.gz: 3c9d95eb4c80778b3d132ed790a7a615c775a7c650e38936cc588782efabaa1a2e393b39ef94ea90acecee05e514c625b0bace832cbbf6aa9e885ecff77c32bf
7
+ data.tar.gz: 55060edf008d1ee5c78a5d598daaa03666b3a423960e03fdea668aa7976e839b31385d1f4d2577f945cd4a66d1f40f6a20ca7fd19e0883fb5ced62a8c0fca420
@@ -21,7 +21,8 @@ module Alma
21
21
  @mms_id = @options.delete(:mms_id)
22
22
 
23
23
  validate(response)
24
- @items = parsed.fetch(key, []).map { |item| single_record_class.new(item) }
24
+ @items = (parsed.fetch(key, []) || [])
25
+ .map { |item| single_record_class.new(item) }
25
26
  end
26
27
 
27
28
  def loggable
data/lib/alma/error.rb CHANGED
@@ -10,7 +10,7 @@ module Alma::Error
10
10
  end
11
11
 
12
12
  def error
13
- @response.fetch("web_service_result", {})
13
+ @response.fetch("web_service_result", {}) || {}
14
14
  end
15
15
  end
16
16
 
data/lib/alma/fine_set.rb CHANGED
@@ -12,7 +12,7 @@ module Alma
12
12
  @raw_response = raw_response
13
13
  @response = raw_response.parsed_response
14
14
  validate(raw_response)
15
- @results = @response.fetch(key, [])
15
+ @results = (@response.fetch(key, []) || [])
16
16
  .map { |item| single_record_class.new(item) }
17
17
  end
18
18
 
@@ -9,7 +9,7 @@ module Alma
9
9
  end
10
10
 
11
11
  def results
12
- @results ||= @response.fetch(key, [])
12
+ @results ||= (@response.fetch(key, []) || [])
13
13
  .map { |item| single_record_class.new(item) }
14
14
  end
15
15
 
data/lib/alma/loan_set.rb CHANGED
@@ -16,8 +16,8 @@ module Alma
16
16
  @response = raw_response.parsed_response
17
17
  @search_args = search_args
18
18
  validate(raw_response)
19
- @results = @response.fetch(key, [])
20
- .map { |item| single_record_class.new(item) }
19
+ @results = @response.fetch(key, []) || []
20
+ @results.map! { |item| single_record_class.new(item) }
21
21
  # args passed to the search that returned this set
22
22
  # such as limit, expand, order_by, etc
23
23
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Alma
4
+ class PaymentResponse
5
+ def initialize(response)
6
+ @raw_response = response
7
+ @response = response.parsed_response
8
+ @success = response["total_sum"] == 0.0
9
+ end
10
+
11
+ def loggable
12
+ { uri: @raw_response&.request&.uri.to_s
13
+ }.select { |k, v| !(v.nil? || v.empty?) }
14
+ end
15
+
16
+ def paid?
17
+ @success
18
+ end
19
+
20
+ def has_payment_error?
21
+ !paid?
22
+ end
23
+
24
+ def payment_message
25
+ if paid?
26
+ "Your balance has been paid."
27
+ else
28
+ "There was a problem processing your payment. Please contact the library for assistance."
29
+ end
30
+ end
31
+
32
+ def error_message
33
+ @response unless paid?
34
+ end
35
+ end
36
+ end
@@ -14,8 +14,8 @@ module Alma
14
14
  @raw_response = raw_response
15
15
  @response = raw_response.parsed_response
16
16
  validate(raw_response)
17
- @results = @response.fetch(key, [])
18
- .map { |item| single_record_class.new(item) }
17
+ @results = @response.fetch(key, []) || []
18
+ @results.map! { |item| single_record_class.new(item) }
19
19
  end
20
20
 
21
21
  def loggable
@@ -22,7 +22,7 @@ class Alma::ResultSet
22
22
  end
23
23
 
24
24
  def each
25
- @results ||= @response.fetch(key, [])
25
+ @results ||= (@response.fetch(key, []) || [])
26
26
  .map { |item| single_record_class.new(item) }
27
27
  end
28
28
 
data/lib/alma/user.rb CHANGED
@@ -26,7 +26,6 @@ module Alma
26
26
  response.code == 204
27
27
  end
28
28
 
29
-
30
29
  # The User object can respond directly to Hash like access of attributes
31
30
  def_delegators :response, :[], :[]=, :has_key?, :keys, :to_json
32
31
 
@@ -58,7 +57,7 @@ module Alma
58
57
  end
59
58
 
60
59
  def total_fines
61
- response.dig("fees", "value") || "0"
60
+ response.dig("fees", "value") || 0.0
62
61
  end
63
62
 
64
63
  def total_requests
@@ -69,7 +68,6 @@ module Alma
69
68
  response.dig("loans", "value") || "0"
70
69
  end
71
70
 
72
-
73
71
  # Access the top level JSON attributes as object methods
74
72
  def method_missing(name)
75
73
  return response[name.to_s] if has_key?(name.to_s)
@@ -80,14 +78,12 @@ module Alma
80
78
  has_key?(name.to_s) || super
81
79
  end
82
80
 
83
-
84
81
  # Persist the user in it's current state back to Alma
85
82
  def save!
86
83
  response = HTTParty.put("#{users_base_path}/#{id}", timeout: timeout, headers: headers, body: to_json)
87
84
  get_body_from(response)
88
85
  end
89
86
 
90
-
91
87
  def fines
92
88
  Alma::Fine.where_user(id)
93
89
  end
@@ -96,7 +92,6 @@ module Alma
96
92
  Alma::UserRequest.where_user(id)
97
93
  end
98
94
 
99
-
100
95
  def loans(args = {})
101
96
  @loans ||= Alma::Loan.where_user(id, args)
102
97
  end
@@ -108,7 +103,6 @@ module Alma
108
103
  end
109
104
  end
110
105
 
111
-
112
106
  def renew_multiple_loans(loan_ids)
113
107
  loan_ids.map { |id| renew_loan(id) }
114
108
  end
@@ -148,8 +142,6 @@ module Alma
148
142
  "#{preferred_first_name} #{preferred_middle_name} #{preferred_last_name} #{preferred_suffix}"
149
143
  end
150
144
 
151
-
152
-
153
145
  private
154
146
 
155
147
  # Attempts to renew a single item for a user
@@ -177,11 +169,20 @@ module Alma
177
169
  loan_ids.map { |id| Alma::User.send_loan_renewal_request(args.merge(loan_id: id)) }
178
170
  end
179
171
 
172
+ # Attempts to pay total fines for a user
173
+ # @param [Hash] args
174
+ # @option args [String] :user_id The unique id of the user
175
+ def self.send_payment(args)
176
+ user_id = args.delete(:user_id) { raise ArgumentError }
177
+ params = { op: "pay", amount: "ALL", method: "ONLINE" }
178
+ response = HTTParty.post("#{users_base_path}/#{user_id}/fees/all", query: params, headers: headers)
179
+ PaymentResponse.new(response)
180
+ end
181
+
180
182
  def get_body_from(response)
181
183
  JSON.parse(response.body)
182
184
  end
183
185
 
184
-
185
186
  def self.users_base_path
186
187
  "https://api-na.hosted.exlibrisgroup.com/almaws/v1/users"
187
188
  end
data/lib/alma/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Alma
4
- VERSION = "0.3.3"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/alma.rb CHANGED
@@ -17,6 +17,7 @@ require "alma/fine"
17
17
  require "alma/bib_set"
18
18
  require "alma/request_set"
19
19
  require "alma/renewal_response"
20
+ require "alma/payment_response"
20
21
  require "alma/availability_response"
21
22
  require "alma/bib_item"
22
23
  require "alma/request_options"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jennifer Anton
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-12-02 00:00:00.000000000 Z
13
+ date: 2022-11-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ezwadl
@@ -260,6 +260,7 @@ files:
260
260
  - lib/alma/loan_set.rb
261
261
  - lib/alma/location.rb
262
262
  - lib/alma/location_set.rb
263
+ - lib/alma/payment_response.rb
263
264
  - lib/alma/renewal_response.rb
264
265
  - lib/alma/request.rb
265
266
  - lib/alma/request_options.rb