alma 0.2.5 → 0.2.6

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
- SHA1:
3
- metadata.gz: 3bcedc3a4e5136aa43268412c062c91dc2d905dd
4
- data.tar.gz: 37f3892ff4a0fc27e8c6a79a540ea52f0f5199d4
2
+ SHA256:
3
+ metadata.gz: 9f8f97556fd38ab3e4b03c42ee739d1a8a878f997e1d2ee54fb5dd5017b3cd51
4
+ data.tar.gz: 1e5d6362f38d31fe538afe713b9b5ec87469f0364ddfde258e29a1c3b076cf88
5
5
  SHA512:
6
- metadata.gz: 120bef80c621c53709475f2c54dd2a7b3379fe307ac0f1227adb1f0a8627e064ea19f87260432a5a45ad65d342623fbc314e5079aea7fae930a0ac719bbf5f7c
7
- data.tar.gz: 2e190810b76aa0b0041b021364d5879cff6a6122ee9f0c17be212cc69bb1d1c2af63059c801752754f6b711ec4e948777d2a1285ef428b1838a7ce1c6fc5eb80
6
+ metadata.gz: 2e9e26c6789cf81b7d8390c56a42f6c422dffda52befa4b629873bfa7edc0a7974c20ed51c485f861809743e9fa9db988af4d4cbe4f63ee8b15b4371ee27f38c
7
+ data.tar.gz: ad6e0abc8e573bb1c02b34047eab1847e21ca858c6baa385b969c1faf45033151679201543f13ddc74d696035e234387e75eba7bfe4e046ff60231fc1e795b3b
@@ -1,5 +1,5 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3.3
4
+ - 2.4.1
5
5
  before_install: gem install bundler -v 1.13.7
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in alma.gemspec
4
4
  gemspec
5
+
6
+ gem 'simplecov', require: false, group: :test
7
+
@@ -15,7 +15,8 @@ require 'alma/bib_set'
15
15
  require 'alma/request_set'
16
16
  require 'alma/renewal_response'
17
17
  require 'alma/availability_response'
18
- require 'alma/bib_items'
18
+ require 'alma/bib_item'
19
+ require 'alma/request_options'
19
20
 
20
21
  module Alma
21
22
 
