evergreen_holdings 0.2.2 → 0.3.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: 7f1ded6a6dc9a553da283e9ed64dfb04c6334d0bd8b7259cc18fc00ac76f713e
4
- data.tar.gz: 037d0726e922e58b20bcffe0daaa8fcbdbcfe1e8973109d69e18ff75e761a1c9
3
+ metadata.gz: 3f3cf8a83e3df42e8fa423883564558c82c18dfb716a449509450aeb9bcea8ab
4
+ data.tar.gz: 6085f268fb39a45ab2d136b1a32cce74b7f68ef46fa19b481b7b47bceffabfbd
5
5
  SHA512:
6
- metadata.gz: 798f5c3213570fdaee11a90382469be3466165b5c96bf850fa9ab5d2eadfed1dde9859e28a2e9665201839e5aec67b2337b780aa4493ffbe6336608b849306cc
7
- data.tar.gz: 0aa44ee1fcb9f66ff00df1a2cce7b79fbda8becee930a6559829292f0ca6ee686bd415efe2accff16f390d936f50b9c87f83cc901a67720d549f44de09d098a3
6
+ metadata.gz: b92e0c37217d1c54297f9eda1767f095b717e2f52b25258135ac72a67a40040c8aedf8659adf00d19da078d7b4e930258fe3e776bbcd3a2545d5b8153f32a41e
7
+ data.tar.gz: b6c2361c0be07a46eeefc02ebecd3a6fe329d726b46336a8ff592c156dc9b7b96cf1a737ef025deac0c4d6311d4e0e552fb354e60ace394ceb8e9b78a30db4cd
@@ -1,6 +1,8 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
3
  require 'evergreen_holdings/errors'
4
+ require 'nokogiri'
5
+ require 'open-uri'
4
6
 
5
7
  OSRF_PATH = '/osrf-gateway-v1'
6
8
 
@@ -12,11 +14,13 @@ module EvergreenHoldings
12
14
  #
13
15
  # Usage: `conn = EvergreenHoldings::Connection.new 'http://gapines.org'`
14
16
  def initialize evergreen_domain
17
+ @evergreen_domain = evergreen_domain
15
18
  @gateway = URI evergreen_domain+OSRF_PATH
19
+ fetch_idl_order
16
20
  unless fetch_statuses
17
21
  raise CouldNotConnectToEvergreenError
18
22
  end
19
- fetch_ou_tree
23
+ fetch_ou_tree
20
24
  end
21
25
 
22
26
  # Fetch holdings data from the Evergreen server
@@ -25,9 +29,6 @@ module EvergreenHoldings
25
29
  # Usage: `stat = conn.get_holdings 23405`
26
30
  # If you just want holdings at a specific org_unit: `my_connection.get_holdings 23405, org_unit: 5`
27
31
  def get_holdings tcn, options = {}
28
- if tcn.nil? || tcn.empty?
29
- raise NoCatalogIdProvidedError
30
- end
31
32
  if options.key?(:org_unit)
32
33
  if options[:descendants]
33
34
  params = "format=json&input_format=json&service=open-ils.cat&method=open-ils.cat.asset.copy_tree.retrieve&param=auth_token_not_needed_for_this_call&param=#{tcn}"
@@ -45,7 +46,7 @@ module EvergreenHoldings
45
46
  @gateway.query = params
46
47
 
47
48
  res = send_query
48
- return Status.new res.body, self if res
49
+ return Status.new res.body, @idl_order, self if res
49
50
  end
50
51
 
51
52
  # Given an ID, returns a human-readable name
@@ -56,7 +57,7 @@ module EvergreenHoldings
56
57
  if res
57
58
  data = JSON.parse(res.body)['payload'][0]
58
59
  unless data.key? 'stacktrace'
59
- return data['__p'][4]
60
+ return data['__p'][@idl_order[:acpl]['name']]
60
61
  end
61
62
  end
62
63
  return id
@@ -80,13 +81,14 @@ module EvergreenHoldings
80
81
  end
81
82
 
82
83
  def take_info_from_ou_tree o
83
- @org_units[o[3]] = {}
84
- @org_units[o[3]][:name] = o[6]
85
- if o[8]
86
- @org_units[o[3]][:parent] = o[8]
87
- add_ou_descendants o[3], o[8]
84
+ id = o[@idl_order[:aou]['id']]
85
+ @org_units[id] = {}
86
+ @org_units[id][:name] = o[@idl_order[:aou]['name']]
87
+ if o[@idl_order[:aou]['parent_ou']]
88
+ @org_units[id][:parent] = o[@idl_order[:aou]['parent_ou']]
89
+ add_ou_descendants id, o[@idl_order[:aou]['parent_ou']]
88
90
  end
