evergreen_holdings 0.1.1
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 +7 -0
- data/lib/evergreen_holdings/errors.rb +2 -0
- data/lib/evergreen_holdings.rb +136 -0
- data/test/evergreen_holdings_test.rb +21 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5511d7fa326b339080aac864cb223a99d5adc935
|
4
|
+
data.tar.gz: e841a0ae4593c453599c45dc018d4c38e14dacad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b4545c01d0127a6be4eca3f1e2173431bc58d87a4dda771c18232af34922f76540ea8b589b49e28fa5380da9152440b00653754eb37350b03a66a321879e1f94
|
7
|
+
data.tar.gz: 3c5e4b56a6ca22c7503db5709c6d82e9ea0f78075a7e3e0a93703bd2fe5e5956ab47cdf676253b710a942dd873912293e55c4f8fca3e45aa301bafc873b349c7
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'evergreen_holdings/errors'
|
4
|
+
|
5
|
+
OSRF_PATH = '/osrf-gateway-v1'
|
6
|
+
|
7
|
+
module EvergreenHoldings
|
8
|
+
class Connection
|
9
|
+
# Create a new object with the evergreen_domain
|
10
|
+
# specified, e.g. http://libcat.linnbenton.edu
|
11
|
+
#
|
12
|
+
# Usage: `conn = EvergreenHoldings::Connection.new 'http://gapines.org'`
|
13
|
+
def initialize evergreen_domain
|
14
|
+
@gateway = URI evergreen_domain+OSRF_PATH
|
15
|
+
unless fetch_statuses
|
16
|
+
raise CouldNotConnectToEvergreenError
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Fetch holdings data from the Evergreen server
|
21
|
+
# Returns a Status object
|
22
|
+
#
|
23
|
+
# Usage: `stat = conn.get_holdings 23405`
|
24
|
+
# If you just want holdings at a specific org_unit: `my_connection.get_holdings 23405, org_unit: 5`
|
25
|
+
def get_holdings tcn, options = {}
|
26
|
+
if options.key?(:org_unit)
|
27
|
+
params = "format=json&input_format=json&service=open-ils.cat&method=open-ils.cat.asset.copy_tree.retrieve¶m=auth_token_not_needed_for_this_call¶m=#{tcn}¶m=#{options[:org_unit]}"
|
28
|
+
else
|
29
|
+
params = "format=json&input_format=json&service=open-ils.cat&method=open-ils.cat.asset.copy_tree.global.retrieve¶m=auth_token_not_needed_for_this_call¶m=#{tcn}"
|
30
|
+
end
|
31
|
+
@gateway.query = params
|
32
|
+
|
33
|
+
res = Net::HTTP.get_response(@gateway)
|
34
|
+
return Status.new res.body, self if res.is_a?(Net::HTTPSuccess)
|
35
|
+
end
|
36
|
+
|
37
|
+
def location_name id
|
38
|
+
params = "format=json&input_format=json&service=open-ils.circ&method=open-ils.circ.copy_location.retrieve¶m=#{id}"
|
39
|
+
@gateway.query = params
|
40
|
+
res = Net::HTTP.get_response(@gateway)
|
41
|
+
if res.is_a? Net::HTTPSuccess
|
42
|
+
data = JSON.parse(res.body)['payload'][0]
|
43
|
+
unless data.key? 'stacktrace'
|
44
|
+
return data['__p'][4]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
return id
|
48
|
+
end
|
49
|
+
|
50
|
+
def status_name id
|
51
|
+
return @possible_item_statuses[id]
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def fetch_statuses
|
57
|
+
@possible_item_statuses = []
|
58
|
+
params = 'format=json&input_format=json&service=open-ils.search&method=open-ils.search.config.copy_status.retrieve.all'
|
59
|
+
@gateway.query = params
|
60
|
+
res = Net::HTTP.get_response(@gateway)
|
61
|
+
if res.is_a?(Net::HTTPSuccess)
|
62
|
+
stats = JSON.parse(res.body)['payload'][0]
|
63
|
+
stats.each do |stat|
|
64
|
+
@possible_item_statuses[stat['__p'][1]] = stat['__p'][2]
|
65
|
+
end
|
66
|
+
return true if stats.size > 0
|
67
|
+
end
|
68
|
+
return false
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
class Status
|
74
|
+
attr_reader :copies
|
75
|
+
def initialize json_data, connection = nil
|
76
|
+
@connection = connection
|
77
|
+
@raw_data = JSON.parse(json_data)['payload'][0]
|
78
|
+
@copies = extract_copies
|
79
|
+
substitute_values_for_ids unless @connection.nil?
|
80
|
+
@available_copies = []
|
81
|
+
@next_copy_available = 'a date'
|
82
|
+
end
|
83
|
+
|
84
|
+
# Determines if any copies are available for your patrons
|
85
|
+
def any_copies_available?
|
86
|
+
@copies.each do |copy|
|
87
|
+
return true if 0 == copy.status
|
88
|
+
return true if 'Available' == copy.status
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
# Look through @raw_data and find the copies
|
94
|
+
def extract_copies
|
95
|
+
copies = Array.new
|
96
|
+
@raw_data.each do |vol|
|
97
|
+
if vol['__p'][0].size > 0
|
98
|
+
vol['__p'][0].each do |item|
|
99
|
+
unless item['__p'][35].nil?
|
100
|
+
copies.push Item.new barcode: item['__p'][2], call_number: vol['__p'][7], location: item['__p'][24], status: item['__p'][28]
|
101
|
+
else
|
102
|
+
begin
|
103
|
+
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]
|
104
|
+
rescue
|
105
|
+
copies.push Item.new barcode: item['__p'][2], call_number: vol['__p'][7], location: item['__p'][24], status: item['__p'][28]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
return copies
|
112
|
+
end
|
113
|
+
|
114
|
+
def substitute_values_for_ids
|
115
|
+
@copies.each do |copy|
|
116
|
+
if copy.location.is_a? Numeric
|
117
|
+
copy.location = @connection.location_name copy.location
|
118
|
+
end
|
119
|
+
if copy.status.is_a? Numeric
|
120
|
+
copy.status = @connection.status_name copy.status
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
class Item
|
128
|
+
attr_accessor :location, :status
|
129
|
+
attr_reader :barcode
|
130
|
+
def initialize data = {}
|
131
|
+
data.each do |k,v|
|
132
|
+
instance_variable_set("@#{k}", v) unless v.nil?
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
Coveralls.wear!
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'evergreen_holdings'
|
5
|
+
|
6
|
+
class EvergreenHoldingsTest < Minitest::Test
|
7
|
+
def test_connecting_to_eg_returns_a_connection_object
|
8
|
+
conn = EvergreenHoldings::Connection.new 'http://gapines.org'
|
9
|
+
assert_instance_of EvergreenHoldings::Connection, conn
|
10
|
+
end
|
11
|
+
def test_connecting_to_a_404_throws_an_error
|
12
|
+
assert_raises('CouldNotConnectToEvergreenError') {
|
13
|
+
EvergreenHoldings::Connection.new('http://httpstat.us/404')
|
14
|
+
}
|
15
|
+
end
|
16
|
+
def test_connecting_to_a_non_evergreen_server_throws_an_error
|
17
|
+
assert_raises('CouldNotConnectToEvergreenError') {
|
18
|
+
EvergreenHoldings::Connection.new('http://libfind.linnbenton.edu')
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: evergreen_holdings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jane Sandberg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: minitest
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.7.0
|
41
|
+
description: Access holdings information from Evergreen ILS
|
42
|
+
email: sandbej@linnbenton.edu
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/evergreen_holdings.rb
|
48
|
+
- lib/evergreen_holdings/errors.rb
|
49
|
+
- test/evergreen_holdings_test.rb
|
50
|
+
homepage:
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.5.1
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: A ruby gem for getting information about copy availability from Evergreen
|
74
|
+
ILS
|
75
|
+
test_files:
|
76
|
+
- test/evergreen_holdings_test.rb
|