@@ -0,0 +1,174 @@
1
+ require 'alma/bib_item_set'
2
+ module Alma
3
+ class BibItem
4
+ extend Forwardable
5
+
6
+ attr_reader :item
7
+ def_delegators :item, :[], :has_key?, :keys, :to_json
8
+
9
+ PERMITTED_ARGS = [
10
+ :limit, :offset, :expand, :user_id, :current_library,
11
+ :current_location, :q, :order_by, :direction
12
+ ]
13
+
14
+ def self.find(mms_id, options={})
15
+ holding_id = options.delete(:holding_id) || "ALL"
16
+ options.select! {|k,_| PERMITTED_ARGS.include? k }
17
+ url = "#{bibs_base_path}/#{mms_id}/holdings/#{holding_id}/items"
18
+ response = HTTParty.get(url, headers: headers, query: options)
19
+ BibItemSet.new(response)
20
+ end
21
+
22
+ def initialize(item)
23
+ @item = item
24
+ end
25
+
26
+ def holding_data
27
+ @item.fetch("holding_data", {})
28
+ end
29
+
30
+ def item_data
31
+ @item.fetch("item_data", {})
32
+ end
33
+
34
+ def in_temp_location?
35
+ holding_data.fetch("in_temp_location", false)
36
+ end
37
+
38
+ def library
39
+ in_temp_location? ? temp_library : holding_library
40
+ end
41
+
42
+ def library_name
43
+ in_temp_location? ? temp_library_name : holding_library_name
44
+ end
45
+
46
+ def location
47
+ in_temp_location? ? temp_location : holding_location
48
+ end
49
+
50
+ def location_name
51
+ in_temp_location? ? temp_location_name : holding_location_name
52
+ end
53
+
54
+
55
+ def holding_library
56
+ item_data.dig("library", "value")
57
+ end
58
+
59
+ def holding_library_name
60
+ item_data.dig("library", "desc")
61
+ end
62
+
63
+ def holding_location
64
+ item_data.dig("location", "value")
65
+ end
66
+
67
+ def holding_location_name
68
+ item_data.dig("location", "desc")
69
+ end
70
+
71
+ def temp_library
72
+ holding_data.dig("temp_library", "value")
73
+ end
74
+
75
+ def temp_library_name
76
+ holding_data.dig("temp_library", "desc")
77
+ end
78
+
79
+ def temp_location
80
+ holding_data.dig("temp_location", "value")
81
+ end
82
+
83
+ def temp_location_name
84
+ holding_data.dig("temp_location", "desc")
85
+ end
86
+
87
+ def temp_call_number
88
+ holding_data.fetch("temp_call_number","")
89
+ end
90
+
91
+ def has_temp_call_number?
92
+ !temp_call_number.empty?
93
+ end
94
+
95
+ def call_number
96
+ if has_temp_call_number?
97
+ holding_data.fetch("temp_call_number")
98
+ elsif has_alt_call_number?
99
+ alt_call_number
100
+ else
101
+ holding_data.fetch("call_number","")
102
+ end
103
+ end
104
+
105
+ def has_alt_call_number?
106
+ !alt_call_number.empty?
107
+ end
108
+
109
+ def alt_call_number
110
+ item_data.fetch("alternative_call_number","")
111
+ end
112
+
113
+ def has_process_type?
114
+ !process_type.empty?
115
+ end
116
+
117
+ def process_type
118
+ item_data.dig("process_type", "value") || ""
119
+ end
120
+
121
+ def missing_or_lost?
122
+ !!process_type.match(/MISSING|LOST_LOAN/)
123
+ end
124
+
125
+ def base_status
126
+ item_data.dig("base_status","value")|| ""
127
+ end
128
+
129
+ def in_place?
130
+ base_status == "1"
131
+ end
132
+
133
+ def circulation_policy
134
+ item_data.dig("policy", "desc") || ""
135
+ end
136
+
137
+ def non_circulating?
138
+ circulation_policy.include?("Non-circulating")
139
+ end
140
+
141
+ def description
142
+ item_data.fetch("description", "")
143
+ end
144
+
145
+ def physical_material_type
146
+ item_data.fetch("physical_material_type", "")
147
+ end
148
+
149
+ def public_note
150
+ item_data.fetch("public_note", "")
151
+ end
152
+
153
+ private
154
+
155
+ def self.region
156
+ Alma.configuration.region
157
+ end
158
+
159
+ def self.bibs_base_path
160
+ "#{region}/almaws/v1/bibs"
161
+ end
162
+
163
+ def self.headers
164
+ { "Authorization": "apikey #{apikey}",
165
+ "Accept": "application/json",
166
+ "Content-Type": "application/json" }
167
+ end
168
+
169
+ def self.apikey
170
+ Alma.configuration.apikey
171
+ end
172
+ end
173
+
174
+ end
@@ -0,0 +1,33 @@
1
+ module Alma
2
+ class BibItemSet
3
+ extend Forwardable
4
+
5
+ # Let BibItemSet respond to the Enumerable duck type
6
+ # by delegating responsibility for #each to items
7
+ include Enumerable
8
+ attr_accessor :items
9
+ def_delegators :items, :each
10
+
11
+ def_delegators :items,:[], :[]=, :empty?, :size
12
+
13
+ attr_reader :raw_response, :total_record_count
14
+ def_delegators :raw_response, :response, :request
15
+
16
+ def initialize(response)
17
+ @raw_response = response
18
+ parsed = JSON.parse(response.body)
19
+ @total_record_count = parsed["total_record_count"]
20
+ @items = parsed.fetch("item",[]).map {|item| BibItem.new(item)}
21
+ end
22
+
23
+ def grouped_by_library
24
+ group_by(&:library)
25
+ end
26
+
27
+ def filter_missing_and_lost
28
+ clone = dup
29
+ clone.items = reject(&:missing_or_lost?)
30
+ clone
31
+ end
32
+ end
33
+ end
@@ -1,31 +1,28 @@
1
1
  module Alma
2
- class BibItems
2
+ class RequestOptions
3
3
  extend Forwardable
4
4
 
