libis-services 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3579b3767e5c7b66ebbc0c98c01f0c4164aafa89
4
- data.tar.gz: b8e1fe27dceb49ad0d3fa234adaf4aedc942b3b9
3
+ metadata.gz: fb0d96192182c5e54643bfd203b7245a3269701b
4
+ data.tar.gz: df4a65fd9bcf511d3e4719a896d2ae206378f985
5
5
  SHA512:
6
- metadata.gz: c54622890dce4e6f3325e26d5aa33792d9a109252c91d4a6ebd76c4e8844fd62efa01cc15331ea9ac46d58f8825ff414ce9ec300bf3dc45aeb911f28919ec7b7
7
- data.tar.gz: 5dd37c5e3740b0b55d12a0b9b01ff8690a33d83f2c1ad7818d7a8f56c41b223b7d14d98798a45c237973a61e880ccd51ac64dd79e40f33424c2b8fcd2484f88e
6
+ metadata.gz: f1969f4ed616aec04c489553fd2234e55b95732ce76b1484c6a28ad1e182c30143fdc538f0c8660665883ed926b9c449426e929ec8e161ebe4df892dbb40b8f6
7
+ data.tar.gz: 08bc1acb1bc9e41313e2dbdff6e234b67c6c6aeeac81ad1da93dd95d0b006222f3f6f191b22089033655e9868617542afec59c04ba94a79612b0ccc79d2389df
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ require 'libis-tools'
3
+ require 'libis/services/service_error'
4
+ require 'libis/services/rest_client'
5
+
6
+ module Libis
7
+ module Services
8
+ module Alma
9
+
10
+ class WebService
11
+ include ::Libis::Services::RestClient
12
+
13
+ def initialize(url = 'https://api-eu.hosted.exlibrisgroup.com/almaws/v1/bibs')
14
+ configure(url)
15
+ end
16
+
17
+ def get_marc(alma_id, apikey = nil)
18
+ apikey ||= case alma_id
19
+ when /1480$/
20
+ 'l7xx8879c82a7d7b453a887a6e6dca8300fd'
21
+ else
22
+ raise Libis::Services::ServiceError, "No Alma API key available for '#{alma_id}'"
23
+ end
24
+ get alma_id, apikey: apikey
25
+ end
26
+
27
+ protected
28
+
29
+ def result_parser(response)
30
+ Libis::Tools::XmlDocument.parse(response)
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,12 +1,13 @@
1
1
  # coding: utf-8
2
2
 
3
- require 'libis/services/soap_client'
3
+ require 'awesome_print'
4
+
4
5
  require 'libis/tools/extend/hash'
5
6
  require 'libis/tools/config'
6
7
  require 'libis/tools/logger'
7
8
 
8
- require 'awesome_print'
9
-
9
+ require 'libis/services/soap_client'
10
+ require 'libis/services/service_error'
10
11
  module Libis
11
12
  module Services
12
13
  module Rosetta
@@ -68,8 +69,8 @@ module Libis
68
69
 
69
70
  # check for errors
70
71
  if data.delete :is_error
71
- error data.delete :error_description
72
- return nil
72
+ msg = data.delete(:error_description) || data.delete(:message_desc)
73
+ raise Libis::Services::ServiceError.new(msg)
73
74
  end
74
75
 
75
76
  # only delete if there is other info. ProducerService isUserExists uses this field as return value.
@@ -95,7 +96,7 @@ module Libis
95
96
  data.is_a?(Array) ? data : []
96
97
  end
97
98
 
98
- def reqeust_object_array(method, klass, args = {})
99
+ def request_object_array(method, klass, args = {})
99
100
  data = request_array(method, args)
100
101
  data.map { |x| klass.new(x) }
101
102
  end
@@ -25,7 +25,7 @@ module Libis
25
25
  end
26
26
 
27
27
  def create(collection_info)
28
- collection_info = collection_info.attributes if collection_info.is_a? CollectionInfo
28
+ collection_info = collection_info.to_hash.cleanup if collection_info.is_a? CollectionInfo
29
29
  call :create_collection, pds_handle: @pds_handle, collection: collection_info
30
30
  end
31
31
 
@@ -1,35 +1,44 @@
1
1
  # encoding: utf-8
2
2
  require 'virtus'
3
3
 
