libis-services 0.1.5 → 0.1.7
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 +4 -4
- data/lib/libis/services/oai.rb +96 -0
- data/lib/libis/services/oracle_client.rb +25 -5
- data/lib/libis/services/rosetta/oai_pmh.rb +6 -34
- data/lib/libis/services/scope/search.rb +25 -11
- data/lib/libis/services/version.rb +1 -1
- data/lib/libis/services/viaa/oai_pmh.rb +18 -0
- data/libis-services.gemspec +1 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb98081d6394e2093ac0b8faac32ab71565907a5
|
4
|
+
data.tar.gz: dfa48fcdcf42bc7da12135dad5ef2dcac93e7ee3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 630bb576af4a70ab7cfe42bb0f2acca199f6912382b859249c90bad41e6c55450afe504e0e116a4132f4c84d037650bfde2a9ff97271240834cd73af96cf2ef3
|
7
|
+
data.tar.gz: b6c80cfadae173fa8ee98a8662c644a843b8e5a09a7267083859396c9711d31c356e7e0d098656491a3d9ef992594badfc1106ccfccb67840e9c82834f97b989
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'oai'
|
2
|
+
require 'libis/tools/extend/hash'
|
3
|
+
require 'libis/services/service_error'
|
4
|
+
|
5
|
+
module Libis
|
6
|
+
module Services
|
7
|
+
class Oai
|
8
|
+
include OAI::XPath
|
9
|
+
|
10
|
+
class Query
|
11
|
+
attr_accessor :from, :until, :set, :metadata_prefix
|
12
|
+
|
13
|
+
def intialize(metadata_prefix = 'oai_dc')
|
14
|
+
@from = @until = @set = nil
|
15
|
+
@metadata_prefix = metadata_prefix
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
{ from: @from, until: @until, metadata_prefix: @metadata_prefix, set: @set }.cleanup
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(url, options = {})
|
25
|
+
options[:debug] = true
|
26
|
+
@oai_client = OAI::Client.new(url, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def identify
|
30
|
+
do_oai_request(:identify)
|
31
|
+
end
|
32
|
+
|
33
|
+
def sets(token = nil)
|
34
|
+
options = { resumption_token: token }
|
35
|
+
do_oai_request(:list_sets, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def metdata_formats(identifier = nil)
|
39
|
+
do_oai_request(:list_metadata_formats, {identifier: identifier})
|
40
|
+
end
|
41
|
+
|
42
|
+
def identifiers(token = nil, query = Query.new)
|
43
|
+
options = token ? {resumption_token: token} : query.to_hash
|
44
|
+
do_oai_request(:list_identifiers, options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def records(token = nil, query = Query.new)
|
48
|
+
options = token ? {resumption_token: token} : query.to_hash
|
49
|
+
do_oai_request(:list_records, options)
|
50
|
+
end
|
51
|
+
|
52
|
+
def record(identifier, metadata_prefix)
|
53
|
+
do_oai_request(:get_record, identifier: identifier, metadata_prefix: metadata_prefix)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def do_oai_request(method, options = {})
|
59
|
+
response = @oai_client.send(method, options.cleanup)
|
60
|
+
object_to_hash(response)
|
61
|
+
rescue OAI::Exception => e
|
62
|
+
raise Libis::Services::ServiceError, "OAI Error: #{e.code} - #{e.message}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def object_to_hash(obj)
|
66
|
+
case obj
|
67
|
+
when Array
|
68
|
+
obj.map { |x| object_to_hash(x) }
|
69
|
+
when Hash
|
70
|
+
obj.each_with_object({}) do |k,v,h|
|
71
|
+
h[k] = object_to_hash(v)
|
72
|
+
end
|
73
|
+
when REXML::Element
|
74
|
+
obj.to_s
|
75
|
+
when OAI::Response, OAI::Header, OAI::Record, OAI::MetadataFormat
|
76
|
+
result = obj.instance_variables.map do |x|
|
77
|
+
x[1..-1].to_sym
|
78
|
+
end.select do |x|
|
79
|
+
![:_source, :doc, :resumption_block].include? x
|
80
|
+
end.each_with_object({}) do |x, h|
|
81
|
+
h[x] = object_to_hash obj.send(x)
|
82
|
+
end
|
83
|
+
if obj.methods.include?(:entries)
|
84
|
+
result[:entries] = obj.entries.map do |entry|
|
85
|
+
object_to_hash(entry)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
result
|
89
|
+
else
|
90
|
+
obj
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -1,18 +1,42 @@
|
|
1
|
+
require 'oci8'
|
2
|
+
|
1
3
|
module Libis
|
2
4
|
module Services
|
3
5
|
|
4
6
|
class OracleClient
|
5
7
|
|
8
|
+
attr_reader :oci
|
9
|
+
|
6
10
|
def initialize(database, user, password)
|
7
11
|
@database = database
|
8
12
|
@user = user
|
9
13
|
@password = password
|
14
|
+
@oci = OCI8.new(user, password, database)
|
15
|
+
ObjectSpace.define_finalizer( self, self.class.finalize(@oci) )
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.finalize(oci)
|
19
|
+
proc { oci.logoff }
|
20
|
+
end
|
21
|
+
|
22
|
+
# @param [Boolean] value
|
23
|
+
def blocking=(value)
|
24
|
+
oci.non_blocking = !value
|
25
|
+
blocking?
|
26
|
+
end
|
27
|
+
|
28
|
+
def blocking?
|
29
|
+
!oci.non_blocking?
|
10
30
|
end
|
11
31
|
|
12
32
|
def call(procedure, parameters = [])
|
13
33
|
params = ''
|
14
34
|
params = "'" + parameters.join("','") + "'" if parameters and parameters.size > 0
|
15
|
-
|
35
|
+
oci.exec("call #{procedure}(#{params})")
|
36
|
+
end
|
37
|
+
|
38
|
+
def execute(statement, *bindvars, &block)
|
39
|
+
oci.exec(statement, *bindvars, &block)
|
16
40
|
end
|
17
41
|
|
18
42
|
def run(script, parameters = [])
|
@@ -21,10 +45,6 @@ module Libis
|
|
21
45
|
process_result `sqlplus -S #{@user}/#{@password}@#{@database} @#{script} #{params}`
|
22
46
|
end
|
23
47
|
|
24
|
-
def execute(sql)
|
25
|
-
process_result `echo \"#{sql}\" | sqlplus -S #{@user}/#{@password}@#{@database}`
|
26
|
-
end
|
27
|
-
|
28
48
|
private
|
29
49
|
|
30
50
|
def process_result(log)
|
@@ -1,45 +1,17 @@
|
|
1
|
-
|
2
|
-
require 'oai'
|
3
|
-
require 'libis/tools/extend/hash'
|
1
|
+
require 'libis/services/oai'
|
4
2
|
|
5
3
|
module Libis
|
6
4
|
module Services
|
7
5
|
module Rosetta
|
8
|
-
class OaiPmh
|
9
|
-
include OAI::XPath
|
6
|
+
class OaiPmh < Libis::Services::Oai
|
10
7
|
|
11
8
|
def initialize(base_url = 'http://depot.lias.be', options = {})
|
12
|
-
|
9
|
+
super('http://depot.lias.be')
|
13
10
|
end
|
14
11
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
{name: oai_set.name, spec: oai_set.spec, description: oai_set.description}.cleanup
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def collections(institute, status = {})
|
23
|
-
result = records("#{institute}-collections", status)
|
24
|
-
result.map do |record|
|
25
|
-
record[:title] = xpath_first(record[:metadata], './/dc:title').text
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def records(spec, status = {})
|
30
|
-
options = { set: spec }
|
31
|
-
options[:resumption_token] = status[:token] if status[:token]
|
32
|
-
result = []
|
33
|
-
response = @oai_client.list_records(options)
|
34
|
-
response.each do |record|
|
35
|
-
next if record.deleted?
|
36
|
-
result << {
|
37
|
-
id: record.header.identifier,
|
38
|
-
date: record.header.datestamp,
|
39
|
-
metadata: record.metadata,
|
40
|
-
}
|
41
|
-
end
|
42
|
-
result
|
12
|
+
def collections(institute, token = nil, query = Query.new)
|
13
|
+
query.set = "#{institute}-collections"
|
14
|
+
records(token, query)
|
43
15
|
end
|
44
16
|
|
45
17
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'libis/services/generic_search'
|
3
2
|
require 'libis/services/oracle_client'
|
4
3
|
require 'libis/tools/xml_document'
|
5
4
|
|
@@ -10,24 +9,39 @@ module Libis
|
|
10
9
|
class Search
|
11
10
|
include ::Libis::Services::GenericSearch
|
12
11
|
|
12
|
+
attr_reader :oracle
|
13
|
+
|
13
14
|
def initialize
|
14
15
|
@doc = nil
|
15
16
|
end
|
16
17
|
|
18
|
+
def connect(name, password)
|
19
|
+
@oracle = OracleClient.new(
|
20
|
+
'libis-db-scope.cc.kuleuven.be:1556/SCOPEP.kuleuven.be',
|
21
|
+
name, password
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
17
25
|
def find(term, options = {})
|
18
26
|
super
|
19
|
-
|
20
|
-
|
21
|
-
|
27
|
+
end
|
28
|
+
|
29
|
+
def query(term, _options = {})
|
30
|
+
@oracle.call('kul_packages.scope_xml_meta_file_ed', [term.upcase])
|
31
|
+
term = term.gsub(/[-\/]/, '_')
|
32
|
+
err_file = "/nas/vol03/oracle/SCOPEP/#{term}_err.XML"
|
33
|
+
md_file = "/nas/vol03/oracle/SCOPEP/#{term}_md.XML"
|
22
34
|
if File.exist? err_file
|
23
|
-
doc = XmlDocument.open(err_file)
|
24
|
-
msg = doc
|
25
|
-
|
26
|
-
File.delete(err_file)
|
35
|
+
doc = Libis::Tools::XmlDocument.open(err_file)
|
36
|
+
msg = doc['/error/error_msg']
|
37
|
+
detail = doc['/error/error_']
|
38
|
+
File.delete(err_file) rescue nil
|
27
39
|
@doc = nil
|
28
|
-
raise RuntimeError, "Scope search failed: '#{msg}'. Details: '#{
|
40
|
+
raise RuntimeError, "Scope search failed: '#{msg}'. Details: '#{detail}'"
|
41
|
+
elsif File.exist? md_file
|
42
|
+
@doc = Libis::Tools::XmlDocument.open(md_file)
|
29
43
|
else
|
30
|
-
|
44
|
+
raise RuntimeError, 'Scope search did not generate expected result file.'
|
31
45
|
end
|
32
46
|
end
|
33
47
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'libis/services/oai'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module Libis
|
5
|
+
module Services
|
6
|
+
module Viaa
|
7
|
+
class OaiPmh < Libis::Services::Oai
|
8
|
+
|
9
|
+
def initialize(name, password)
|
10
|
+
token = Base64.encode64("#{name}:#{password}").gsub("\n", '')
|
11
|
+
base_url = 'https://archief.viaa.be/mediahaven-oai/oai'
|
12
|
+
super(base_url, headers: {'Authorization' => "Basic #{token}"})
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/libis-services.gemspec
CHANGED
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_runtime_dependency 'savon', '~> 2.11'
|
35
35
|
spec.add_runtime_dependency 'rest-client', '~> 1.8'
|
36
36
|
spec.add_runtime_dependency 'oai', '~> 0.4'
|
37
|
+
spec.add_runtime_dependency 'ruby-oci8', '~> 2.2.2'
|
37
38
|
spec.add_runtime_dependency 'virtus', '~> 1.0'
|
38
39
|
spec.add_runtime_dependency 'write_xlsx', '~> 0.83'
|
39
40
|
spec.add_runtime_dependency 'awesome_print', '~> 1.6'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libis-services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Dekeyser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0.4'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: ruby-oci8
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 2.2.2
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 2.2.2
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: virtus
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -235,6 +249,7 @@ files:
|
|
235
249
|
- lib/libis/services/extend/http_fetch.rb
|
236
250
|
- lib/libis/services/generic_search.rb
|
237
251
|
- lib/libis/services/http_error.rb
|
252
|
+
- lib/libis/services/oai.rb
|
238
253
|
- lib/libis/services/oracle_client.rb
|
239
254
|
- lib/libis/services/primo.rb
|
240
255
|
- lib/libis/services/primo/limo.rb
|
@@ -266,6 +281,7 @@ files:
|
|
266
281
|
- lib/libis/services/soap_client.rb
|
267
282
|
- lib/libis/services/soap_error.rb
|
268
283
|
- lib/libis/services/version.rb
|
284
|
+
- lib/libis/services/viaa/oai_pmh.rb
|
269
285
|
- libis-services.gemspec
|
270
286
|
- spec/alma_service_spec.rb
|
271
287
|
- spec/ie_data.rb
|
@@ -299,7 +315,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
299
315
|
version: '0'
|
300
316
|
requirements: []
|
301
317
|
rubyforge_project:
|
302
|
-
rubygems_version: 2.4
|
318
|
+
rubygems_version: 2.6.4
|
303
319
|
signing_key:
|
304
320
|
specification_version: 4
|
305
321
|
summary: LIBIS Services toolbox.
|