evergreen_holdings 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/evergreen_holdings.rb +48 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dd3388514b1c9b46a0478dae03c6bbc8b96e496
|
4
|
+
data.tar.gz: 6e1296f90b066155369b8578e91f6505e7d43a1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c5a4590219f7be4216794114f89405cb6badd6ec63710a469d33bd349b8d88d6eb22049c16c7883fb68a863ddb1125cbcfb0551ce1aca0a9dd80e20ca5bccf3
|
7
|
+
data.tar.gz: 1ea5680f515e5ad9e862d0813ec86c7dd81cf87fd2705d2fe01cd13e2343cc798d439d3da82b28336bccc7f20965c6244dc99da5e30fd4026b78804134ba513e
|
data/lib/evergreen_holdings.rb
CHANGED
@@ -15,6 +15,7 @@ module EvergreenHoldings
|
|
15
15
|
unless fetch_statuses
|
16
16
|
raise CouldNotConnectToEvergreenError
|
17
17
|
end
|
18
|
+
fetch_ou_tree
|
18
19
|
end
|
19
20
|
|
20
21
|
# Fetch holdings data from the Evergreen server
|
@@ -34,6 +35,7 @@ module EvergreenHoldings
|
|
34
35
|
return Status.new res.body, self if res
|
35
36
|
end
|
36
37
|
|
38
|
+
# Given an ID, returns a human-readable name
|
37
39
|
def location_name id
|
38
40
|
params = "format=json&input_format=json&service=open-ils.circ&method=open-ils.circ.copy_location.retrieve¶m=#{id}"
|
39
41
|
@gateway.query = params
|
@@ -51,8 +53,32 @@ module EvergreenHoldings
|
|
51
53
|
return @possible_item_statuses[id]
|
52
54
|
end
|
53
55
|
|
56
|
+
def ou_name id
|
57
|
+
return @org_units[id][:name]
|
58
|
+
end
|
59
|
+
|
54
60
|
private
|
55
61
|
|
62
|
+
def add_ou_descendants id, parent
|
63
|
+
(@org_units[parent][:descendants] ||= []) << id
|
64
|
+
if @org_units[parent][:parent]
|
65
|
+
add_ou_descendants id, @org_units[parent][:parent]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def take_info_from_ou_tree o
|
70
|
+
@org_units[o[3]] = {}
|
71
|
+
@org_units[o[3]][:name] = o[6]
|
72
|
+
if o[8]
|
73
|
+
@org_units[o[3]][:parent] = o[8]
|
74
|
+
add_ou_descendants o[3], o[8]
|
75
|
+
end
|
76
|
+
o[0].each do |p|
|
77
|
+
take_info_from_ou_tree p['__p']
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
|
56
82
|
def send_query
|
57
83
|
begin
|
58
84
|
res = Net::HTTP.get_response(@gateway)
|
@@ -78,6 +104,19 @@ module EvergreenHoldings
|
|
78
104
|
return false
|
79
105
|
end
|
80
106
|
|
107
|
+
def fetch_ou_tree
|
108
|
+
@org_units = {}
|
109
|
+
params = 'format=json&input_format=json&service=open-ils.actor&method=open-ils.actor.org_tree.retrieve'
|
110
|
+
@gateway.query = params
|
111
|
+
res = send_query
|
112
|
+
if res
|
113
|
+
raw_orgs = JSON.parse(res.body)['payload'][0]['__p']
|
114
|
+
take_info_from_ou_tree raw_orgs
|
115
|
+
return true if @org_units.size > 0
|
116
|
+
end
|
117
|
+
return false
|
118
|
+
end
|
119
|
+
|
81
120
|
end
|
82
121
|
|
83
122
|
# Status objects represent all the holdings attached to a specific tcn
|
@@ -109,12 +148,14 @@ module EvergreenHoldings
|
|
109
148
|
if vol['__p'][0].size > 0
|
110
149
|
vol['__p'][0].each do |item|
|
111
150
|
unless item['__p'][35].nil?
|
112
|
-
|
151
|
+
copies.push Item.new barcode: item['__p'][2], call_number: vol['__p'][7], location: item['__p'][24], status: item['__p'][28], owning_lib: item['__p'][5]
|
113
152
|
else
|
114
153
|
begin
|
115
|
-
|
154
|
+
copies.push Item.new barcode: item['__p'][2], call_number: vol['__p'][7], due_date: item['__p'][35][0]['__p'][6], location: item['__p'][24], status: item['__p'][28], owning_lib: item['__p'][5]
|
116
155
|
rescue
|
117
|
-
|
156
|
+
puts item['__p'][5]
|
157
|
+
puts @org_units
|
158
|
+
copies.push Item.new barcode: item['__p'][2], call_number: vol['__p'][7], location: item['__p'][24], status: item['__p'][28], owning_lib: item['__p'][5]
|
118
159
|
end
|
119
160
|
end
|
120
161
|
end
|
@@ -131,6 +172,9 @@ module EvergreenHoldings
|
|
131
172
|
if copy.status.is_a? Numeric
|
132
173
|
copy.status = @connection.status_name copy.status
|
133
174
|
end
|
175
|
+
if copy.owning_lib.is_a? Numeric
|
176
|
+
copy.owning_lib = @connection.ou_name copy.owning_lib
|
177
|
+
end
|
134
178
|
end
|
135
179
|
end
|
136
180
|
|
@@ -138,7 +182,7 @@ module EvergreenHoldings
|
|
138
182
|
|
139
183
|
# A physical copy of an item
|
140
184
|
class Item
|
141
|
-
attr_accessor :location, :status
|
185
|
+
attr_accessor :location, :status, :owning_lib
|
142
186
|
attr_reader :barcode, :call_number
|
143
187
|
def initialize data = {}
|
144
188
|
data.each do |k,v|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evergreen_holdings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jane Sandberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
69
|
rubyforge_project:
|
70
|
-
rubygems_version: 2.5.
|
70
|
+
rubygems_version: 2.5.2
|
71
71
|
signing_key:
|
72
72
|
specification_version: 4
|
73
73
|
summary: A ruby gem for getting information about copy availability from Evergreen
|