5
- attr_accessor :items
6
- def_delegators :items, :[], :[]=, :has_key?, :keys, :to_json
7
-
8
- attr_reader :raw_response
5
+ attr_accessor :request_options, :raw_response
9
6
  def_delegators :raw_response, :response, :request
10
7
 
8
+ REQUEST_OPTIONS_PERMITTED_ARGS = [:user_id]
9
+
11
10
  def initialize(response)
12
11
  @raw_response = response
13
- @items = JSON.parse(response.body)
12
+ @request_options = JSON.parse(response.body)["request_option"]
14
13
  end
15
14
 
16
- PERMITTED_ARGS = [
17
- :limit, :offset, :expand, :user_id, :current_library,
18
- :current_location, :q, :order_by, :direction
19
- ]
20
-
21
- def self.find(mms_id, options={})
22
- holding_id = options.delete(:holding_id) || "ALL"
23
- options.select! {|k,_| PERMITTED_ARGS.include? k }
24
- url = "#{bibs_base_path}/#{mms_id}/holdings/#{holding_id}/items"
15
+ def self.get(mms_id, options={})
16
+ url = "#{bibs_base_path}/#{mms_id}/request-options"
17
+ options.select! {|k,_| REQUEST_OPTIONS_PERMITTED_ARGS.include? k }
25
18
  response = HTTParty.get(url, headers: headers, query: options)
26
19
  new(response)
27
20
  end
28
21
 
22
+ def hold_allowed?
23
+ !request_options.select {|option| option["type"]["value"] == "HOLD" }.empty?
24
+ end
25
+
29
26
  private
30
27
 
31
28
  def self.region
@@ -45,5 +42,6 @@ module Alma
45
42
  def self.apikey
46
43
  Alma.configuration.apikey
47
44
  end
45
+
48
46
  end
49
47
  end
@@ -77,9 +77,9 @@ module Alma
77
77
  end
78
78
 
79
79
 
80
- def loans
80
+ def loans(args={})
81
81
  unless @loans && !recheck_loans?
82
- @loans = send_loans_request
82
+ @loans = send_loans_request(args)
83
83
  @recheck_loans = false
84
84
  end
85
85
  @loans
@@ -121,11 +121,12 @@ module Alma
121
121
 
122
122
  private
123
123
 
124
- def send_loans_request
125
- #TODO Handle Additional Parameters
126
- #TODO Handle Pagination
124
+ def send_loans_request(args={})
127
125
  #TODO Handle looping through all results
128
- response = HTTParty.get("#{users_base_path}/#{id}/loans", headers: headers)
126
+
127
+ # Always expand renewable unless you really don't want to
128
+ args["expand"] ||= "renewable"
129
+ response = HTTParty.get("#{users_base_path}/#{id}/loans", query: args, headers: headers)
129
130
  Alma::LoanSet.new(get_body_from(response))
130
131
  end
131
132
 
@@ -1,3 +1,3 @@
1
1
  module Alma
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
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.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Nelson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-19 00:00:00.000000000 Z
11
+ date: 2018-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ezwadl
@@ -147,7 +147,8 @@ files:
147
147
  - lib/alma/api.rb
148
148
  - lib/alma/availability_response.rb
149
149
  - lib/alma/bib.rb
150
- - lib/alma/bib_items.rb
150
+ - lib/alma/bib_item.rb
151
+ - lib/alma/bib_item_set.rb
151
152
  - lib/alma/bib_set.rb
152
153
  - lib/alma/config.rb
153
154
  - lib/alma/error.rb
@@ -155,6 +156,7 @@ files:
155
156
  - lib/alma/loan.rb
156
157
  - lib/alma/loan_set.rb
157
158
  - lib/alma/renewal_response.rb
159
+ - lib/alma/request_options.rb
158
160
  - lib/alma/request_set.rb
159
161
  - lib/alma/result_set.rb
160
162
  - lib/alma/user.rb
@@ -182,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
184
  version: '0'
183
185
  requirements: []
184
186
  rubyforge_project:
185
- rubygems_version: 2.6.11
187
+ rubygems_version: 2.7.6
186
188
  signing_key:
187
189
  specification_version: 4
188
190
  summary: Client for Ex Libris Alma Web Services