ezid-client 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7525ff60fc6c37fafa16197480ff8612fb0d7cd0
4
- data.tar.gz: 2d7a986b67c23cf09722b4ccfb27d70913a2ef5e
3
+ metadata.gz: 40cb3555f7bca7cbb5a29841afc004e9d00ebeaa
4
+ data.tar.gz: 07da9b35895929c94079f2ef82a24e511bb6f89a
5
5
  SHA512:
6
- metadata.gz: a681531c12267fd6b849d59ce37a533cd2e9e00c8f8f43deb54e646fff4772f881ba7e84e1d118545bcec90e0531f87647bf35c51c0c6b1d06a978b39ef0aa66
7
- data.tar.gz: 87b9bc72d63e31e934ec4849b79f2307ac73ad34cabbcf21faf4a10c69f3f23e0e65ec58e8e080cfb37019f270fdd0eeb6404c636b48431944ee18535c8a7288
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.2.0
1
+ 0.3.0
@@ -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
- lines = escape_keys.zip(escape_values).map { |e| e.join(ANVL_SEPARATOR) }
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
- # method_missing is used to provide internal element readers and writers
90
- def method_missing(name, *args)
91
- if INTERNAL_ELEMENTS.include?(element = "_#{name}")
92
- reader(element)
93
- elsif name.to_s.end_with?("=") && INTERNAL_READWRITE_ELEMENTS.include?(element = "_#{name}".sub("=", ""))
94
- writer(element, args.first)
95
- else
96
- super
97
- end
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
- value = self[element]
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
- describe "method missing" do
5
- context "for an internal element name w/o leading underscore" do
6
- it "should call the reader method" do
7
- expect(subject).to receive(:reader).with("_status")
8
- subject.status
9
- end
10
- end
11
- context "for an internal writable element name + '=' and w/o leading underscore" do
12
- it "should call the writer method" do
13
- expect(subject).to receive(:writer).with("_status", "public")
14
- subject.status = "public"
15
- end
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
- context "for an internal readonly element name + '=' and w/o leading underscore" do
18
- it "should not call the writer method" do
19
- expect { subject.created = "1416507086" }.to raise_error
20
- end
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
- describe "internal element reader" do
25
- context "for a datetime element" do
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
- context "for a non-datetime element" do
32
- before { subject["_status"] = "public" }
33
- it "should return the value" do
34
- expect(subject.status).to eq("public")
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
- describe "internal element writer" do
40
- before { subject["_status"] = "reserved" }
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(metadata.to_anvl).to eq("\
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
- context "of element names" do
68
- it "should escape a colon"
69
- it "should escape a line feed"
70
- it "should escape a carriage return"
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
- context "of element values" do
74
- it "should escape a line feed"
75
- it "should escape a carriage return"
76
- it "should escape a percent sign"
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
- subject { described_class.new(data) }
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
- it "should stringify the keys"
106
- end
107
- context "of an Ezid::Metadata instance" do
108
- it "should return the elements hash"
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezid-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dchandekstark