89
- o[0].each do |p|
91
+ o[@idl_order[:aou]['children']].each do |p|
90
92
  take_info_from_ou_tree p['__p']
91
93
  end
92
94
  end
@@ -102,6 +104,22 @@ module EvergreenHoldings
102
104
  return nil
103
105
  end
104
106
 
107
+ def fetch_idl_order
108
+ @idl_order = {}
109
+
110
+ idl = Nokogiri::XML(open(@evergreen_domain + '/reports/fm_IDL.xml'))
111
+
112
+ [:acn, :acp, :acpl, :aou, :ccs, :circ].each do |idl_class|
113
+ i = 0
114
+ @idl_order[idl_class] = {}
115
+ fields = idl.xpath("//idl:class[@id='#{idl_class}']/idl:fields/idl:field", 'idl' => 'http://opensrf.org/spec/IDL/base/v1')
116
+ fields.each do |field|
117
+ @idl_order[idl_class][field['name']] = i
118
+ i = i + 1
119
+ end
120
+ end
121
+ end
122
+
105
123
  def fetch_statuses
106
124
  @possible_item_statuses = []
107
125
  params = 'format=json&input_format=json&service=open-ils.search&method=open-ils.search.config.copy_status.retrieve.all'
@@ -110,7 +128,7 @@ module EvergreenHoldings
110
128
  if res
111
129
  stats = JSON.parse(res.body)['payload'][0]
112
130
  stats.each do |stat|
113
- @possible_item_statuses[stat['__p'][1]] = stat['__p'][2]
131
+ @possible_item_statuses[stat['__p'][@idl_order[:ccs]['id']]] = stat['__p'][@idl_order[:ccs]['name']]
114
132
  end
115
133
  return true if stats.size > 0
116
134
  end
@@ -135,7 +153,8 @@ module EvergreenHoldings
135
153
  # Status objects represent all the holdings attached to a specific tcn
136
154
  class Status
137
155
  attr_reader :copies, :libraries
138
- def initialize json_data, connection = nil
156
+ def initialize json_data, idl_order, connection = nil
157
+ @idl_order = idl_order
139
158
  @connection = connection
140
159
  @raw_data = JSON.parse(json_data)['payload'][0]
141
160
  extract_copies
@@ -162,14 +181,21 @@ module EvergreenHoldings
162
181
  if vol['__p'][0].size > 0
163
182
  vol['__p'][0].each do |item|
164
183
  i = 0
165
- unless item['__p'][35].is_a? Array
166
- @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]
184
+ item_info = {
185
+ barcode: item['__p'][@idl_order[:acp]['barcode']],
186
+ call_number: vol['__p'][@idl_order[:acn]['label']],
187
+ location: item['__p'][@idl_order[:acp]['location']],
188
+ status: item['__p'][@idl_order[:acp]['status']],
189
+ owning_lib: item['__p'][@idl_order[:acp]['circ_lib']],
190
+ }
191
+ unless item['__p'][@idl_order[:acp]['circulations']].is_a? Array
192
+ @copies.push Item.new item_info
167
193
  else
168
194
  begin
169
- @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]
195
+ item_info[:due_date] = item['__p'][@idl_order[:acp]['circulations']][0]['__p'][@idl_order[:circ]['due_date']]
170
196
  rescue
171
- @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]
172
197
  end
198
+ @copies.push Item.new item_info
173
199
  end
174
200
  end
175
201
  end
@@ -1,4 +1,2 @@
1
1
  class CouldNotConnectToEvergreenError < StandardError
2
2
  end
3
- class NoCatalogIdProvidedError < StandardError
4
- end
metadata CHANGED
@@ -1,33 +1,47 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evergreen_holdings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jane Sandberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-18 00:00:00.000000000 Z
11
+ date: 2019-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">="
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0'
18
+ version: 1.10.4
19
+ name: nokogiri
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.10.4
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0
19
33
  name: minitest
20
34
  prerelease: false
21
35
  type: :development
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
- - - ">="
38
+ - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '0'
40
+ version: 5.0.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  requirement: !ruby/object:Gem::Requirement
29
43
  requirements:
30
- - - '='
44
+ - - "~>"
31
45
  - !ruby/object:Gem::Version
32
46
  version: 0.7.0
33
47
  name: coveralls
@@ -35,7 +49,7 @@ dependencies:
35
49
  type: :development
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - '='
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: 0.7.0
41
55
  description: Access holdings information from Evergreen ILS
@@ -47,7 +61,7 @@ files:
47
61
  - lib/evergreen_holdings.rb
48
62
  - lib/evergreen_holdings/errors.rb
49
63
  - test/evergreen_holdings_test.rb
50
- homepage:
64
+ homepage: https://github.com/sandbergja/evergreen_holdings_gem
51
65
  licenses:
52
66
  - MIT
53
67
  metadata: {}