ezid-client 0.6.0 → 0.7.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: 044a6bd05e5a81f2990f4d865515af5f1679e853
4
- data.tar.gz: 7d45fe9bca596a17562812f5a6adf4ef73649665
3
+ metadata.gz: 038635d432049119e82aac80465380671287358b
4
+ data.tar.gz: cfd504d17c9468dffbbb58196f32da8b5f8e1516
5
5
  SHA512:
6
- metadata.gz: 49710a5dd7aed59d88ae6e2463267ee429534d46597096684d16236d8d54c7eeb8bced1f12b7ed196f8e8eba8c7a2e9505244ec8a97d6c6b60019279e8a50ad8
7
- data.tar.gz: 7084e2afebd769a138109732c01e6017eea687f6c1eb3f3ced5f84e18862dad2f4030a7830271d97cbceb88c69d9024d615b9a3b053da4d6f172615e2798149d
6
+ metadata.gz: 8ff054e688b99800e83f6b1f811100aa45b94d45786cf59de54fdba71189235a2c73c86c1e626dcdaf1c6658e928aa1abf2170c842653cfe4be1b33140705068
7
+ data.tar.gz: 77f959afe84560d65cac696df47cd85c1e9b26ca6d2cdfa8289d1fb96acd0f581326790c2c82606251373e0ff7c86b4ed1028b7bdb7e9e050816176181fdb1bc
data/README.md CHANGED
@@ -21,9 +21,11 @@ Or install it yourself as:
21
21
 
22
22
  ## Basic Resource-oriented Usage (CRUD)
23
23
 
24
- See the test suite for more examples.
24
+ *See the test suite for more examples.*
25
25
 