4
- class Libis::Services::Rosetta::CollectionInfo
5
- # noinspection RubyResolve
6
- include Virtus.model
7
-
8
- class MetaData
9
- # noinspection RubyResolve
10
- include Virtus.model
11
-
12
- attribute :mid, String
13
- attribute :type, String
14
- attribute :sub_type, String
15
- attribute :content, String
16
- end
4
+ module Libis
5
+ module Services
6
+ module Rosetta
17
7
 
18
- attribute :id, String
19
- attribute :name, String
20
- attribute :parent_id, String
21
- attribute :md_dc, MetaData
22
- attribute :md_source, Array[MetaData]
23
- attribute :navigate, Boolean
24
- attribute :publish, Boolean
25
- attribute :external_id, String
26
- attribute :external_system, String
27
-
28
- def to_hash
29
- result = self.attributes
30
- result[:md_dc] = result[:md_dc].attributes if result[:md_dc]
31
- result[:md_source] = result[:md_source].map { |md| md.attributes }
32
- result
33
- end
8
+ class CollectionInfo
9
+ # noinspection RubyResolve
10
+ include Virtus.model
11
+
12
+ class MetaData
13
+ # noinspection RubyResolve
14
+ include Virtus.model
15
+
16
+ attribute :mid, String
17
+ attribute :type, String
18
+ attribute :sub_type, String
19
+ attribute :content, String
20
+ end
34
21
 
22
+ attribute :id, String
23
+ attribute :name, String
24
+ attribute :parent_id, String
25
+ attribute :description, String
26
+ attribute :md_dc, MetaData
27
+ attribute :md_source, Array[MetaData]
28
+ attribute :navigate, Boolean
29
+ attribute :publish, Boolean
30
+ attribute :external_id, String
31
+ attribute :external_system, String
32
+
33
+ def to_hash
34
+ result = self.attributes
35
+ result[:md_dc] = result[:md_dc].attributes if result[:md_dc]
36
+ result[:md_source] = result[:md_source].map { |md| md.attributes }
37
+ result
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
35
44
  end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ require 'oai'
3
+ require 'libis/tools/extend/hash'
4
+
5
+ module Libis
6
+ module Services
7
+ module Rosetta
8
+ class OaiPmh
9
+ include OAI::XPath
10
+
11
+ def initialize(base_url = 'http://depot.lias.be', options = {})
12
+ @oai_client = OAI::Client.new(base_url + '/oaiprovider/request', options)
13
+ end
14
+
15
+ def sets
16
+ response = @oai_client.list_sets
17
+ response.map do |oai_set|
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
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,21 @@
1
+ require 'virtus'
2
+
3
+ module Libis
4
+ module Services
5
+ module Rosetta
6
+ class OaiSet
7
+ # noinspection RubyResolve
8
+ include Virtus.model nullify_blank: true
9
+
10
+ attribute :description, String
11
+ attribute :name, String
12
+ attribute :spec, String
13
+
14
+ def to_hash
15
+ super.cleanup
16
+ end
17
+
18
+ end
19
+ end
20
+ end
21
+ end
@@ -4,6 +4,7 @@ require_relative 'deposit_handler'
4
4
  require_relative 'sip_handler'
5
5
  require_relative 'ie_handler'
6
6
  require_relative 'collection_handler'
7
+ require_relative 'oai_pmh'
7
8
 
8
9
  require 'libis/tools/mets_file'
9
10
 
@@ -16,18 +17,20 @@ module Libis
16
17
  module Services
17
18
  module Rosetta
18
19
 
20
+ # noinspection RubyTooManyInstanceVariablesInspection
19
21
  class Service
20
22
 
21
23
  attr_reader :pds_service, :producer_service, :deposit_service, :sip_service, :ie_service, :collection_service
22
24
 
23
25
  # @param [String] base_url
24
- def initialize(base_url = 'http://depot.lias.be', pds_url = 'https://pds.libis.be')
26
+ def initialize(base_url = 'http://depot.lias.be', pds_url = 'https://pds.libis.be', opts = {})
25
27
  @pds_service = Libis::Services::Rosetta::PdsHandler.new pds_url
