openurl 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +25 -4
- data/lib/openurl/context_object.rb +6 -3
- data/lib/openurl/context_object_entity.rb +2 -0
- data/lib/openurl/metadata_formats/book.rb +2 -0
- data/lib/openurl/metadata_formats/dissertation.rb +2 -0
- data/lib/openurl/metadata_formats/dublin_core.rb +7 -3
- data/lib/openurl/metadata_formats/journal.rb +2 -0
- data/lib/openurl/metadata_formats/marc.rb +2 -0
- data/lib/openurl/metadata_formats/patent.rb +2 -0
- data/lib/openurl/metadata_formats/scholarly_common.rb +2 -0
- data/lib/openurl/metadata_formats/scholarly_service_type.rb +2 -0
- data/lib/openurl/transport.rb +2 -0
- data/lib/openurl.rb +2 -0
- data/test/context_object_entity_test.rb +1 -0
- data/test/context_object_test.rb +28 -24
- data/test/encoding_test.rb +58 -0
- metadata +25 -19
data/README
CHANGED
@@ -30,7 +30,30 @@ response format, so parsing the returned value is up to you.
|
|
30
30
|
transport = OpenURL::Transport.new('http://demo.exlibrisgroup.com:9003/lr_3', context_object)
|
31
31
|
transport.get
|
32
32
|
puts tranport.response
|
33
|
+
|
34
|
+
# Create a new ContextObject from an existing kev or XML serialization:
|
35
|
+
#
|
36
|
+
# ContextObject.new_from_kev( kev_context_object )
|
37
|
+
# ContextObject.new_from_xml( xml_context_object ) # Can be String or REXML::Document
|
38
|
+
|
39
|
+
== Ruby 1.9 and encodings
|
40
|
+
|
41
|
+
Gem does run and all tests pass under ruby 1.9. There is very limited
|
42
|
+
support for handling character encodings in the proper 1.9 way.
|
43
|
+
|
44
|
+
CTX or XML context objects will be assumed utf-8 even if the ruby string
|
45
|
+
they are held in has an ascii-8bit encoding. They will forced into a utf-8 encoding.
|
46
|
+
This seems to be a side effect of the REXML and CGI libraries we use to parse,
|
47
|
+
but there are runnable tests that assert it is true. (see test/encoding_test.rb)
|
48
|
+
|
49
|
+
Incoming context objects with a non-utf8 ctx_enc value will *not* be handled
|
50
|
+
properly, they'll still be forced to utf8.
|
51
|
+
|
52
|
+
Programmatically created context objects, you must ensure all strings are
|
53
|
+
represented as utf8 encoded yourself.
|
33
54
|
|
55
|
+
More sophisticated encoding handling can theoretically be added, but it's
|
56
|
+
somewhat non-trivial, and it's not clear anyone needs it.
|
34
57
|
|
35
58
|
== INSTALLATION
|
36
59
|
|
@@ -38,10 +61,8 @@ You should be able to install the gem:
|
|
38
61
|
|
39
62
|
gem install openurl
|
40
63
|
|
41
|
-
The source lives in
|
64
|
+
The source lives in git on github:
|
42
65
|
|
43
|
-
http://
|
66
|
+
http://github.com/openurl/openurl
|
44
67
|
|
45
|
-
== CONTACT
|
46
68
|
|
47
|
-
Bugs and suggestions to Ross Singer <rossfsinger@gmail.com>
|
@@ -1,7 +1,11 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
module OpenURL
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
+
if RUBY_VERSION < '1.9'
|
6
|
+
require 'jcode'
|
7
|
+
$KCODE='UTF-8'
|
8
|
+
end
|
5
9
|
|
6
10
|
##
|
7
11
|
# The ContextObject class is intended to both create new OpenURL 1.0 context
|
@@ -47,7 +51,6 @@ module OpenURL
|
|
47
51
|
@serviceType = []
|
48
52
|
@resolver = []
|
49
53
|
@foreign_keys = {}
|
50
|
-
$KCODE='UTF-8'
|
51
54
|
@admin = {"ctx_ver"=>{"label"=>"version", "value"=>"Z39.88-2004"}, "ctx_tim"=>{"label"=>"timestamp", "value"=>DateTime.now().to_s}, "ctx_id"=>{"label"=>"identifier", "value"=>""}, "ctx_enc"=>{"label"=>"encoding", "value"=>"info:ofi/enc:UTF-8"}}
|
52
55
|
end
|
53
56
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
1
3
|
#
|
2
4
|
# dublin_core.rb
|
3
5
|
#
|
@@ -54,11 +56,13 @@ module OpenURL
|
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
57
|
-
def import_xml_metadata(node)
|
59
|
+
def import_xml_metadata(node)
|
58
60
|
mbv = REXML::XPath.first(node, "./ctx:metadata-by-val/ctx:metadata/fmt:dc", {"ctx"=>"info:ofi/fmt:xml:xsd:ctx", "fmt"=>@oai_ns})
|
59
61
|
if mbv
|
60
|
-
mbv.to_a.each do |m|
|
61
|
-
|
62
|
+
mbv.to_a.each do |m|
|
63
|
+
m.children.each do | value|
|
64
|
+
self.set_metadata(m.name(), CGI.unescapeHTML(value.to_s))
|
65
|
+
end
|
62
66
|
end
|
63
67
|
end
|
64
68
|
end
|
data/lib/openurl/transport.rb
CHANGED
data/lib/openurl.rb
CHANGED
data/test/context_object_test.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
Encoding.default_external = "UTF-8" if defined? Encoding
|
4
|
+
|
1
5
|
class ContextObjectTest < Test::Unit::TestCase
|
2
6
|
|
3
7
|
def test_create_ctx
|
@@ -273,30 +277,6 @@ class ContextObjectTest < Test::Unit::TestCase
|
|
273
277
|
test_not_shared_objects( ctx_orig, ctx_with_imported_data )
|
274
278
|
|
275
279
|
end
|
276
|
-
|
277
|
-
|
278
|
-
# Make sure ctx1 and ctx2 don't share the same data objects.
|
279
|
-
# If they did, a change to one would change the other.
|
280
|
-
def test_not_shared_objects(ctx1, ctx2)
|
281
|
-
assert_not_equal( ctx1.referent.object_id, ctx2.referent.object_id );
|
282
|
-
assert_not_equal( ctx1.referent.metadata.object_id, ctx2.referent.metadata.object_id )
|
283
|
-
|
284
|
-
original_ref_title = ctx1.referent.metadata['title']
|
285
|
-
new_title = "new test title"
|
286
|
-
# just ensure new uniqueness
|
287
|
-
new_title += original_ref_title if original_ref_title
|
288
|
-
|
289
|
-
ctx1.referent.set_metadata('title', new_title)
|
290
|
-
|
291
|
-
# That better not have changed ctx2
|
292
|
-
|
293
|
-
assert_not_equal( new_title, ctx2.referent.metadata['title'])
|
294
|
-
|
295
|
-
# Now fix first title back to what it was originally, to have no
|
296
|
-
# side-effects
|
297
|
-
ctx1.referent.set_metadata('title', original_ref_title )
|
298
|
-
end
|
299
|
-
|
300
280
|
|
301
281
|
|
302
282
|
def test_to_hash
|
@@ -372,6 +352,30 @@ class ContextObjectTest < Test::Unit::TestCase
|
|
372
352
|
assert_match("ctx_enc=#{CGI.escape("info:ofi/enc:UTF-8")}", ctx.kev)
|
373
353
|
end
|
374
354
|
|
355
|
+
protected
|
356
|
+
|
357
|
+
# Make sure ctx1 and ctx2 don't share the same data objects.
|
358
|
+
# If they did, a change to one would change the other.
|
359
|
+
def test_not_shared_objects(ctx1, ctx2)
|
360
|
+
assert_not_equal( ctx1.referent.object_id, ctx2.referent.object_id );
|
361
|
+
assert_not_equal( ctx1.referent.metadata.object_id, ctx2.referent.metadata.object_id )
|
362
|
+
|
363
|
+
original_ref_title = ctx1.referent.metadata['title']
|
364
|
+
new_title = "new test title"
|
365
|
+
# just ensure new uniqueness
|
366
|
+
new_title += original_ref_title if original_ref_title
|
367
|
+
|
368
|
+
ctx1.referent.set_metadata('title', new_title)
|
369
|
+
|
370
|
+
# That better not have changed ctx2
|
371
|
+
|
372
|
+
assert_not_equal( new_title, ctx2.referent.metadata['title'])
|
373
|
+
|
374
|
+
# Now fix first title back to what it was originally, to have no
|
375
|
+
# side-effects
|
376
|
+
ctx1.referent.set_metadata('title', original_ref_title )
|
377
|
+
end
|
378
|
+
|
375
379
|
def test_kev_values(ctx)
|
376
380
|
assert_equal(ctx.referent.format, 'book')
|
377
381
|
assert_equal(ctx.referent.class, OpenURL::Book)
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
|
4
|
+
require 'yaml'
|
5
|
+
|
6
|
+
unless "".respond_to?(:encoding)
|
7
|
+
puts <<eos
|
8
|
+
|
9
|
+
=================================================================
|
10
|
+
WARNING: Can't run encoding tests unless under ruby 1.9
|
11
|
+
#{__FILE__}
|
12
|
+
Encoding tests will NOT be run.
|
13
|
+
=================================================================
|
14
|
+
|
15
|
+
eos
|
16
|
+
else
|
17
|
+
|
18
|
+
class EncodingTest < Test::Unit::TestCase
|
19
|
+
|
20
|
+
|
21
|
+
def test_kev
|
22
|
+
# Load from string explicitly set to binary, to make sure it ends up utf-8
|
23
|
+
# anyhow.
|
24
|
+
raw_kev = "url_ver=Z39.88-2004&url_tim=2003-04-11T10%3A09%3A15TZD&url_ctx_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Actx&ctx_ver=Z39.88-2004&ctx_enc=info%3Aofi%2Fenc%3AUTF-8&ctx_id=10_8&ctx_tim=2003-04-11T10%3A08%3A30TZD&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rft.genre=book&rft.aulast=Vergnaud&rft.auinit=J.-R&rft.btitle=D%C3%A9pendances+et+niveaux+de+repr%C3%A9sentation+en+syntaxe&rft.date=1985&rft.pub=Benjamins&rft.place=Amsterdam%2C+Philadelphia&rfe_id=urn%3Aisbn%3A0262531283&rfe_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Abook&rfe.genre=book&rfe.aulast=Chomsky&rfe.auinit=N&rfe.btitle=Minimalist+Program&rfe.isbn=0262531283&rfe.date=1995&rfe.pub=The+MIT+Press&rfe.place=Cambridge%2C+Mass&svc_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Asch_svc&svc.abstract=yes&rfr_id=info%3Asid%2Febookco.com%3Abookreader".force_encoding("ascii-8bit")
|
25
|
+
|
26
|
+
assert_equal("ASCII-8BIT", raw_kev.encoding.name)
|
27
|
+
|
28
|
+
ctx = OpenURL::ContextObject.new_from_kev(raw_kev)
|
29
|
+
|
30
|
+
assert_equal("UTF-8", ctx.referent.metadata['btitle'].encoding.name)
|
31
|
+
assert_equal("Dépendances et niveaux de représentation en syntaxe", ctx.referent.metadata["btitle"])
|
32
|
+
|
33
|
+
# serialized as utf-8
|
34
|
+
assert_equal("UTF-8", ctx.kev.encoding.name)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_xml
|
38
|
+
assert_equal("ASCII-8BIT", @@xml_with_utf8.encoding.name)
|
39
|
+
|
40
|
+
ctx = OpenURL::ContextObject.new_from_xml(@@xml_with_utf8)
|
41
|
+
|
42
|
+
assert_equal("UTF-8", ctx.referent.metadata['btitle'].encoding.name)
|
43
|
+
assert_equal("Dépendances et niveaux de représentation en syntaxe", ctx.referent.metadata["btitle"])
|
44
|
+
|
45
|
+
# serialized as utf-8
|
46
|
+
assert_equal("UTF-8", ctx.xml.encoding.name)
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
@@xml_with_utf8 = <<eos
|
52
|
+
<ctx:context-objects xmlns:ctx='info:ofi/fmt:xml:xsd:ctx' xsi:schemaLocation='info:ofi/fmt:xml:xsd:ctx http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:ctx' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><ctx:context-object identifier='10_8' timestamp='2003-04-11T10:08:30TZD' version='Z39.88-2004'><ctx:referent><ctx:metadata-by-val><ctx:format>info:ofi/fmt:xml:xsd:book</ctx:format><ctx:metadata><rft:book xmlns:rft='info:ofi/fmt:xml:xsd:book' xsi:schemaLocation='info:ofi/fmt:xml:xsd:book http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:book'><rft:genre>book</rft:genre><rft:btitle>Dépendances et niveaux de représentation en syntaxe</rft:btitle><rft:date>1985</rft:date><rft:pub>Benjamins</rft:pub><rft:place>Amsterdam, Philadelphia</rft:place><rft:authors><rft:author><rft:aulast>Vergnaud</rft:aulast><rft:auinit>J.-R</rft:auinit></rft:author></rft:authors></rft:book></ctx:metadata></ctx:metadata-by-val></ctx:referent><ctx:referring-entity><ctx:metadata-by-val><ctx:format>info:ofi/fmt:xml:xsd:book</ctx:format><ctx:metadata><rfe:book xmlns:rfe='info:ofi/fmt:xml:xsd:book' xsi:schemaLocation='info:ofi/fmt:xml:xsd:book http://www.openurl.info/registry/docs/info:ofi/fmt:xml:xsd:book'><rfe:genre>book</rfe:genre><rfe:btitle>Minimalist Program</rfe:btitle><rfe:isbn>0262531283</rfe:isbn><rfe:date>1995</rfe:date><rfe:pub>The MIT Press</rfe:pub><rfe:place>Cambridge, Mass</rfe:place><rfe:authors><rfe:author><rfe:aulast>Chomsky</rfe:aulast><rfe:auinit>N</rfe:auinit></rfe:author></rfe:authors></rfe:book></ctx:metadata></ctx:metadata-by-val><ctx:identifier>urn:isbn:0262531283</ctx:identifier></ctx:referring-entity><ctx:referrer><ctx:identifier>info:sid/ebookco.com:bookreader</ctx:identifier></ctx:referrer><ctx:service-type><ctx:metadata-by-val><ctx:format>info:ofi/fmt:xml:xsd:sch_svc</ctx:format><ctx:metadata><svc:abstract xmlns:svc='info:ofi/fmt:xml:xsd:sch_svc'>yes</svc:abstract></ctx:metadata></ctx:metadata-by-val></ctx:service-type></ctx:context-object></ctx:context-objects>
|
53
|
+
eos
|
54
|
+
# Make sure it's got a raw encoding, so we can test it winds up utf-8 anyhow
|
55
|
+
@@xml_with_utf8.force_encoding("ascii-8bit")
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
metadata
CHANGED
@@ -1,21 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openurl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
+
- 2
|
8
9
|
- 0
|
9
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jonathan Rochkind
|
13
14
|
- Ross Singer
|
14
|
-
autorequire:
|
15
|
+
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date:
|
19
|
+
date: 2011-10-10 00:00:00 -04:00
|
19
20
|
default_executable:
|
20
21
|
dependencies: []
|
21
22
|
|
@@ -31,53 +32,58 @@ extra_rdoc_files:
|
|
31
32
|
- README
|
32
33
|
files:
|
33
34
|
- lib/openurl.rb
|
34
|
-
- lib/openurl/context_object.rb
|
35
35
|
- lib/openurl/context_object_entity.rb
|
36
36
|
- lib/openurl/metadata_formats/book.rb
|
37
|
-
- lib/openurl/metadata_formats/dissertation.rb
|
38
|
-
- lib/openurl/metadata_formats/dublin_core.rb
|
39
37
|
- lib/openurl/metadata_formats/journal.rb
|
38
|
+
- lib/openurl/metadata_formats/scholarly_service_type.rb
|
39
|
+
- lib/openurl/metadata_formats/dublin_core.rb
|
40
|
+
- lib/openurl/metadata_formats/scholarly_common.rb
|
40
41
|
- lib/openurl/metadata_formats/marc.rb
|
41
42
|
- lib/openurl/metadata_formats/patent.rb
|
42
|
-
- lib/openurl/metadata_formats/
|
43
|
-
- lib/openurl/metadata_formats/scholarly_service_type.rb
|
43
|
+
- lib/openurl/metadata_formats/dissertation.rb
|
44
44
|
- lib/openurl/transport.rb
|
45
|
-
-
|
46
|
-
- test/context_object_test.rb
|
47
|
-
- test/data/dc_ctx.xml
|
48
|
-
- test/data/marc_ctx.xml
|
45
|
+
- lib/openurl/context_object.rb
|
49
46
|
- test/data/metalib_sap2_post_params.yml
|
50
|
-
- test/data/
|
47
|
+
- test/data/dc_ctx.xml
|
51
48
|
- test/data/yu.xml
|
49
|
+
- test/data/scholarly_au_ctx.xml
|
50
|
+
- test/data/marc_ctx.xml
|
51
|
+
- test/context_object_entity_test.rb
|
52
52
|
- test/test.yml
|
53
|
+
- test/context_object_test.rb
|
54
|
+
- test/encoding_test.rb
|
53
55
|
- README
|
54
56
|
has_rdoc: true
|
55
|
-
homepage:
|
57
|
+
homepage: https://github.com/openurl/openurl
|
56
58
|
licenses: []
|
57
59
|
|
58
60
|
post_install_message:
|
59
|
-
rdoc_options:
|
60
|
-
|
61
|
+
rdoc_options: []
|
62
|
+
|
61
63
|
require_paths:
|
62
64
|
- lib
|
63
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
64
67
|
requirements:
|
65
68
|
- - ">="
|
66
69
|
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
67
71
|
segments:
|
68
72
|
- 0
|
69
73
|
version: "0"
|
70
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
71
76
|
requirements:
|
72
77
|
- - ">="
|
73
78
|
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
74
80
|
segments:
|
75
81
|
- 0
|
76
82
|
version: "0"
|
77
83
|
requirements: []
|
78
84
|
|
79
85
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.
|
86
|
+
rubygems_version: 1.6.2
|
81
87
|
signing_key:
|
82
88
|
specification_version: 3
|
83
89
|
summary: a Ruby library to create, parse and use NISO Z39.88 OpenURLs
|