alma 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e55ff048167a0ab10d80f1480ba2b18cc9fdb10
4
- data.tar.gz: 87f0c5b9c23ac7a7c3c5927866f6f204db71656b
3
+ metadata.gz: 205918f513cfea340ea21733aebf97f9028a87ac
4
+ data.tar.gz: c8e0ada2ffcdd3cd1742bf076be8ee8416ec9c76
5
5
  SHA512:
6
- metadata.gz: f047816c46187fc7ed8521156cfe4b5be6aa192f6fa1f67bf68f2330ec8a206d1423ace8d9232eabb7bc496f9472d1cfc89a1289f14aa67445d533949f02f603
7
- data.tar.gz: 5912e6b39e09e6c6f5b29ac70e8223eaf1b2a343524b2f7a774641c63c452e63e8bf55b14ec4e2c6d2ec26eaeeffb469a4006562b24373b55bd13b4164981e5b
6
+ metadata.gz: b1e361f47c0f0b3feebf760111b3760ff7891aec3b040a697a79bbe827d5464a23d763350f04f14593c242bda1169713ff4a36d43140a6658969e8a5af7b8c97
7
+ data.tar.gz: 12b24d9df96c5c796324e4f3fee471883f77fd78079402e740b04b25a466d4fc2fa609fb7ef31ecb2ad7273af0517faa8739ac1881ec5fd6ae0f2985f5881522
data/README.md CHANGED
@@ -38,7 +38,7 @@ Now you can access those configuration attributes with `Alma.configuration.apike
38
38
  ### Making Requests
39
39
 
40
40
  #### Get a list of Users
41
- ```ruby
41
+ ```ruby
42
42
  users = Alma::User.find
43
43
 
44
44
  users.total count
@@ -46,10 +46,10 @@ Now you can access those configuration attributes with `Alma.configuration.apike
46
46
 
47
47
  users.list.first.id
48
48
  > 123456789
49
- ```
49
+ ```
50
50
 
51
51
  #### Get a Single user
52
- ```ruby
52
+ ```ruby
53
53
  user = Alma::User.find({:user_id => 123456789})
54
54
 
55
55
  user.first_name
