evergreen_holdings 0.1.8 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/evergreen_holdings.rb +46 -16
  3. metadata +24 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bc48757194a624a320a66952894f1fb06feb2d3
4
- data.tar.gz: bc39854e6d931c380a7996b8c998268917254bf7
3
+ metadata.gz: da13869aee1d6030dc730f20f662d3bbae682f1b
4
+ data.tar.gz: efbf034638ed3b6b301934de474f1dc1365bcfcb
5
5
  SHA512:
6
- metadata.gz: cf9824129e3a2aaaa7c4f58a3e2534f014b9d33ddb9bf0f7ad8950324849b22522f29574b2e7e53056595ce1f3dbb130957eb1aa2d7248371bfc21919b66c9bf
7
- data.tar.gz: d701f9dc7a595241544540e1cdb714a2b78be515adfa4bf476f257c27476b555a1cd614e208a507159f9052240693fbfdb4b47e9a993ca3f3843cfee4c0e8dfe
6
+ metadata.gz: 8a874195ffa5f2c7b0a202cecf66121d487d8eca4f60cf8ba0536f258040cc9a58d50dda5d6b4f62d6dcb17ce93a46654cdc3e3b0b6b81d0f0ca16872839ef6b
7
+ data.tar.gz: 9557150bed33a4e14d189e1ee2cd0e8f6048ca44d63cd289bb10e32547e315ed7b2a5c2ad8efc73d346b1179dca1d5d52686a951e06c6e66ee6c62f443b98138
@@ -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
@@ -42,7 +46,7 @@ module EvergreenHoldings
42
46
  @gateway.query = params
43
47
 
44
48
  res = send_query
45
- return Status.new res.body, self if res
49
+ return Status.new res.body, @idl_order, self if res
46
50
  end
47
51
 
48
52
  # Given an ID, returns a human-readable name
@@ -53,7 +57,7 @@ module EvergreenHoldings
53
57
  if res
54
58
  data = JSON.parse(res.body)['payload'][0]
55
59
  unless data.key? 'stacktrace'
56
- return data['__p'][4]
60
+ return data['__p'][@idl_order[:acpl]['name']]
57
61
  end
58
62
  end
59
63
  return id
@@ -77,13 +81,14 @@ module EvergreenHoldings
77
81
  end
78
82
 
79
83
  def take_info_from_ou_tree o
80
- @org_units[o[3]] = {}
81
- @org_units[o[3]][:name] = o[6]
82
- if o[8]
83
- @org_units[o[3]][:parent] = o[8]
84
- 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']]
85
90
  end
86
- o[0].each do |p|
91
+ o[@idl_order[:aou]['children']].each do |p|
87
92
  take_info_from_ou_tree p['__p']
88
93
  end
89
94
  end
@@ -99,6 +104,22 @@ module EvergreenHoldings
99
104
  return nil
100
105
  end
101
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
+
102
123
  def fetch_statuses
103
124
  @possible_item_statuses = []
104
125
  params = 'format=json&input_format=json&service=open-ils.search&method=open-ils.search.config.copy_status.retrieve.all'
@@ -107,7 +128,7 @@ module EvergreenHoldings
107
128
  if res
108
129
  stats = JSON.parse(res.body)['payload'][0]
109
130
  stats.each do |stat|
110
- @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']]
111
132
  end
112
133
  return true if stats.size > 0
113
134
  end
@@ -132,7 +153,8 @@ module EvergreenHoldings
132
153
  # Status objects represent all the holdings attached to a specific tcn
133
154
  class Status
134
155
  attr_reader :copies, :libraries
135
- def initialize json_data, connection = nil
156
+ def initialize json_data, idl_order, connection = nil
157
+ @idl_order = idl_order
136
158
  @connection = connection
137
159
  @raw_data = JSON.parse(json_data)['payload'][0]
138
160
  extract_copies
@@ -158,14 +180,22 @@ module EvergreenHoldings
158
180
  @raw_data.each do |vol|
159
181
  if vol['__p'][0].size > 0
160
182
  vol['__p'][0].each do |item|
161
- unless item['__p'][35].nil?
162
- @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]
183
+ i = 0
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
163
193
  else
164
194
  begin
165
- @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']]
166
196
  rescue
167
- @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]
168
197
  end
198
+ @copies.push Item.new item_info
169
199
  end
170
200
  end
171
201
  end
@@ -195,7 +225,7 @@ module EvergreenHoldings
195
225
  # A physical copy of an item
196
226
  class Item
197
227
  attr_accessor :location, :status, :owning_lib
198
- attr_reader :barcode, :call_number
228
+ attr_reader :barcode, :call_number, :due_date
199
229
  def initialize data = {}
200
230
  data.each do |k,v|
201
231
  instance_variable_set("@#{k}", v) unless v.nil?
metadata CHANGED
@@ -1,41 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evergreen_holdings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jane Sandberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-11 00:00:00.000000000 Z
11
+ date: 2019-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: minitest
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - ">="
31
+ - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '0'
33
+ version: 5.0.0
20
34
  type: :development
21
35
  prerelease: false
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
  name: coveralls
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - '='
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
47
  version: 0.7.0
34
48
  type: :development
35
49
  prerelease: false
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: {}
@@ -67,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
81
  version: '0'
68
82
  requirements: []
69
83
  rubyforge_project:
70
- rubygems_version: 2.5.2
84
+ rubygems_version: 2.6.13
71
85
  signing_key:
72
86
  specification_version: 4
73
87
  summary: A ruby gem for getting information about copy availability from Evergreen