ezid-client 0.2.0 → 0.3.0
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/README.md +0 -4
- data/VERSION +1 -1
- data/lib/ezid/metadata.rb +36 -19
- data/spec/lib/ezid/metadata_spec.rb +75 -59
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40cb3555f7bca7cbb5a29841afc004e9d00ebeaa
|
4
|
+
data.tar.gz: 07da9b35895929c94079f2ef82a24e511bb6f89a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eb587dffe69c56bd119fcfbebcd06e58d3bc6cf4f7a5a5dcced275411b675e70ebebb0dcf1c19e21e4369b9673235d439860893be455c6e8d1b85f5de11284a
|
7
|
+
data.tar.gz: c29ec20b8fd8dae31c8e4e60afe0210c460b9817e6367c2284a9fe2045d43638705891dce0a148ad8ce8fc14e00ea70561ba878a963614d1c351e850cfaa0a82
|
data/README.md
CHANGED
@@ -85,10 +85,6 @@ I, [2014-11-20T13:18:47.213566 #86059] INFO -- : success: authentication creden
|
|
85
85
|
=> #<Ezid::Client:0x007faa5a712350 , @user="apitest", @password="********">
|
86
86
|
```
|
87
87
|
|
88
|
-
## Resource-oriented Usage
|
89
|
-
|
90
|
-
Experimental -- see `Ezid::Identifier`.
|
91
|
-
|
92
88
|
## Metadata handling
|
93
89
|
|
94
90
|
See `Ezid::Metadata`.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/ezid/metadata.rb
CHANGED
@@ -37,10 +37,6 @@ module Ezid
|
|
37
37
|
|
38
38
|
# EZID internal metadata elements
|
39
39
|
INTERNAL_ELEMENTS = (INTERNAL_READONLY_ELEMENTS + INTERNAL_READWRITE_ELEMENTS).freeze
|
40
|
-
|
41
|
-
# Internal metadata element which are datetime values
|
42
|
-
# @note EZID outputs datetime info as epoch seconds.
|
43
|
-
DATETIME_ELEMENTS = %w( _created _updated ).freeze
|
44
40
|
|
45
41
|
# EZID metadata field/value separator
|
46
42
|
ANVL_SEPARATOR = ": "
|
@@ -70,8 +66,7 @@ module Ezid
|
|
70
66
|
# @see http://ezid.cdlib.org/doc/apidoc.html#request-response-bodies
|
71
67
|
# @return [String] the ANVL output
|
72
68
|
def to_anvl
|
73
|
-
|
74
|
-
lines.join("\n").force_encoding(Encoding::UTF_8)
|
69
|
+
escape_keys.zip(escape_values).map { |e| e.join(ANVL_SEPARATOR) }.join("\n")
|
75
70
|
end
|
76
71
|
|
77
72
|
def to_s
|
@@ -86,23 +81,45 @@ module Ezid
|
|
86
81
|
self
|
87
82
|
end
|
88
83
|
|
89
|
-
#
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
84
|
+
# Identifier status
|
85
|
+
# @return [String] the status
|
86
|
+
def status
|
87
|
+
reader("_status")
|
88
|
+
end
|
89
|
+
|
90
|
+
# The time the identifier was created
|
91
|
+
# @return [Time] the time
|
92
|
+
def created
|
93
|
+
value = reader("_created")
|
94
|
+
return Time.at(value.to_i) if value
|
95
|
+
value
|
96
|
+
end
|
97
|
+
|
98
|
+
# The time the identifier was last updated
|
99
|
+
# @return [Time] the time
|
100
|
+
def updated
|
101
|
+
value = reader("_updated")
|
102
|
+
return Time.at(value.to_i) if value
|
103
|
+
value
|
104
|
+
end
|
105
|
+
|
106
|
+
# The identifier's preferred metadata profile
|
107
|
+
# @see http://ezid.cdlib.org/doc/apidoc.html#metadata-profiles
|
108
|
+
# @return [String] the profile
|
109
|
+
def profile
|
110
|
+
reader("_profile")
|
111
|
+
end
|
112
|
+
|
113
|
+
# The identifier's target URL
|
114
|
+
# @return [String] the URL
|
115
|
+
def target
|
116
|
+
reader("_target")
|
98
117
|
end
|
99
118
|
|
100
119
|
private
|
101
120
|
|
102
121
|
def reader(element)
|
103
|
-
|
104
|
-
return Time.at(value.to_i) if DATETIME_ELEMENTS.include?(element) && !value.nil?
|
105
|
-
value
|
122
|
+
self[element]
|
106
123
|
end
|
107
124
|
|
108
125
|
def writer(element, value)
|
@@ -136,7 +153,7 @@ module Ezid
|
|
136
153
|
# @param value [String] the value to escape
|
137
154
|
# @return [String] the escaped value
|
138
155
|
def escape(re, value)
|
139
|
-
value.gsub(re) { |m| URI.encode_www_form_component(m) }
|
156
|
+
value.gsub(re) { |m| URI.encode_www_form_component(m, Encoding::UTF_8) }
|
140
157
|
end
|
141
158
|
|
142
159
|
# Unescape value from EZID host (or other source)
|
@@ -1,59 +1,46 @@
|
|
1
1
|
module Ezid
|
2
2
|
RSpec.describe Metadata do
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
3
|
+
|
4
|
+
let(:elements) do
|
5
|
+
{ "_updated" => "1416507086",
|
6
|
+
"_target" => "http://ezid.cdlib.org/id/ark:/99999/fk4fn19h87",
|
7
|
+
"_profile" => "erc",
|
8
|
+
"_ownergroup" => "apitest",
|
9
|
+
"_owner" => "apitest",
|
10
|
+
"_export" => "yes",
|
11
|
+
"_created" => "1416507086",
|
12
|
+
"_status" => "public" }
|
13
|
+
end
|
14
|
+
before { subject.instance_variable_set(:@elements, elements) }
|
15
|
+
describe "#status" do
|
16
|
+
it "should return the status" do
|
17
|
+
expect(subject.status).to eq("public")
|
16
18
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
end
|
20
|
+
describe "#target" do
|
21
|
+
it "should return the target URL" do
|
22
|
+
expect(subject.target).to eq("http://ezid.cdlib.org/id/ark:/99999/fk4fn19h87")
|
21
23
|
end
|
22
24
|
end
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
before { subject["_created"] = "1416507086" }
|
27
|
-
it "should return a Time" do
|
28
|
-
expect(subject.created).to be_a(Time)
|
29
|
-
end
|
25
|
+
describe "#profile" do
|
26
|
+
it "should return the profile" do
|
27
|
+
expect(subject.profile).to eq("erc")
|
30
28
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
end
|
29
|
+
end
|
30
|
+
describe "#created" do
|
31
|
+
it "should return the creation time" do
|
32
|
+
expect(subject.created).to be_a(Time)
|
36
33
|
end
|
37
34
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
it "should set the element" do
|
42
|
-
expect { subject.status = "public" }.to change { subject["_status"] }.from("reserved").to("public")
|
35
|
+
describe "#updated" do
|
36
|
+
it "should return the last update time" do
|
37
|
+
expect(subject.updated).to be_a(Time)
|
43
38
|
end
|
44
39
|
end
|
45
40
|
|
46
41
|
describe "ANVL output" do
|
47
|
-
let(:metadata) { described_class.new(_updated: "1416507086",
|
48
|
-
_target: "http://ezid.cdlib.org/id/ark:/99999/fk4fn19h87",
|
49
|
-
_profile: "erc",
|
50
|
-
_ownergroup: "apitest",
|
51
|
-
_owner: "apitest",
|
52
|
-
_export: "yes",
|
53
|
-
_created: "1416507086",
|
54
|
-
_status: "public") }
|
55
42
|
it "should output the proper format" do
|
56
|
-
expect(
|
43
|
+
expect(subject.to_anvl).to eq("\
|
57
44
|
_updated: 1416507086
|
58
45
|
_target: http://ezid.cdlib.org/id/ark:/99999/fk4fn19h87
|
59
46
|
_profile: erc
|
@@ -63,24 +50,36 @@ _export: yes
|
|
63
50
|
_created: 1416507086
|
64
51
|
_status: public")
|
65
52
|
end
|
53
|
+
describe "encoding" do
|
54
|
+
before do
|
55
|
+
subject.each_key { |k| subject[k] = subject[k].force_encoding("US_ASCII") }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
it "should be encoded in UTF-8" do
|
59
|
+
expect(subject.to_anvl.encoding).to eq(Encoding::UTF_8)
|
60
|
+
end
|
66
61
|
describe "escaping" do
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
it "should escape a percent sign"
|
62
|
+
before do
|
63
|
+
subject["_target"] = "http://example.com/path%20with%20spaces"
|
64
|
+
subject["dc.title"] = "A really long title\nneeds a line feed"
|
65
|
+
subject["dc.creator"] = "David Chandek-Stark\r\nJim Coble"
|
72
66
|
end
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
67
|
+
it "should escape a line feed" do
|
68
|
+
expect(subject.to_anvl).to match(/dc.title: A really long title%0Aneeds a line feed/)
|
69
|
+
end
|
70
|
+
it "should escape a carriage return" do
|
71
|
+
expect(subject.to_anvl).to match(/dc.creator: David Chandek-Stark%0D%0AJim Coble/)
|
72
|
+
end
|
73
|
+
it "should escape a percent sign" do
|
74
|
+
expect(subject.to_anvl).to match(/_target: http:\/\/example.com\/path%2520with%2520spaces/)
|
77
75
|
end
|
78
76
|
end
|
79
77
|
end
|
80
78
|
|
81
79
|
describe "coercion" do
|
80
|
+
subject { described_class.new(data) }
|
82
81
|
context "of a string" do
|
83
|
-
let(:data)
|
82
|
+
let(:data) do <<-EOS
|
84
83
|
_updated: 1416507086
|
85
84
|
_target: http://ezid.cdlib.org/id/ark:/99999/fk4fn19h87
|
86
85
|
_profile: erc
|
@@ -88,8 +87,9 @@ _ownergroup: apitest
|
|
88
87
|
_owner: apitest
|
89
88
|
_export: yes
|
90
89
|
_created: 1416507086
|
91
|
-
_status: public
|
92
|
-
|
90
|
+
_status: public
|
91
|
+
EOS
|
92
|
+
end
|
93
93
|
it "should coerce the data into a hash" do
|
94
94
|
expect(subject.elements).to eq({"_updated" => "1416507086",
|
95
95
|
"_target" => "http://ezid.cdlib.org/id/ark:/99999/fk4fn19h87",
|
@@ -102,10 +102,26 @@ _status: public" }
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
context "of a hash" do
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
105
|
+
let(:data) do
|
106
|
+
{ _updated: "1416507086",
|
107
|
+
_target: "http://ezid.cdlib.org/id/ark:/99999/fk4fn19h87",
|
108
|
+
_profile: "erc",
|
109
|
+
_ownergroup: "apitest",
|
110
|
+
_owner: "apitest",
|
111
|
+
_export: "yes",
|
112
|
+
_created: "1416507086",
|
113
|
+
_status: "public" }
|
114
|
+
end
|
115
|
+
it "should stringify the keys" do
|
116
|
+
expect(subject.elements).to eq({"_updated" => "1416507086",
|
117
|
+
"_target" => "http://ezid.cdlib.org/id/ark:/99999/fk4fn19h87",
|
118
|
+
"_profile" => "erc",
|
119
|
+
"_ownergroup" => "apitest",
|
120
|
+
"_owner" => "apitest",
|
121
|
+
"_export" => "yes",
|
122
|
+
"_created" => "1416507086",
|
123
|
+
"_status" => "public"})
|
124
|
+
end
|
109
125
|
end
|
110
126
|
end
|
111
127
|
|