26
- Create (Mint)
26
+ **Create** (Mint/Create)
27
+
28
+ [Mint an identifier on a shoulder](http://ezid.cdlib.org/doc/apidoc.html#operation-mint-identifier)
27
29
 
28
30
  ```ruby
29
31
  >> identifier = Ezid::Identifier.create(shoulder: "ark:/99999/fk4")
@@ -38,7 +40,33 @@ I, [2014-12-04T15:06:03.249793 #86655] INFO -- : EZID GET ark:/99999/fk4rx9d523
38
40
  => "http://ezid.cdlib.org/id/ark:/99999/fk4rx9d523"
39
41
  ```
40
42
 
41
- Retrieve (Get)
43
+ A default shoulder can be configured:
44
+
45
+ ```ruby
46
+ Ezid::Client.configure do |config|
47
+ config.default_shoulder = "ark:/99999/fk4"
48
+ end
49
+ ```
50
+
51
+ Then identifiers can minted on the default shoulder:
52
+
53
+ ```ruby
54
+ >> identifier = Ezid::Identifier.create
55
+ I, [2014-12-09T11:22:34.499860 #32279] INFO -- : EZID MINT ark:/99999/fk4 -- success: ark:/99999/fk43f4wd4v
56
+ I, [2014-12-09T11:22:35.317181 #32279] INFO -- : EZID GET ark:/99999/fk43f4wd4v -- success: ark:/99999/fk43f4wd4v
57
+ => #<Ezid::Identifier id="ark:/99999/fk43f4wd4v" status="public" target="http://ezid.cdlib.org/id/ark:/99999/fk43f4wd4v" created="2014-12-09 16:22:35 UTC">
58
+ ```
59
+
60
+ [Create a specific identifier](http://ezid.cdlib.org/doc/apidoc.html#operation-create-identifier)
61
+
62
+ ```ruby
63
+ >> identifier = Ezid::Identifier.create(id: "ark:/99999/fk4rx9d523/12345")
64
+ I, [2014-12-09T11:21:42.077297 #32279] INFO -- : EZID CREATE ark:/99999/fk4rx9d523/12345 -- success: ark:/99999/fk4rx9d523/12345
65
+ I, [2014-12-09T11:21:42.808534 #32279] INFO -- : EZID GET ark:/99999/fk4rx9d523/12345 -- success: ark:/99999/fk4rx9d523/12345
66
+ => #<Ezid::Identifier id="ark:/99999/fk4rx9d523/12345" status="public" target="http://ezid.cdlib.org/id/ark:/99999/fk4rx9d523/12345" created="2014-12-09 16:21:42 UTC">
67
+ ```
68
+
69
+ **Retrieve** (Get Metadata)
42
70
 
43
71
  ```ruby
44
72
  >> identifier = Ezid::Identifier.find("ark:/99999/fk4rx9d523")
@@ -46,18 +74,24 @@ I, [2014-12-04T15:07:00.648676 #86655] INFO -- : EZID GET ark:/99999/fk4rx9d523
46
74
  => #<Ezid::Identifier id="ark:/99999/fk4rx9d523" status="public" target="http://ezid.cdlib.org/id/ark:/99999/fk4rx9d523" created="2014-12-04 20:06:02 UTC">
47
75
  ```
48
76
 
49
- Update (Modify)
77
+ **Update** (Modify)
50
78
 
51
79
  ```ruby
80
+ >> identifier.target
81
+ => "http://ezid.cdlib.org/id/ark:/99999/fk43f4wd4v"
52
82
  >> identifier.target = "http://example.com"
53
83
  => "http://example.com"
54
84
  >> identifier.save
55
- I, [2014-12-04T15:11:57.263906 #86734] INFO -- : EZID MODIFY ark:/99999/fk4rx9d523 -- success: ark:/99999/fk4rx9d523
56
- I, [2014-12-04T15:11:58.099128 #86734] INFO -- : EZID GET ark:/99999/fk4rx9d523 -- success: ark:/99999/fk4rx9d523
57
- => #<Ezid::Identifier id="ark:/99999/fk4rx9d523" status="public" target="http://example.com" created="2014-12-04 20:06:02 UTC">
85
+ I, [2014-12-09T11:24:26.321801 #32279] INFO -- : EZID MODIFY ark:/99999/fk43f4wd4v -- success: ark:/99999/fk43f4wd4v
86
+ I, [2014-12-09T11:24:27.039288 #32279] INFO -- : EZID GET ark:/99999/fk43f4wd4v -- success: ark:/99999/fk43f4wd4v
87
+ => #<Ezid::Identifier id="ark:/99999/fk43f4wd4v" status="public" target="http://example.com" created="2014-12-09 16:22:35 UTC">
88
+ >> identifier.target
89
+ => "http://example.com"
58
90
  ```
59
91
 
60
- Delete
92
+ **Delete**
93
+
94
+ *Identifier status must be "reserved" to delete.* http://ezid.cdlib.org/doc/apidoc.html#operation-delete-identifier
61
95
 
62
96
  ```ruby
63
97
  >> identifier = Ezid::Identifier.create(shoulder: "ark:/99999/fk4", status: "reserved")
@@ -73,6 +107,33 @@ I, [2014-12-04T15:12:48.853964 #86734] INFO -- : EZID DELETE ark:/99999/fk4n58p
73
107
 
74
108
  Although "EZID imposes no requirements on the presence or form of citation metadata"[*](http://ezid.cdlib.org/doc/apidoc.html#metadata-requirements-mapping), `ezid-client` is intended to support the EZID [reserved metadata elements](http://ezid.cdlib.org/doc/apidoc.html#internal-metadata) and [metadata profiles](http://ezid.cdlib.org/doc/apidoc.html#metadata-profiles). While it is possible to use the client to send and receive any metadata, the object methods are geared towards the defined elements. Therefore it was seen fit, for example, to map the method `Ezid::Identifier#status` to the "_status" element. Likewise, all the reserved elements, except for "_crossref", have readers and -- for user-writable elements -- writers without the leading underscores. Since there are both "_crossref" and "crossref" elements, their accessors match the elements names. Similarly, accessors for metadata profile elements use underscores in place of dots -- for example, `Ezid::Identifer#dc_title` and `#dc_title=` for the "dc.title" element.
75
109
 
110
+ **Setting default metadata values**
111
+
112
+ Default metadata values can be set:
113
+
114
+ ```ruby
115
+ Ezid::Client.configure do |config|
116
+ # set multiple defaults with a hash
117
+ config.identifier.defaults = {status: "reserved", profile: "dc"}
118
+ # or set individual elements
119
+ config.identifier.defaults[:status] = "reserved"
120
+ config.identifier.defaults[:profile] = "dc"
121
+ end
122
+ ```
123
+
124
+ Then new identifiers will receive the defaults:
125
+
126
+ ```ruby
127
+ >> identifier = Ezid::Identifier.create(shoulder: "ark:/99999/fk4")
128
+ I, [2014-12-09T11:38:37.335136 #32279] INFO -- : EZID MINT ark:/99999/fk4 -- success: ark:/99999/fk4zs2w500
129
+ I, [2014-12-09T11:38:38.153546 #32279] INFO -- : EZID GET ark:/99999/fk4zs2w500 -- success: ark:/99999/fk4zs2w500
130
+ => #<Ezid::Identifier id="ark:/99999/fk4zs2w500" status="reserved" target="http://ezid.cdlib.org/id/ark:/99999/fk4zs2w500" created="2014-12-09 16:38:38 UTC">
131
+ >> identifier.profile
132
+ => "dc"
133
+ >> identifier.status
134
+ => "reserved"
135
+ ```
136
+
76
137
  ## Authentication
77
138
 
78
139
  Credentials can be provided in any -- or a combination -- of these ways:
@@ -94,7 +155,29 @@ end
94
155
  client = Ezid::Client.new(user: "eziduser", password: "ezidpass")
95
156
  ```
96
157
 
97
- ## Running the tests
158
+ ## Test Helper
159
+
160
+ If you have tests that (directly or indirectly) use `ezid-client` you may want to require the test helper module:
161
+
162
+ ```ruby
163
+ require "ezid/test_helper"
164
+ ```
165
+
166
+ The module provides constants:
167
+
168
+ - `TEST_ARK_SHOULDER` => "ark:/99999/fk4"
169
+ - `TEST_DOI_SHOULDER` => "doi:10.5072/FK2"
170
+ - `TEST_USER` => "apitest"
171
+
172
+ The test user password is not provided - contact EZID and configure as above - or use your own EZID credentials, since all accounts can mint/create on the test shoulders.
173
+
174
+ A convenience method `ezid_test_mode!` is provided to configure the client to:
175
+
176
+ - authenticate as `TEST_USER`
177
+ - use `TEST_ARK_SHOULDER` as the default shoulder
178
+ - log to the null device (instead of default STDERR)
179
+
180
+ ## Running the ezid-client tests
98
181
 
99
182
  See http://ezid.cdlib.org/doc/apidoc.html#testing-the-api.
100
183
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.0
@@ -0,0 +1,24 @@
1
+ require "ezid-client"
2
+
3
+ module Ezid
4
+ module TestHelper
5
+
6
+ TEST_ARK_SHOULDER = "ark:/99999/fk4"
7
+ TEST_DOI_SHOULDER = "doi:10.5072/FK2"
8
+ TEST_USER = "apitest"
9
+
10
+ def ezid_test_mode!
11
+ Ezid::Client.configure do |config|
12
+ config.user = TEST_USER
13
+ # Contact EZID for password
14
+ # config.password = "********"
15
+ config.logger = Logger.new(File::NULL)
16
+ config.default_shoulder = TEST_ARK_SHOULDER
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+
23
+ include Ezid::TestHelper
24
+
@@ -3,7 +3,7 @@ module Ezid
3
3
 
4
4
  shared_examples "an EZID client" do |client|
5
5
  it "should mint and modify" do
6
- minted = client.mint_identifier(ARK_SHOULDER, "_status: reserved")
6
+ minted = client.mint_identifier(TEST_ARK_SHOULDER, "_status: reserved")
7
7
  expect(minted).to be_success
8
8
  @id = minted.id
9
9
  modified = client.modify_identifier(@id, "dc.title" => "Test")
@@ -46,7 +46,7 @@ module Ezid
46
46
  describe "without a session" do
47
47
  it "should send the user name and password" do
48
48
  expect_any_instance_of(Net::HTTP::Post).to receive(:basic_auth).with(subject.user, subject.password).and_call_original
49
- subject.mint_identifier(ARK_SHOULDER)
49
+ subject.mint_identifier(TEST_ARK_SHOULDER)
50
50
  end
51
51
  end
52
52
  end
@@ -6,14 +6,14 @@ module Ezid
6
6
  describe "CRUD operations" do
7
7
  describe "create" do
8
8
  describe "with a shoulder" do
9
- subject { described_class.create(shoulder: ARK_SHOULDER) }
9
+ subject { described_class.create(shoulder: TEST_ARK_SHOULDER) }
10
10
  it "should mint an identifier" do
11
11
  expect(subject).to be_a(described_class)
12
- expect(subject.id).to match(/#{ARK_SHOULDER}/)
12
+ expect(subject.id).to match(/#{TEST_ARK_SHOULDER}/)
13
13
  end
14
14
  end
15
15
  describe "with an id" do
16
- let(:minted) { described_class.create(shoulder: ARK_SHOULDER) }
16
+ let(:minted) { described_class.create(shoulder: TEST_ARK_SHOULDER) }
17
17
  subject { described_class.create(id: "#{minted}/123") }
18
18
  it "should create the identifier" do
19
19
  expect(subject).to be_a(described_class)
@@ -23,7 +23,7 @@ module Ezid
23
23
  end
24
24
 
25
25
  describe "retrieve" do
26
- let(:minted) { described_class.create(shoulder: ARK_SHOULDER, target: "http://example.com") }
26
+ let(:minted) { described_class.create(shoulder: TEST_ARK_SHOULDER, target: "http://example.com") }
27
27
  subject { described_class.find(minted.id) }
28
28
  it "should instantiate the identifier" do
29
29
  expect(subject).to be_a(described_class)
@@ -33,7 +33,7 @@ module Ezid
33
33
  end
34
34
 
35
35
  describe "update" do
36
- subject { described_class.create(shoulder: ARK_SHOULDER, target: "http://google.com") }
36
+ subject { described_class.create(shoulder: TEST_ARK_SHOULDER, target: "http://google.com") }
37
37
  before do
38
38
  subject.target = "http://example.com"
39
39
  subject.save
@@ -44,7 +44,7 @@ module Ezid
44
44
  end
45
45
 
46
46
  describe "delete" do
47
- subject { described_class.create(shoulder: ARK_SHOULDER, status: "reserved") }
47
+ subject { described_class.create(shoulder: TEST_ARK_SHOULDER, status: "reserved") }
48
48
  before { subject.delete }
49
49
  it "should delete the identifier" do
50
50
  expect { described_class.find(subject.id) }.to raise_error
data/spec/spec_helper.rb CHANGED
@@ -18,17 +18,8 @@
18
18
  require 'coveralls'
19
19
  Coveralls.wear!
20
20
 
21
- require "ezid-client"
22
-
23
- Ezid::Client.configure do |config|
24
- config.user = "apitest"
25
- # Contact EZID for password
26
- # config.password = "********"
27
- config.logger = Logger.new(File::NULL)
28
- end
29
-
30
- ARK_SHOULDER = "ark:/99999/fk4"
31
- DOI_SHOULDER = "doi:10.5072/FK2"
21
+ require "ezid/test_helper"
22
+ ezid_test_mode!
32
23
 
33
24
  RSpec.configure do |config|
34
25
 
@@ -25,8 +25,8 @@ module Ezid
25
25
  describe "#mint_identifier" do
26
26
  describe "which is an ARK" do
27
27
  let(:stub_response) { Response.new(double(body: "success: ark:/99999/fk4fn19h88")) }
28
- before { allow(Request).to receive(:execute).with(:Post, "/shoulder/#{ARK_SHOULDER}") { stub_response } }
29
- subject { described_class.new.mint_identifier(ARK_SHOULDER) }
28
+ before { allow(Request).to receive(:execute).with(:Post, "/shoulder/#{TEST_ARK_SHOULDER}") { stub_response } }
29
+ subject { described_class.new.mint_identifier(TEST_ARK_SHOULDER) }
30
30
  it "should be a succes" do
31
31
  expect(subject).to be_success
32
32
  expect(subject.id).to eq("ark:/99999/fk4fn19h88")
@@ -44,8 +44,8 @@ datacite.publicationyear: 2014
44
44
  datacite.resourcetype: Other
45
45
  EOS
46
46
  end
47
- before { allow(Request).to receive(:execute).with(:Post, "/shoulder/#{DOI_SHOULDER}") { stub_response } }
48
- subject { described_class.new.mint_identifier(DOI_SHOULDER, metadata) }
47
+ before { allow(Request).to receive(:execute).with(:Post, "/shoulder/#{TEST_DOI_SHOULDER}") { stub_response } }
48
+ subject { described_class.new.mint_identifier(TEST_DOI_SHOULDER, metadata) }
49
49
  it "should be a sucess" do
50
50
  expect(subject).to be_success
51
51
  expect(subject.id).to eq("doi:10.5072/FK2TEST")
@@ -57,14 +57,15 @@ EOS
57
57
  context "and the :default_shoulder config option is set" do
58
58
  subject { described_class.new.mint_identifier }
59
59
  before do
60
- allow(Request).to receive(:execute).with(:Post, "/shoulder/#{ARK_SHOULDER}") { stub_response }
61
- allow(Client.config).to receive(:default_shoulder) { ARK_SHOULDER }
60
+ allow(Request).to receive(:execute).with(:Post, "/shoulder/#{TEST_ARK_SHOULDER}") { stub_response }
61
+ allow(Client.config).to receive(:default_shoulder) { TEST_ARK_SHOULDER }
62
62
  end
63
63
  it "should use the default shoulder" do
64
64
  expect(subject).to be_success
65
65
  end
66
66
  end
67
67
  context "and the :default_shoulder config option is not set" do
68
+ before { allow(Client.config).to receive(:default_shoulder) { nil } }
68
69
  it "should raise an exception" do
69
70
  expect { described_class.new.mint_identifier }.to raise_error
70
71
  end
@@ -2,7 +2,7 @@ module Ezid
2
2
  RSpec.describe Identifier do
3
3
 
4
4
  describe ".create" do
5
- let(:attrs) { {shoulder: ARK_SHOULDER, profile: "dc", target: "http://example.com"} }
5
+ let(:attrs) { {shoulder: TEST_ARK_SHOULDER, profile: "dc", target: "http://example.com"} }
6
6
  it "should instantiate a new Identifier and save it" do
7
7
  expect(described_class).to receive(:new).with(attrs).and_call_original
8
8
  expect_any_instance_of(described_class).to receive(:save) { double }
@@ -59,7 +59,7 @@ module Ezid
59
59
  expect(subject.status).to eq("reserved")
60
60
  end
61
61
  context "when explicit arguments override the defaults" do
62
- subject { described_class.new(shoulder: ARK_SHOULDER, status: "public") }
62
+ subject { described_class.new(shoulder: TEST_ARK_SHOULDER, status: "public") }
63
63
  it "should override the defaults" do
64
64
  expect(subject.profile).to eq("dc")
65
65
  expect(subject.status).to eq("public")
@@ -150,13 +150,14 @@ module Ezid
150
150
  end
151
151
  context "and `id' is not present" do
152
152
  context "and `shoulder' is present" do
153
- before { allow(subject).to receive(:shoulder) { ARK_SHOULDER } }
153
+ before { allow(subject).to receive(:shoulder) { TEST_ARK_SHOULDER } }
154
154
  it "should mint the identifier" do
155
- expect(subject.client).to receive(:mint_identifier).with(ARK_SHOULDER, {}) { double(id: "id") }
155
+ expect(subject.client).to receive(:mint_identifier).with(TEST_ARK_SHOULDER, {}) { double(id: "id") }
156
156
  subject.save
157
157
  end
158
158
  end
159
159
  context "and `shoulder' is not present" do
160
+ before { allow(Client.config).to receive(:default_shoulder) { nil } }
160
161
  it "should raise an exception" do
161
162
  expect { subject.save }.to raise_error
162
163
  end
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.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chandek-Stark
@@ -78,6 +78,7 @@ files:
78
78
  - lib/ezid/response.rb
79
79
  - lib/ezid/session.rb
80
80
  - lib/ezid/status.rb
81
+ - lib/ezid/test_helper.rb
81
82
  - spec/integration/client_spec.rb
82
83
  - spec/integration/identifier_spec.rb
83
84
  - spec/spec_helper.rb