voyager_oracle_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ gem "activesupport"
5
+ gem 'i18n'
6
+ gem 'ruby-oci8'
7
+ gem 'json'
8
+ gem 'activesupport'
9
+
10
+ # Add dependencies to develop your gem here.
11
+ # Include everything needed to run rake, tests, features, etc.
12
+ group :development do
13
+ gem "minitest", ">= 0"
14
+ gem "bundler", "> 1.0.0"
15
+ gem "jeweler", "~> 1.6.4"
16
+ gem "rcov", ">= 0"
17
+ gem "guard-minitest"
18
+ gem "rb-fsevent" # comment out if not on mac
19
+ gem "mocha"
20
+ gem "growl"
21
+ end
@@ -0,0 +1,45 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.2.8)
5
+ i18n (~> 0.6)
6
+ multi_json (~> 1.0)
7
+ git (1.2.5)
8
+ growl (1.0.3)
9
+ guard (0.6.3)
10
+ thor (~> 0.14.6)
11
+ guard-minitest (0.4.0)
12
+ guard (~> 0.4)
13
+ i18n (0.6.0)
14
+ jeweler (1.6.4)
15
+ bundler (~> 1.0)
16
+ git (>= 1.2.5)
17
+ rake
18
+ json (1.7.5)
19
+ metaclass (0.0.1)
20
+ minitest (2.5.1)
21
+ mocha (0.10.0)
22
+ metaclass (~> 0.0.1)
23
+ multi_json (1.3.6)
24
+ rake (0.9.2)
25
+ rb-fsevent (0.4.3.1)
26
+ rcov (0.9.10)
27
+ ruby-oci8 (2.1.2)
28
+ thor (0.14.6)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ activesupport
35
+ bundler (> 1.0.0)
36
+ growl
37
+ guard-minitest
38
+ i18n
39
+ jeweler (~> 1.6.4)
40
+ json
41
+ minitest
42
+ mocha
43
+ rb-fsevent
44
+ rcov
45
+ ruby-oci8
@@ -0,0 +1,10 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'minitest' do
5
+ watch(%r{^test/(.*)test_(.*).rb})
6
+ watch(%r{^lib/((?:(?:[^/]+)/)*)([^/]+)\.rb}) do |m|
7
+ Dir.glob("test/#{m[1]}test_#{m[2]}*.rb")
8
+ end
9
+ watch(%r{^test/helper(.*).rb}) { "test" }
10
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 James Stuart
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = voyager_oracle_api
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to voyager_oracle_api
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 James Stuart. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+ require 'rake'
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
18
+ gem.name = "voyager_oracle_api"
19
+ gem.homepage = "http://github.com/cul/voyager_oracle_api"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{Columbia University Voyager Oracle API wrapper}
22
+ gem.description = %Q{Middleware gem for Voyager Oracle API calls, specificially holdings information }
23
+ gem.email = "github@jamesstuart.org"
24
+ gem.authors = ["James Stuart", "Gary Bertchume"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ Dir.glob(File.join(File.dirname(__FILE__), "tasks", "**", "*.rake")).each { |f| load f }
30
+
31
+ require 'rake/testtask'
32
+ Rake::TestTask.new(:test) do |test|
33
+ test.libs << 'lib' << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+
38
+ require 'rcov/rcovtask'
39
+ Rcov::RcovTask.new do |test|
40
+ test.libs << 'test'
41
+ test.pattern = 'test/**/test_*.rb'
42
+ test.verbose = true
43
+ test.rcov_opts << '--exclude "gems/*"'
44
+ end
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/rdoctask'
49
+ Rake::RDocTask.new do |rdoc|
50
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "voyager_oracle_api #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
57
+
58
+
59
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,172 @@
1
+ 1n:
2
+ short_message: Available
3
+ long_message: Not checked out
4
+ 1r:
5
+ short_message: 'Available (Requests: %REQS)'
6
+ long_message: 'Not checked out (Requests: %REQS)'
7
+ 2n:
8
+ short_message: 'Checked out, due %DATE'
9
+ long_message: 'Checked out, due %DATE - Recall, or try Borrow Direct or ILL.'
10
+ services:
11
+ - recall_hold
12
+ - borrow_direct
13
+ - ill
14
+ 2r:
15
+ short_message: 'Checked out, due %DATE (Requests: %REQS)'
16
+ long_message: 'Checked out, due %DATE (Requests: %REQS). Try Borrow Direct or ILL.'
17
+ services:
18
+ - borrow_direct
19
+ - ill
20
+ 3n:
21
+ short_message: 'Checked out, due %DATE'
22
+ long_message: 'Checked out, due %DATE - Recall, or try Borrow Direct or ILL.'
23
+ services:
24
+ - recall_hold
25
+ - borrow_direct
26
+ - ill
27
+ 3r:
28
+ short_message: 'Checked out, due %DATE (Requests: %REQS)'
29
+ long_message: 'Checked out, due %DATE (Requests: %REQS). Try Borrow Direct or ILL.'
30
+ services:
31
+ - borrow_direct
32
+ - ill
33
+ 4n:
34
+ short_message: 'Overdue as of %DATE'
35
+ long_message: 'Overdue as of %DATE - Recall, or try Borrow Direct.'
36
+ services:
37
+ - recall_hold
38
+ - borrow_direct
39
+ 4r:
40
+ short_message: 'Overdue as of %DATE (Requests: %REQS)'
41
+ long_message: 'Overdue as of %DATE (Requests: %REQS). Try Borrow Direct or ILL.'
42
+ services:
43
+ - borrow_direct
44
+ - ill
45
+ 5n:
46
+ short_message: 'Requests: %REQS'
47
+ long_message: 'Requests: %REQS'
48
+ 5r:
49
+ short_message: 'Checked out, due %DATE (Requests: %REQS)'
50
+ long_message: 'Checked out, due %DATE (Requests: %REQS). Try Borrow Direct or ILL.'
51
+ services:
52
+ - borrow_direct
53
+ - ill
54
+ 6n:
55
+ short_message: 'Requests: %REQS'
56
+ long_message: 'Requests: %REQS'
57
+ 6r:
58
+ short_message: 'Checked out, due %DATE (Requests: %REQS)'
59
+ long_message: 'Checked out, due %DATE (Requests: %REQS). Try Borrow Direct or ILL.'
60
+ services:
61
+ - borrow_direct
62
+ - ill
63
+ 7n:
64
+ short_message: 'On hold at %LOC'
65
+ long_message: 'On hold at %LOC. Try Borrow Direct or ILL.'
66
+ services:
67
+ - borrow_direct
68
+ - ill
69
+ 7r:
70
+ short_message: 'On hold at %LOC (Requests: %REQS)'
71
+ long_message: 'On hold at %LOC (Requests: %REQS). Try Borrow Direct or ILL.'
72
+ services:
73
+ - borrow_direct
74
+ - ill
75
+ 8n:
76
+ short_message: 'In transit %DATE'
77
+ long_message: 'In transit %DATE. Place a hold request.'
78
+ services:
79
+ - recall_hold
80
+ 8r:
81
+ short_message: 'In transit %DATE (Requests: %REQS)'
82
+ long_message: 'In transit %DATE (Requests: %REQS). Try Borrow Direct or ILL.'
83
+ services:
84
+ - borrow_direct
85
+ - ill
86
+ 9n:
87
+ short_message: 'In transit to %LOC %DATE'
88
+ long_message: 'In transit to %LOC %DATE. Place a hold request.'
89
+ services:
90
+ - recall_hold
91
+ 9r:
92
+ short_message: 'In transit to %LOC %DATE (Requests: %REQS)'
93
+ long_message: 'In transit to %LOC %DATE (Requests: %REQS). Try Borrow Direct.'
94
+ services:
95
+ - borrow_direct
96
+ 10n:
97
+ short_message: 'In transit to %LOC %DATE. Place a hold request.'
98
+ long_message: 'In transit to %LOC %DATE. Place a hold request.'
99
+ services:
100
+ - recall_hold
101
+ 10r:
102
+ short_message: 'In transit to %LOC %DATE (Requests: %REQS)'
103
+ long_message: 'In transit to %LOC %DATE (Requests: %REQS). Try Borrow Direct.'
104
+ services:
105
+ - borrow_direct
106
+ 11n:
107
+ short_message: 'Returned %DATE'
108
+ long_message: 'Returned %DATE'
109
+ 11r:
110
+ short_message: 'Returned %DATE (Requests: %REQS)'
111
+ long_message: 'Returned %DATE (Requests: %REQS). Try Borrow Direct or ILL.'
112
+ services:
113
+ - borrow_direct
114
+ - ill
115
+ 12n:
116
+ short_message: 'Missing %DATE'
117
+ long_message: 'Missing %DATE. Try Borrow Direct or ILL.'
118
+ services:
119
+ - borrow_direct
120
+ - ill
121
+ 12r:
122
+ short_message: 'Missing %DATE (Requests: %REQS)'
123
+ long_message: 'Missing %DATE (Requests: %REQS). Try Borrow Direct or ILL.'
124
+ services:
125
+ - borrow_direct
126
+ - ill
127
+ 13n:
128
+ short_message: 'Unavailable %DATE'
129
+ long_message: 'Unavailable %DATE. Try Borrow Direct or ILL.'
130
+ services:
131
+ - borrow_direct
132
+ - ill
133
+ 13r:
134
+ short_message: 'Unavailable %DATE (Requests: %REQS)'
135
+ long_message: 'Unavailable %DATE (Requests: %REQS). Try Borrow Direct or ILL.'
136
+ services:
137
+ - borrow_direct
138
+ - ill
139
+ 14n:
140
+ short_message: 'Unavailable %DATE'
141
+ long_message: 'Unavailable %DATE. Try Borrow Direct or ILL.'
142
+ services:
143
+ - borrow_direct
144
+ - ill
145
+ 14r:
146
+ short_message: 'Unavailable %DATE (Requests: %REQS)'
147
+ long_message: 'Unavailable %DATE (Requests: %REQS). Try Borrow Direct or ILL.'
148
+ services:
149
+ - borrow_direct
150
+ - ill
151
+ 18n:
152
+ short_message: 'Sent to bindery for 1 month on %DATE'
153
+ long_message: 'Sent to bindery for 1 month on %DATE. Try Borrow Direct or ILL. '
154
+ services:
155
+ - borrow_direct
156
+ - ill
157
+ 18r:
158
+ short_message: 'Sent to bindery for 1 month on %DATE (Requests: %REQS)'
159
+ long_message: 'Sent to bindery for 1 month on %DATE (Requests: %REQS). Try Borrow Direct or ILL.'
160
+ services:
161
+ - borrow_direct
162
+ - ill
163
+ 22n:
164
+ short_message: 'In Process %DATE'
165
+ long_message: 'In Process %DATE. Place an In Process item request.'
166
+ services:
167
+ - in_process
168
+ 22r:
169
+ short_message: 'In Process %DATE (Requests: %REQS)'
170
+ long_message: 'In Process %DATE (Requests: %REQS). Place an In Process item request.'
171
+ services:
172
+ - in_process
@@ -0,0 +1,25 @@
1
+ '0':
2
+ short_message: 'In the Pre-Order Process'
3
+ long_message: 'In the Pre-Order Process. Try Borrow Direct or ILL.'
4
+ services:
5
+ - borrow_direct
6
+ - ill
7
+ '1':
8
+ short_message: 'Received %DATE'
9
+ long_message: 'Received %DATE. Place an In Process item request.'
10
+ services:
11
+ - in_process
12
+ '4':
13
+ short_message: 'Not yet received; claimed %DATE'
14
+ long_message: 'Not yet received; claimed %DATE. Try Borrow Direct or ILL.'
15
+ services:
16
+ - on_order
17
+ - borrow_direct
18
+ - ill
19
+ '8':
20
+ short_message: 'Copy On Order %DATE'
21
+ long_message: 'Copy On Order %DATE. Try Borrow Direct or ILL.'
22
+ services:
23
+ - on_order
24
+ - borrow_direct
25
+ - ill
@@ -0,0 +1,33 @@
1
+ module Voyager
2
+ class Collection
3
+ attr_reader :holdings, :holdings_status
4
+
5
+ def initialize(args = {})
6
+ @connection = args[:connection] || raise("Must pass a connection")
7
+ @bibid = args[:bibid] || raise("Must pass a bibid")
8
+ @bibid = @bibid.to_s
9
+
10
+ parse_results
11
+
12
+ end
13
+
14
+ def to_hash(args = {})
15
+ {
16
+ statuses: @holdings_status.to_hash(args)
17
+ }
18
+ end
19
+
20
+ private
21
+
22
+ def parse_results
23
+ results = @connection.results['retrieve_holdings'][@bibid]
24
+
25
+ @holdings = results.reject { |r| r["MFHD_ID"].nil? }
26
+ status = Status.new(holdings)
27
+
28
+ @holdings_status = status.statuses
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,94 @@
1
+ module Voyager
2
+ class OracleConnection
3
+
4
+ attr_reader :connection
5
+ attr_accessor :results
6
+
7
+ def initialize(args = {})
8
+ @connection = args['connection']
9
+
10
+
11
+ unless args.has_key?('connection')
12
+ app_config_filename = File.join(File.dirname(__FILE__), "..", "config" ,"app_config.yml")
13
+
14
+ args = YAML.load_file(app_config_filename)['oracle_connection_details'] if args == {} and File.exists?(app_config_filename)
15
+
16
+ raise "Need argument 'user'" unless args.has_key?('user')
17
+ raise "Need argument 'password'" unless args.has_key?('password')
18
+ raise "Need argument 'service'" unless args.has_key?('service')
19
+
20
+ @connection = OCI8.new(args['user'], args['password'], args['service'])
21
+ @connection.prefetch_rows = 1000
22
+ end
23
+
24
+ @results = {}
25
+
26
+ end
27
+
28
+
29
+ def retrieve_holdings(*bibids)
30
+ query = <<-HERE
31
+ select a.bib_id, a.mfhd_id, c.item_id, item_status
32
+ from bib_mfhd a, mfhd_master b, mfhd_item c, item_status d
33
+ where a.bib_id IN (~bibid~) and
34
+ b.mfhd_id = a.mfhd_id and
35
+ suppress_in_opac = 'N' and
36
+ c.mfhd_id (+) = b.mfhd_id and
37
+ d.item_id (+) = c.item_id
38
+ order by c.mfhd_id, c.item_id, item_status
39
+ HERE
40
+
41
+
42
+ raw_results = execute_select_command(query, bibid: bibids)
43
+ parse_results(raw_results, name: 'retrieve_holdings', hash_by: 'BIB_ID')
44
+ end
45
+
46
+
47
+ private
48
+
49
+ def parse_results(results, *args)
50
+ options = args.extract_options!
51
+ @results[options[:name]] ||= {}
52
+ result_hash = @results[options[:name]]
53
+
54
+ results.each do |row|
55
+ if (key = row[options[:hash_by]])
56
+ result_hash[key] ||= []
57
+ result_hash[key] << row
58
+ end
59
+ end
60
+
61
+ return result_hash
62
+ end
63
+
64
+
65
+
66
+
67
+ def execute_select_command(query, *args)
68
+ options = args.extract_options!
69
+ options.each do |name, value|
70
+ value = [value] unless value.kind_of?(Array)
71
+ formatted_value = value.collect { |item| "'#{item.to_s.gsub("'","''")}'"}.join(',')
72
+ query.gsub!("~#{name.to_s}~",formatted_value)
73
+ end
74
+
75
+
76
+ cursor = @connection.parse(query)
77
+
78
+ results = []
79
+ cursor.exec
80
+
81
+ cursor.fetch_hash do |row|
82
+ results << row
83
+ end
84
+
85
+ cursor.close
86
+
87
+ return results
88
+
89
+
90
+ end
91
+
92
+
93
+ end
94
+ end