26
- @producer_service = Libis::Services::Rosetta::ProducerHandler.new base_url
27
- @deposit_service = Libis::Services::Rosetta::DepositHandler.new base_url
28
- @sip_service = Libis::Services::Rosetta::SipHandler.new base_url
29
- @ie_service = Libis::Services::Rosetta::IeHandler.new base_url
30
- @collection_service = Libis::Services::Rosetta::CollectionHandler.new base_url
28
+ @producer_service = Libis::Services::Rosetta::ProducerHandler.new base_url, opts
29
+ @deposit_service = Libis::Services::Rosetta::DepositHandler.new base_url, opts
30
+ @sip_service = Libis::Services::Rosetta::SipHandler.new base_url, opts
31
+ @ie_service = Libis::Services::Rosetta::IeHandler.new base_url, opts
32
+ @collection_service = Libis::Services::Rosetta::CollectionHandler.new base_url, opts
33
+ @oai_pmh_service = Libis::Services::Rosetta::OaiPmh.new base_url, opts
31
34
  end
32
35
 
33
36
  # @param [String] name
@@ -40,6 +43,7 @@ module Libis
40
43
  @deposit_service.pds_handle = handle
41
44
  @sip_service.pds_handle = handle
42
45
  @ie_service.pds_handle = handle
46
+ @collection_service.pds_handle = handle
43
47
  handle
44
48
  end
45
49
 
@@ -20,7 +20,8 @@ module Libis
20
20
  end
21
21
 
22
22
  def get_ies(sip_id)
23
- request_array :get_sip_i_es, arg0: sip_id
23
+ request_array(:get_sip_i_es, arg0: sip_id).map {|ie| Rosetta::Ie.new(pid: ie)}
24
+
24
25
  end
25
26
 
26
27
  end
@@ -1 +1,2 @@
1
- require_relative 'rosetta/service'
1
+ require_relative 'rosetta/service'
2
+ require_relative 'rosetta/oai_pmh'
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ module Libis
4
+ module Services
5
+
6
+ class ServiceError < Exception
7
+ attr_accessor :message
8
+
9
+ def initialize(error)
10
+ @message = error.to_s
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+ end
@@ -1,5 +1,5 @@
1
1
  module Libis
2
2
  module Services
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ module Libis
3
3
 
4
4
  autoload :HttpError, 'libis/services/http_error'
5
5
  autoload :SoapError, 'libis/services/soap_error'
6
+ autoload :ServiceError, 'libis/services/service_error'
6
7
 
7
8
  autoload :SoapClient, 'libis/services/soap_client'
8
9
  autoload :RestClient, 'libis/services/rest_client'
@@ -32,6 +32,7 @@ Gem::Specification.new do |gem|
32
32
  gem.add_runtime_dependency 'highline', '~> 1.7'
33
33
  gem.add_runtime_dependency 'savon', '~> 2.11'
34
34
  gem.add_runtime_dependency 'rest-client', '~> 1.8'
35
+ gem.add_runtime_dependency 'oai', '~> 0.4'
35
36
  gem.add_runtime_dependency 'virtus', '~> 1.0'
36
37
  gem.add_runtime_dependency 'write_xlsx', '~> 0.83'
37
38
  gem.add_runtime_dependency 'awesome_print', '~> 1.6'