@@ -57,30 +57,97 @@ Now you can access those configuration attributes with `Alma.configuration.apike
57
57
 
58
58
  user.email
59
59
  > chad.nelson@fictional.edu
60
- ```
60
+ ```
61
61
 
62
- Once you have a user, you can also request that users loans, fines, requests.
62
+ #### Get details on a users fines
63
63
 
64
- ```ruby
64
+ ```ruby
65
65
  fines = user.fines
66
66
  fines.sum
67
- > 20.0
67
+ > "20.0"
68
+
69
+ fines.total_record_count
70
+ > "2"
71
+
72
+ fines.list
73
+ > [#<Alma::AlmaRecord:0x000000038b7b50
74
+ ...>,
75
+ #<Alma::AlmaRecord:0x000000038b7b28
76
+ ...>]
68
77
 
69
78
  fines.list.first.title
70
- > Practical Object Oriented Design with Ruby
79
+ > "Practical Object Oriented Design with Ruby"
80
+
81
+ ```
82
+
83
+ #### Get details on a users loans
84
+
85
+ ```ruby
86
+ loans = user.loans
87
+
88
+ loans.total_record_count
89
+ > "2"
90
+
91
+ loans.list
92
+ > [#<Alma::Loan:0x000000038c6b79
93
+ ...>,
94
+ #<Alma::Loan:0x000000038c6b34
95
+ ...>]
96
+
97
+ loans.list.first.title
98
+ > "Javascript: The Good Parts"
99
+
100
+ loans.list.first.due_date
101
+ "2016-12-26z
102
+
103
+ ```
104
+
105
+ To renew an item you can can call the Loan objects renew method
106
+
107
+ ```ruby
108
+ renewal = loans.list.first.renew
109
+
110
+ renewal.renewed?
111
+ > True
112
+
113
+ renewal.message
114
+ > "Javascript: The Good Parts is now due 02-20-17"
115
+
116
+ ```
117
+
118
+
119
+
120
+ #### Get details on a users requests
121
+ ```ruby
122
+ requests = user.requests
123
+
124
+ requests.total_record_count
125
+ > "1"
71
126
 
72
- user.loans.list
73
- [\<Item Object 1\>, \<Item Oject 2\>]
74
- ```
127
+ requests.list
128
+ > [#<Alma::AlmaRecord:0x000000038c6b79...>]
129
+
130
+ requests.list.first.title
131
+ > "Food in history / Reay Tannahill."
132
+
133
+ requests.list.first.pickup_location
134
+ > "Main Library"
135
+
136
+ requests.list.first.request_status
137
+ > "In Process"
138
+
139
+ ```
75
140
 
76
141
  Loans, fines and Requests can also be accessed statically
77
142
 
78
- ```ruby
79
- fines = Alma::User.get_fines({:user_id => 123456789})
143
+ ```ruby
144
+ Alma::User.get_fines({:user_id => 123456789})
80
145
 
81
- loans = Alma::User.get_loans({:user_id => 123456789})
146
+ Alma::User.get_loans({:user_id => 123456789})
147
+
148
+ Alma::User.get_requests({:user_id => 123456789})
82
149
 
83
- ```
150
+ ```
84
151
  ## Development
85
152
 
86
153
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -3,12 +3,14 @@ require 'alma/config'
3
3
  require 'alma/api'
4
4
  require 'alma/alma_record'
5
5
  require 'alma/user'
6
+ require 'alma/loan'
6
7
  require 'alma/result_set'
7
8
  require 'alma/loan_set'
8
9
  require 'alma/user_set'
9
10
  require 'alma/fine_set'
10
11
  require 'alma/user_set'
11
12
  require 'alma/request_set'
13
+ require 'alma/renewal_response'
12
14
 
13
15
  module Alma
14
16
 
@@ -0,0 +1,9 @@
1
+ module Alma
2
+ class Loan < AlmaRecord
3
+
4
+ def renew
5
+ Alma::User.renew_loan({user_id: user_id, loan: self})
6
+ end
7
+
8
+ end
9
+ end
@@ -5,7 +5,7 @@ module Alma
5
5
 
6
6
  def initialize(ws_response)
7
7
  @ws_response = ws_response
8
- @total_record_count = ws_response.fetch(total_record_count, 0)
8
+ @total_record_count = ws_response.fetch('total_record_count', 0)
9
9
  @list ||= list_results
10
10
  end
11
11
 
@@ -15,9 +15,9 @@ module Alma
15
15
 
16
16
  def list_results
17
17
  response_records.map do |loan|
18
- Alma::AlmaRecord.new(loan)
18
+ Alma::Loan.new(loan)
19
19
  end
20
20
  end
21
21
 
22
22
  end
23
- end
23
+ end
@@ -0,0 +1,39 @@
1
+ module Alma
2
+ class RenewalResponse
3
+
4
+ def initialize(response, loan=nil)
5
+ @loan = loan
6
+ @success = response.fetch('item_loan', nil)
7
+ @error = response.fetch('web_service_result', nil)
8
+ @renewed = @error.nil?
9
+ end
10
+
11
+ def renewed?
12
+ @renewed
13
+ end
14
+
15
+ def new_due_date
16
+ Time.parse(@success['due_date']).strftime('%m-%e-%y %H:%M')
17
+ end
18
+
19
+ def error_message
20
+ @error['errorList']['error']['errorMessage']
21
+ end
22
+
23
+ def item_title
24
+ if @loan
25
+ @loan.title
26
+ else
27
+ "This Item"
28
+ end
29
+ end
30
+
31
+ def message
32
+ if @success
33
+ "#{item_title} is now due #{new_due_date}"
34
+ else
35
+ "#{item_title} could not be renewed."
36
+ end
37
+ end
38
+ end
39
+ end
@@ -7,19 +7,34 @@ module Alma
7
7
  attr_accessor :id
8
8
 
9
9
  def post_initialize
10
- @id = response['primary_id']
10
+ @id = response['primary_id'].to_s
11
+ @recheck_loans = true
11
12
  end
12
13
 
13
14
  def fines
14
- Alma::User.get_fines({:user_id => self.id.to_s})
15
+ self.class.get_fines({user_id: self.id})
15
16
  end
16
17
 
17
18
  def loans
18
- Alma::User.get_loans({:user_id => self.id.to_s})
19
+ unless @loans && !recheck_loans?
20
+ @loans = self.class.get_loans({user_id: self.id})
21
+ @recheck_loans = false
22
+ end
23
+ @loans
24
+ end
25
+
26
+ def renew_loan(loan)
27
+ response = self.class.renew_loan({user_id: self.id, loan: loan})
28
+ @recheck_loans = true if response.renewed?
29
+ response
30
+ end
31
+
32
+ def recheck_loans?
33
+ @recheck_loans
19
34
  end
20
35
 
21
36
  def requests
22
- Alma::User.get_requests({:user_id => self.id.to_s})
37
+ self.class.get_requests({user_id:self.id})
23
38
  end
24
39
 
25
40
  class << self
@@ -30,7 +45,7 @@ module Alma
30
45
  #TODO Handle Pagination
31
46
  #TODO Handle looping through all results
32
47
 
33
- return find_by_id(:user_id => args[:user_id]) if args.fetch(:user_id, nil)
48
+ return find_by_id(user_id: args[:user_id]) if args.fetch(:user_id, nil)
34
49
  params = query_merge args
35
50
  response = resources.almaws_v1_users.get(params)
36
51
  Alma::UserSet.new(response)
@@ -77,6 +92,26 @@ module Alma
77
92
  response.code == 204
78
93
  end
79
94
 
95
+ # Attempts to renew a single item for a user
96
+ # @param [Hash] args
97
+ # @option args [String] :user_id The unique id of the user
98
+ # @option args [String] :loan_id The unique id of the loan - optional (either :loan_id or :loan must be present)
99
+ # @option args [String] :loan_id A loan object - optional (either :loan_id or :loan must be present)
100
+ # @option args [String] :user_id_type Type of identifier being used to search
101
+ # @return [RenewalResponse] Object indicating the renewal message
102
+ def renew_loan(args)
103
+ args.merge!({op: 'renew'})
104
+
105
+ # If a loan object is passed in args, us its id as loan_id
106
+ loan = args.delete(:loan)
107
+ if loan
108
+ args[:loan_id] = loan.loan_id
109
+ end
110
+ params = query_merge args
111
+ response = resources.almaws_v1_users.user_id_loans_loan_id.post(params)
112
+ RenewalResponse.new(response, loan)
113
+ end
114
+
80
115
 
81
116
  def set_wadl_filename
82
117
  'user.wadl'
@@ -1,3 +1,3 @@
1
1
  module Alma
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Nelson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-18 00:00:00.000000000 Z
11
+ date: 2017-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ezwadl
@@ -119,7 +119,9 @@ files:
119
119
  - lib/alma/api.rb
120
120
  - lib/alma/config.rb
121
121
  - lib/alma/fine_set.rb
122
+ - lib/alma/loan.rb
122
123
  - lib/alma/loan_set.rb
124
+ - lib/alma/renewal_response.rb
123
125
  - lib/alma/request_set.rb
124
126
  - lib/alma/result_set.rb
125
127
  - lib/alma/user.rb