openurl 0.2.0 → 0.2.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.
- data/README.md +71 -0
- data/lib/openurl/context_object.rb +17 -5
- data/lib/openurl/metadata_formats/scholarly_common.rb +9 -2
- data/test/context_object_test.rb +19 -0
- data/test/scholarly_common_test.rb +13 -0
- metadata +40 -44
- data/README +0 -68
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# openurl
|
2
|
+
|
3
|
+
## DESCRIPTION
|
4
|
+
|
5
|
+
openurl is a Ruby library creating, parsing and using NISO Z39.88 OpenURLs over
|
6
|
+
HTTP. <http://openurl.info/registry>
|
7
|
+
|
8
|
+
While openurl can send requests to OpenURL 1.0 resolvers, there is no 'standard'
|
9
|
+
response format, so parsing the returned value is up to you.
|
10
|
+
|
11
|
+
## USAGE
|
12
|
+
|
13
|
+
require 'openurl'
|
14
|
+
|
15
|
+
# Create your context object
|
16
|
+
context_object = OpenURL::ContextObject.new
|
17
|
+
|
18
|
+
# Add metadata to the Context Object Entities
|
19
|
+
context_object.referent.set_format('journal')
|
20
|
+
context_object.referent.add_identifier('info:doi/10.1016/j.ipm.2005.03.024')
|
21
|
+
context_object.referent.set_metadata('issn', '0306-4573')
|
22
|
+
context_object.referent.set_metadata('aulast', 'Bollen')
|
23
|
+
context_object.referrer.add_identifier('info:sid/google')
|
24
|
+
|
25
|
+
puts context_object.kev
|
26
|
+
|
27
|
+
puts context_object.xml
|
28
|
+
|
29
|
+
# Send the context object to an OpenURL link resolver
|
30
|
+
transport = OpenURL::Transport.new('http://demo.exlibrisgroup.com:9003/lr_3', context_object)
|
31
|
+
transport.get
|
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.
|
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.
|
57
|
+
|
58
|
+
## INSTALLATION
|
59
|
+
|
60
|
+
You should be able to install the gem:
|
61
|
+
|
62
|
+
gem install openurl
|
63
|
+
|
64
|
+
The source lives in git on github:
|
65
|
+
|
66
|
+
http://github.com/openurl/openurl
|
67
|
+
|
68
|
+
## TESTS
|
69
|
+
|
70
|
+
There are some automated tests. Run with `rake test`. They live in `./test`
|
71
|
+
and use Test::Unit.
|
@@ -37,7 +37,7 @@ module OpenURL
|
|
37
37
|
|
38
38
|
attr_reader :admin, :referent, :referringEntity, :requestor, :referrer,
|
39
39
|
:serviceType, :resolver
|
40
|
-
attr_accessor :foreign_keys
|
40
|
+
attr_accessor :foreign_keys, :openurl_ver
|
41
41
|
|
42
42
|
@@defined_entities = {"rft"=>"referent", "rfr"=>"referrer", "rfe"=>"referring-entity", "req"=>"requestor", "svc"=>"service-type", "res"=>"resolver"}
|
43
43
|
|
@@ -51,7 +51,17 @@ module OpenURL
|
|
51
51
|
@serviceType = []
|
52
52
|
@resolver = []
|
53
53
|
@foreign_keys = {}
|
54
|
-
@
|
54
|
+
@openurl_ver = "Z39.88-2004"
|
55
|
+
@admin = {"ctx_ver"=>{"label"=>"version", "value"=>@openurl_ver}, "ctx_tim"=>{"label"=>"timestamp", "value"=>DateTime.now().to_s}, "ctx_id"=>{"label"=>"identifier", "value"=>""}, "ctx_enc"=>{"label"=>"encoding", "value"=>"info:ofi/enc:UTF-8"}}
|
56
|
+
end
|
57
|
+
|
58
|
+
# Any legal OpenURL 1.0 sends url_ver=Z39.88-2004, and usually
|
59
|
+
# ctx_ver=Z39.88-2004 too. However, sometimes we need to send
|
60
|
+
# an illegal OpenURL with a different openurl ver string, to deal
|
61
|
+
# with weird agents, for instance to trick SFX into doing the right thing.
|
62
|
+
def openurl_ver=(ver)
|
63
|
+
@openurl_ver = ver
|
64
|
+
@admin["ctx_ver"]["value"] = ver
|
55
65
|
end
|
56
66
|
|
57
67
|
def deep_copy
|
@@ -99,7 +109,7 @@ module OpenURL
|
|
99
109
|
# true argument if you do not want the ctx_tim key included.
|
100
110
|
|
101
111
|
def kev(no_date=false)
|
102
|
-
kevs = ["url_ver
|
112
|
+
kevs = ["url_ver=#{self.openurl_ver}", "url_ctx_fmt=#{CGI.escape("info:ofi/fmt:kev:mtx:ctx")}"]
|
103
113
|
|
104
114
|
# Loop through the administrative metadata
|
105
115
|
@admin.each_key do |k|
|
@@ -127,7 +137,7 @@ module OpenURL
|
|
127
137
|
# So this function is really deprecated, but here because we have so much
|
128
138
|
# code dependent on it.
|
129
139
|
def to_hash
|
130
|
-
co_hash = {"url_ver"=>
|
140
|
+
co_hash = {"url_ver"=>self.openurl_ver, "url_ctx_fmt"=>"info:ofi/fmt:kev:mtx:ctx"}
|
131
141
|
|
132
142
|
@admin.each_key do |k|
|
133
143
|
co_hash[k]=@admin[k]["value"] if @admin[k]["value"]
|
@@ -367,7 +377,9 @@ module OpenURL
|
|
367
377
|
@referent.add_identifier(val)
|
368
378
|
end
|
369
379
|
elsif key == 'sid'
|
370
|
-
@referrer.set_identifier("info:sid/"+val.to_s)
|
380
|
+
@referrer.set_identifier("info:sid/"+val.to_s)
|
381
|
+
elsif key == 'pid'
|
382
|
+
@referent.set_private_data(val.to_s)
|
371
383
|
else
|
372
384
|
@referent.set_metadata(key, val)
|
373
385
|
end
|
@@ -18,6 +18,7 @@ module OpenURL
|
|
18
18
|
@author_keys = ['aulast','aufirst','auinit','auinit1','auinitm','ausuffix',
|
19
19
|
'au', 'aucorp']
|
20
20
|
end
|
21
|
+
|
21
22
|
def method_missing(metadata, value=nil)
|
22
23
|
meta = metadata.to_s.sub(/=$/,'')
|
23
24
|
raise ArgumentError, "#{meta.to_s} is not a valid #{self.class} metadata field." unless (@author_keys+@metadata_keys).index(meta)
|
@@ -28,10 +29,16 @@ module OpenURL
|
|
28
29
|
end
|
29
30
|
else
|
30
31
|
return self.metadata[meta]
|
31
|
-
end
|
32
|
-
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def respond_to?(message)
|
36
|
+
# make it match method_messing
|
37
|
+
key = message.to_s.sub(/=$/,'')
|
38
|
+
super || (@author_keys+@metadata_keys).index(key)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
35
42
|
def set_metadata(key, val)
|
36
43
|
@metadata[key] = val.to_s
|
37
44
|
if @author_keys.index(key)
|
data/test/context_object_test.rb
CHANGED
@@ -352,6 +352,25 @@ class ContextObjectTest < Test::Unit::TestCase
|
|
352
352
|
assert_match("ctx_enc=#{CGI.escape("info:ofi/enc:UTF-8")}", ctx.kev)
|
353
353
|
end
|
354
354
|
|
355
|
+
def test_kev_01_pid
|
356
|
+
kev = "sid=CSA:eric-set-c&pid=%3CAN%3EED492558%3C%2FAN%3E%26%3CPY%3E2004%3C%2FPY%3E%26%3CAU%3EHsu%2C%20Jeng-yih%20Tim%3C%2FAU%3E&date=2004&genre=proceeding&aulast=Hsu&aufirst=Jeng-yih&auinitm=T&title=Reading%20without%20Teachers%3A%20Literature%20Circles%20in%20an%20EFL%20Classroom"
|
357
|
+
ctx = OpenURL::ContextObject.new_from_kev(kev)
|
358
|
+
assert_equal("<AN>ED492558</AN>&<PY>2004</PY>&<AU>Hsu, Jeng-yih Tim</AU>", ctx.referent.private_data)
|
359
|
+
end
|
360
|
+
|
361
|
+
def test_set_openurl_ver
|
362
|
+
# manually set 'illegal' openurl_ver is respected
|
363
|
+
kev = "sid=CSA:eric-set-c&pid=%3CAN%3EED492558%3C%2FAN%3E%26%3CPY%3E2004%3C%2FPY%3E%26%3CAU%3EHsu%2C%20Jeng-yih%20Tim%3C%2FAU%3E&date=2004&genre=proceeding&aulast=Hsu&aufirst=Jeng-yih&auinitm=T&title=Reading%20without%20Teachers%3A%20Literature%20Circles%20in%20an%20EFL%20Classroom"
|
364
|
+
ctx = OpenURL::ContextObject.new_from_kev(kev)
|
365
|
+
|
366
|
+
ctx.openurl_ver = "" # empty string!
|
367
|
+
|
368
|
+
kev = ctx.kev
|
369
|
+
|
370
|
+
assert_match(/url_ver=&/, kev)
|
371
|
+
assert_match(/ctx_ver=&/, kev)
|
372
|
+
end
|
373
|
+
|
355
374
|
protected
|
356
375
|
|
357
376
|
# Make sure ctx1 and ctx2 don't share the same data objects.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class ScholarlyCommonTest < Test::Unit::TestCase
|
2
|
+
|
3
|
+
def test_respond_to
|
4
|
+
kev = "url_ver=Z39.88-2004&rfr_id=info:sid/library.jhu.edu%3Axerxes+%28+OmniFile+Full+Text+Mega%29&rft.genre=article&rft_val_fmt=info%3Aofi%2Ffmt%3Akev%3Amtx%3Ajournal&rft.issn=00297917&rft.date=2012&rft.tpages=2+pages&rft.jtitle=Occupational+Health&rft.volume=64&rft.issue=5&rft.spage=14&rft.epage=15&rft.atitle=Inhalation+versus+skin+exposure+%3A+have+we+got+the+balance+right%3F+&rft.aulast=Packham&rft.aufirst=Chris+Partner%2C+EnviroDerm+Services"
|
5
|
+
|
6
|
+
openurl = OpenURL::ContextObject.new_from_kev(kev)
|
7
|
+
|
8
|
+
assert openurl.referent.respond_to? :jtitle
|
9
|
+
assert openurl.referent.respond_to? :atitle
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
metadata
CHANGED
@@ -1,36 +1,42 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: openurl
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 2
|
9
|
-
- 0
|
10
|
-
version: 0.2.0
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Jonathan Rochkind
|
14
9
|
- Ross Singer
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
date: 2011-10-10 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: marc
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
23
31
|
description:
|
24
|
-
email:
|
32
|
+
email:
|
25
33
|
- rochkind@jhu.edu
|
26
34
|
- rossfsinger@gmail.com
|
27
35
|
executables: []
|
28
|
-
|
29
36
|
extensions: []
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
files:
|
37
|
+
extra_rdoc_files:
|
38
|
+
- README.md
|
39
|
+
files:
|
34
40
|
- lib/openurl.rb
|
35
41
|
- lib/openurl/context_object_entity.rb
|
36
42
|
- lib/openurl/metadata_formats/book.rb
|
@@ -52,40 +58,30 @@ files:
|
|
52
58
|
- test/test.yml
|
53
59
|
- test/context_object_test.rb
|
54
60
|
- test/encoding_test.rb
|
55
|
-
-
|
56
|
-
|
61
|
+
- test/scholarly_common_test.rb
|
62
|
+
- README.md
|
57
63
|
homepage: https://github.com/openurl/openurl
|
58
64
|
licenses: []
|
59
|
-
|
60
65
|
post_install_message:
|
61
66
|
rdoc_options: []
|
62
|
-
|
63
|
-
require_paths:
|
67
|
+
require_paths:
|
64
68
|
- lib
|
65
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
70
|
none: false
|
67
|
-
requirements:
|
68
|
-
- -
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
|
72
|
-
- 0
|
73
|
-
version: "0"
|
74
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
76
|
none: false
|
76
|
-
requirements:
|
77
|
-
- -
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
|
80
|
-
segments:
|
81
|
-
- 0
|
82
|
-
version: "0"
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
83
81
|
requirements: []
|
84
|
-
|
85
82
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.8.24
|
87
84
|
signing_key:
|
88
85
|
specification_version: 3
|
89
86
|
summary: a Ruby library to create, parse and use NISO Z39.88 OpenURLs
|
90
87
|
test_files: []
|
91
|
-
|
data/README
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
== openurl
|
2
|
-
|
3
|
-
== DESCRIPTION
|
4
|
-
|
5
|
-
openurl is a Ruby library creating, parsing and using NISO Z39.88 OpenURLs over
|
6
|
-
HTTP. <http://openurl.info/registry>
|
7
|
-
|
8
|
-
While openurl can send requests to OpenURL 1.0 resolvers, there is no 'standard'
|
9
|
-
response format, so parsing the returned value is up to you.
|
10
|
-
|
11
|
-
== USAGE
|
12
|
-
|
13
|
-
require 'openurl'
|
14
|
-
|
15
|
-
# Create your context object
|
16
|
-
context_object = OpenURL::ContextObject.new
|
17
|
-
|
18
|
-
# Add metadata to the Context Object Entities
|
19
|
-
context_object.referent.set_format('journal')
|
20
|
-
context_object.referent.add_identifier('info:doi/10.1016/j.ipm.2005.03.024')
|
21
|
-
context_object.referent.set_metadata('issn', '0306-4573')
|
22
|
-
context_object.referent.set_metadata('aulast', 'Bollen')
|
23
|
-
context_object.referrer.add_identifier('info:sid/google')
|
24
|
-
|
25
|
-
puts context_object.kev
|
26
|
-
|
27
|
-
puts context_object.xml
|
28
|
-
|
29
|
-
# Send the context object to an OpenURL link resolver
|
30
|
-
transport = OpenURL::Transport.new('http://demo.exlibrisgroup.com:9003/lr_3', context_object)
|
31
|
-
transport.get
|
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.
|
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.
|
57
|
-
|
58
|
-
== INSTALLATION
|
59
|
-
|
60
|
-
You should be able to install the gem:
|
61
|
-
|
62
|
-
gem install openurl
|
63
|
-
|
64
|
-
The source lives in git on github:
|
65
|
-
|
66
|
-
http://github.com/openurl/openurl
|
67
|
-
|
68
|
-
|