@@ -0,0 +1,104 @@
1
+ require_relative 'spec_helper'
2
+ require 'awesome_print'
3
+
4
+ require 'libis/services/alma/web_service'
5
+
6
+ describe 'Alma web service' do
7
+ let(:subject) { Libis::Services::Alma::WebService.new }
8
+
9
+ context 'marc' do
10
+
11
+ let(:record) {
12
+ {
13
+ leader: '01206nas 2200337u 4500',
14
+ controlfield: ['9930800070101480', '20151015113543.0', '881205c19679999be r|p|| 0|||a|dut c'],
15
+ datafield: [
16
+ {
17
+ subfield: '(BeLVLBS)003080007LBS01-Aleph',
18
+ :@tag => '035', :@ind1 => ' ', :@ind2 => ' '
19
+ }, {
20
+ subfield: '(EXLNZ-32KUL_LIBIS_NETWORK)9930800070101471',
21
+ :@tag => '035', :@ind1 => ' ', :@ind2 => ' '
22
+ }, {
23
+ subfield: 'Kerk en leven. Bisdom Antwerpen (0991).',
24
+ :@tag => '245', :@ind1 => '0', :@ind2 => '0'
25
+ }, {
26
+ subfield: 'K & L',
27
+ :@tag => '246', :@ind1 => '3', :@ind2 => '3'
28
+ }, {
29
+ subfield: ['Antwerpen', 'Kerk en leven,', '1967-.'],
30
+ :@tag => '260', :@ind1 => ' ', :@ind2 => ' '
31
+ }, {
32
+ subfield: 'Weekly',
33
+ :@tag => '310', :@ind1 => ' ', :@ind2 => ' '
34
+ }, {
35
+ subfield: %w(text rdacontent),
36
+ :@tag => '336', :@ind1 => ' ', :@ind2 => ' '
37
+ }, {
38
+ subfield: %w(computer rdamedia),
39
+ :@tag => '337', :@ind1 => ' ', :@ind2 => ' '
40
+ }, {
41
+ subfield: ['online resource', 'rdacarrier'],
42
+ :@tag => '338', :@ind1 => ' ', :@ind2 => ' '
43
+ }, {
44
+ subfield: 'Online',
45
+ :@tag => '340', :@ind1 => ' ', :@ind2 => ' '
46
+ }, {
47
+ subfield: 'Digitale kopie van de gedrukte uitgave',
48
+ :@tag => '500', :@ind1 => ' ', :@ind2 => ' '
49
+ }, {
50
+ subfield: 'E-journals',
51
+ :@tag => '653', :@ind1 => ' ', :@ind2 => '6'
52
+ }, {
53
+ subfield: 'Collectie Kerk en Leven',
54
+ :@tag => '699', :@ind1 => ' ', :@ind2 => ' '
55
+ }, {
56
+ subfield: ['KADOC', 'C1', 'Kerken en religie', '(ODIS-HT)'],
57
+ :@tag => '650', :@ind1 => ' ', :@ind2 => '7'
58
+ }, {
59
+ subfield: ['KADOC', 'Antwerpen [deelgemeente in gemeente Antwerpen - BE]', '(ODIS-GEO)10560000006504'],
60
+ :@tag => '650', :@ind1 => ' ', :@ind2 => '7'
61
+ }, {
62
+ subfield: ['KADOC', 'Bisdom Antwerpen (1961-heden)', '(ODIS-ORG)9284'],
63
+ :@tag => '650', :@ind1 => ' ', :@ind2 => '7'
64
+ }, {
65
+ subfield: ['KADOC', 'Studiecentrum voor Zielzorg en Predicatie', '(ODIS-ORG)24894'],
66
+ :@tag => '650', :@ind1 => ' ', :@ind2 => '7'
67
+ }, {
68
+ subfield: 'KYE000486',
69
+ :@tag => '983', :@ind1 => ' ', :@ind2 => ' '
70
+ }, {
71
+ subfield: ['EKAD', '(2007)39-42, 44, 46-49, 51-52'],
72
+ :@tag => '993', :@ind1 => ' ', :@ind2 => ' '
73
+ }, {
74
+ subfield: ['EKAD', '(2008)1-28, 32-53'],
75
+ :@tag => '993', :@ind1 => ' ', :@ind2 => ' '
76
+ }, {
77
+ subfield: ['EKAD', '(2009)1-34, 36-38'],
78
+ :@tag => '993', :@ind1 => ' ', :@ind2 => ' '
79
+ }, {
80
+ subfield: ['EKAD', '(2011)1-13, 15-36, 45-52'],
81
+ :@tag => '993', :@ind1 => ' ', :@ind2 => ' '
82
+ }, {
83
+ subfield: ['EKAD', 'KADOC elektronische tijdschriften'],
84
+ :@tag => '995', :@ind1 => ' ', :@ind2 => ' '
85
+ }, {
86
+ subfield: ['EKAD', 'KADOC lopende periodiek'],
87
+ :@tag => '995', :@ind1 => ' ', :@ind2 => ' '
88
+ }, {
89
+ subfield: ['KADOC', 'online', '201510', 'W', 'Collectie Kerk en Leven', 'local'],
90
+ :@tag => '996', :@ind1 => ' ', :@ind2 => ' '
91
+ }
92
+ ],
93
+ }
94
+ }
95
+
96
+ it 'get record' do
97
+ result = subject.get_marc('9930800070101480', 'l7xx8879c82a7d7b453a887a6e6dca8300fd').
98
+ to_hash(:convert_tags_to => lambda { |tag| tag.snakecase.to_sym })
99
+ check_container(record, result[:bib][:record])
100
+ end
101
+
102
+ end
103
+
104
+ end