ezid-client 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -3
- data/VERSION +1 -1
- data/lib/ezid/client.rb +25 -14
- data/lib/ezid/configuration.rb +13 -1
- data/lib/ezid/identifier.rb +2 -2
- data/lib/ezid/metadata.rb +6 -6
- data/lib/ezid/request.rb +7 -5
- data/lib/ezid/session.rb +1 -1
- data/lib/ezid/status.rb +1 -1
- data/lib/ezid/test_helper.rb +4 -2
- data/spec/integration/client_spec.rb +2 -2
- data/spec/unit/client_spec.rb +54 -45
- data/spec/unit/identifier_spec.rb +5 -5
- data/spec/unit/metadata_spec.rb +7 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5057a59c4d4de21482b25d1bf18a64eec306a3e
|
4
|
+
data.tar.gz: ac126799f0f435288245d1101880e58a1f9887cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 825251d97f61359cee02e0f7dec0af2f9d784af1adf28ef4fefe3c1748211f98f8243810e422d6a353810f5a0e89a578465fa5e653c0fc97e09be72bd8ed6e2a
|
7
|
+
data.tar.gz: 564658a689c0b75a4ffb38f2c8dc0d69649a967845a7a85cb6f579658f442065548109e9b89a2ecdc2239c4cfd51ec8133f807b0d543d461bdbb6f6336a98af4
|
data/README.md
CHANGED
@@ -89,7 +89,7 @@ I, [2014-12-09T11:24:27.039288 #32279] INFO -- : EZID GET ark:/99999/fk43f4wd4v
|
|
89
89
|
=> "http://example.com"
|
90
90
|
```
|
91
91
|
|
92
|
-
**Delete**
|
92
|
+
**Delete**
|
93
93
|
|
94
94
|
*Identifier status must be "reserved" to delete.* http://ezid.cdlib.org/doc/apidoc.html#operation-delete-identifier
|
95
95
|
|
@@ -105,7 +105,7 @@ I, [2014-12-04T15:12:48.853964 #86734] INFO -- : EZID DELETE ark:/99999/fk4n58p
|
|
105
105
|
|
106
106
|
## Metadata handling
|
107
107
|
|
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
|
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.
|
109
109
|
|
110
110
|
**Setting default metadata values**
|
111
111
|
|
@@ -149,12 +149,33 @@ Ezid::Client.configure do |config|
|
|
149
149
|
end
|
150
150
|
```
|
151
151
|
|
152
|
-
- At client initialization (only if
|
152
|
+
- At client initialization (only if explicitly instantiating `Ezid::Client`):
|
153
153
|
|
154
154
|
```ruby
|
155
155
|
client = Ezid::Client.new(user: "eziduser", password: "ezidpass")
|
156
156
|
```
|
157
157
|
|
158
|
+
## Alternate Host and Disabling SSL
|
159
|
+
|
160
|
+
By default Ezid::Client connects over SSL to the EZID host at [ezid.cdlib.org](http://ezid.cdlib.org), but the host and SSL settings may be overridden:
|
161
|
+
|
162
|
+
- By setting the `EZID_HOST` environment variable; `EZID_USE_SSL` may be set to the string "false" to disable SSL for all requests.
|
163
|
+
|
164
|
+
- Client configuration:
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
Ezid::Client.configure do |config|
|
168
|
+
config.host = "localhost"
|
169
|
+
config.use_ssl = false
|
170
|
+
end
|
171
|
+
```
|
172
|
+
|
173
|
+
- At client initialization (only if explicitly instantiating `Ezid::Client`):
|
174
|
+
|
175
|
+
```ruby
|
176
|
+
client = Ezid::Client.new(host: "localhost", use_ssl: false)
|
177
|
+
```
|
178
|
+
|
158
179
|
## Test Helper
|
159
180
|
|
160
181
|
If you have tests that (directly or indirectly) use `ezid-client` you may want to require the test helper module:
|
@@ -168,12 +189,14 @@ The module provides constants:
|
|
168
189
|
- `TEST_ARK_SHOULDER` => "ark:/99999/fk4"
|
169
190
|
- `TEST_DOI_SHOULDER` => "doi:10.5072/FK2"
|
170
191
|
- `TEST_USER` => "apitest"
|
192
|
+
- `TEST_HOST` => "ezid.cdlib.org"
|
171
193
|
|
172
194
|
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
195
|
|
174
196
|
A convenience method `ezid_test_mode!` is provided to configure the client to:
|
175
197
|
|
176
198
|
- authenticate as `TEST_USER`
|
199
|
+
- use `TEST_HOST` as the host
|
177
200
|
- use `TEST_ARK_SHOULDER` as the default shoulder
|
178
201
|
- log to the null device (instead of default STDERR)
|
179
202
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.8.0
|
data/lib/ezid/client.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "uri"
|
2
|
+
|
1
3
|
require_relative "configuration"
|
2
4
|
require_relative "request"
|
3
5
|
require_relative "response"
|
@@ -20,20 +22,24 @@ module Ezid
|
|
20
22
|
def config
|
21
23
|
@config ||= Configuration.new
|
22
24
|
end
|
23
|
-
|
25
|
+
|
24
26
|
# Yields the configuration to a block
|
25
27
|
# @yieldparam [Ezid::Configuration] the configuration
|
26
28
|
def configure
|
27
29
|
yield config
|
28
30
|
end
|
29
|
-
end
|
31
|
+
end
|
30
32
|
|
31
|
-
attr_reader :session, :user, :password
|
33
|
+
attr_reader :session, :user, :password, :host, :use_ssl
|
32
34
|
|
33
35
|
def initialize(opts = {})
|
34
36
|
@session = Session.new
|
37
|
+
@host = opts[:host] || config.host
|
38
|
+
@use_ssl = opts.fetch(:use_ssl, config.use_ssl)
|
35
39
|
@user = opts[:user] || config.user
|
40
|
+
raise Error, "User name is required." unless user
|
36
41
|
@password = opts[:password] || config.password
|
42
|
+
raise Error, "Password is required." unless password
|
37
43
|
if block_given?
|
38
44
|
login
|
39
45
|
yield self
|
@@ -42,7 +48,7 @@ module Ezid
|
|
42
48
|
end
|
43
49
|
|
44
50
|
def inspect
|
45
|
-
"#<#{self.class.name} user=\"#{user}\" session=#{logged_in? ? 'OPEN' : 'CLOSED'}>"
|
51
|
+
"#<#{self.class.name} host=\"#{host}\" user=\"#{user}\" session=#{logged_in? ? 'OPEN' : 'CLOSED'}>"
|
46
52
|
end
|
47
53
|
|
48
54
|
# The client configuration
|
@@ -64,7 +70,7 @@ module Ezid
|
|
64
70
|
if logged_in?
|
65
71
|
logger.info("Already logged in, skipping login request.")
|
66
72
|
else
|
67
|
-
response = Request.execute(:Get, "/login") do |request|
|
73
|
+
response = Request.execute(:Get, build_uri("/login")) do |request|
|
68
74
|
add_authentication(request)
|
69
75
|
end
|
70
76
|
handle_response(response, "LOGIN")
|
@@ -77,7 +83,7 @@ module Ezid
|
|
77
83
|
# @return [Ezid::Client] the client
|
78
84
|
def logout
|
79
85
|
if logged_in?
|
80
|
-
response = Request.execute(:Get, "/logout")
|
86
|
+
response = Request.execute(:Get, build_uri("/logout"))
|
81
87
|
handle_response(response, "LOGOUT")
|
82
88
|
session.close
|
83
89
|
else
|
@@ -96,7 +102,7 @@ module Ezid
|
|
96
102
|
# @raise [Ezid::Error]
|
97
103
|
# @return [Ezid::Response] the response
|
98
104
|
def create_identifier(identifier, metadata=nil)
|
99
|
-
response = Request.execute(:Put, "/id/#{identifier}") do |request|
|
105
|
+
response = Request.execute(:Put, build_uri("/id/#{identifier}")) do |request|
|
100
106
|
add_authentication(request)
|
101
107
|
add_metadata(request, metadata)
|
102
108
|
end
|
@@ -110,19 +116,19 @@ module Ezid
|
|
110
116
|
def mint_identifier(shoulder=nil, metadata=nil)
|
111
117
|
shoulder ||= config.default_shoulder
|
112
118
|
raise Error, "Shoulder missing -- cannot mint identifier." unless shoulder
|
113
|
-
response = Request.execute(:Post, "/shoulder/#{shoulder}") do |request|
|
119
|
+
response = Request.execute(:Post, build_uri("/shoulder/#{shoulder}")) do |request|
|
114
120
|
add_authentication(request)
|
115
121
|
add_metadata(request, metadata)
|
116
122
|
end
|
117
123
|
handle_response(response, "MINT #{shoulder}")
|
118
124
|
end
|
119
|
-
|
125
|
+
|
120
126
|
# @param identifier [String] the identifier to modify
|
121
127
|
# @param metadata [String, Hash, Ezid::Metadata] metadata to set
|
122
128
|
# @raise [Ezid::Error]
|
123
129
|
# @return [Ezid::Response] the response
|
124
130
|
def modify_identifier(identifier, metadata)
|
125
|
-
response = Request.execute(:Post, "/id/#{identifier}") do |request|
|
131
|
+
response = Request.execute(:Post, build_uri("/id/#{identifier}")) do |request|
|
126
132
|
add_authentication(request)
|
127
133
|
add_metadata(request, metadata)
|
128
134
|
end
|
@@ -133,7 +139,7 @@ module Ezid
|
|
133
139
|
# @raise [Ezid::Error]
|
134
140
|
# @return [Ezid::Response] the response
|
135
141
|
def get_identifier_metadata(identifier)
|
136
|
-
response = Request.execute(:Get, "/id/#{identifier}") do |request|
|
142
|
+
response = Request.execute(:Get, build_uri("/id/#{identifier}")) do |request|
|
137
143
|
add_authentication(request)
|
138
144
|
end
|
139
145
|
handle_response(response, "GET #{identifier}")
|
@@ -143,7 +149,7 @@ module Ezid
|
|
143
149
|
# @raise [Ezid::Error]
|
144
150
|
# @return [Ezid::Response] the response
|
145
151
|
def delete_identifier(identifier)
|
146
|
-
response = Request.execute(:Delete, "/id/#{identifier}") do |request|
|
152
|
+
response = Request.execute(:Delete, build_uri("/id/#{identifier}")) do |request|
|
147
153
|
add_authentication(request)
|
148
154
|
end
|
149
155
|
handle_response(response, "DELETE #{identifier}")
|
@@ -153,12 +159,17 @@ module Ezid
|
|
153
159
|
# @raise [Ezid::Error]
|
154
160
|
# @return [Ezid::Status] the status response
|
155
161
|
def server_status(*subsystems)
|
156
|
-
response = Request.execute(:Get, "/status?subsystems=#{subsystems.join(',')}")
|
162
|
+
response = Request.execute(:Get, build_uri("/status?subsystems=#{subsystems.join(',')}"))
|
157
163
|
handle_response(Status.new(response), "STATUS")
|
158
164
|
end
|
159
165
|
|
160
166
|
private
|
161
167
|
|
168
|
+
def build_uri(path)
|
169
|
+
scheme = use_ssl ? "https" : "http"
|
170
|
+
URI([scheme, "://", host, path].join)
|
171
|
+
end
|
172
|
+
|
162
173
|
# Adds authentication data to the request
|
163
174
|
def add_authentication(request)
|
164
175
|
if session.open?
|
@@ -172,7 +183,7 @@ module Ezid
|
|
172
183
|
def add_metadata(request, metadata)
|
173
184
|
return if metadata.nil? || metadata.empty?
|
174
185
|
metadata = Metadata.new(metadata) unless metadata.is_a?(Metadata)
|
175
|
-
request.body = metadata.to_anvl(false)
|
186
|
+
request.body = metadata.to_anvl(false)
|
176
187
|
end
|
177
188
|
|
178
189
|
def handle_response(response, request_info)
|
data/lib/ezid/configuration.rb
CHANGED
@@ -9,6 +9,16 @@ module Ezid
|
|
9
9
|
# @api private
|
10
10
|
class Configuration
|
11
11
|
|
12
|
+
HOST = "ezid.cdlib.org"
|
13
|
+
|
14
|
+
# EZID host name
|
15
|
+
# Default: "ezid.cdlib.org"
|
16
|
+
attr_accessor :host
|
17
|
+
|
18
|
+
# Use HTTPS?
|
19
|
+
# Default: `true`
|
20
|
+
attr_accessor :use_ssl
|
21
|
+
|
12
22
|
# EZID user name
|
13
23
|
# Default: value of `EZID_USER` environment variable
|
14
24
|
attr_accessor :user
|
@@ -22,7 +32,7 @@ module Ezid
|
|
22
32
|
attr_writer :logger
|
23
33
|
|
24
34
|
# Default metadata profile - "erc" (EZID default), "dc", "datacite", or "crossref"
|
25
|
-
# If set, new identifiers (created or minted) will set the "_profile" element to
|
35
|
+
# If set, new identifiers (created or minted) will set the "_profile" element to
|
26
36
|
# this value.
|
27
37
|
# attr_accessor :default_metadata_profile
|
28
38
|
|
@@ -38,6 +48,8 @@ module Ezid
|
|
38
48
|
def initialize
|
39
49
|
@user = ENV["EZID_USER"]
|
40
50
|
@password = ENV["EZID_PASSWORD"]
|
51
|
+
@host = ENV["EZID_HOST"] || HOST
|
52
|
+
@use_ssl = ENV["EZID_USE_SSL"] != false.to_s
|
41
53
|
end
|
42
54
|
|
43
55
|
def logger
|
data/lib/ezid/identifier.rb
CHANGED
@@ -23,7 +23,7 @@ module Ezid
|
|
23
23
|
RESERVED = "reserved"
|
24
24
|
UNAVAILABLE = "unavailable"
|
25
25
|
|
26
|
-
class << self
|
26
|
+
class << self
|
27
27
|
attr_accessor :defaults
|
28
28
|
|
29
29
|
# Creates or mints an identifier (depending on arguments)
|
@@ -80,7 +80,7 @@ module Ezid
|
|
80
80
|
reload
|
81
81
|
end
|
82
82
|
|
83
|
-
# Updates the metadata
|
83
|
+
# Updates the metadata
|
84
84
|
# @param attrs [Hash] the metadata
|
85
85
|
# @return [Ezid::Identifier] the identifier
|
86
86
|
def update_metadata(attrs={})
|
data/lib/ezid/metadata.rb
CHANGED
@@ -29,17 +29,17 @@ module Ezid
|
|
29
29
|
UNESCAPE_RE = /%\h\h/
|
30
30
|
|
31
31
|
# A comment line
|
32
|
-
COMMENT_RE = /^#.*(\r?\n)?/
|
32
|
+
COMMENT_RE = /^#.*(\r?\n)?/
|
33
33
|
|
34
34
|
# A line continuation
|
35
35
|
LINE_CONTINUATION_RE = /\r?\n\s+/
|
36
36
|
|
37
37
|
# A line ending
|
38
38
|
LINE_ENDING_RE = /\r?\n/
|
39
|
-
|
39
|
+
|
40
40
|
# A metadata element
|
41
41
|
Element = Struct.new(:name, :writer)
|
42
|
-
|
42
|
+
|
43
43
|
# Metadata profiles
|
44
44
|
PROFILES = {
|
45
45
|
"dc" => %w( creator title publisher date type ).freeze,
|
@@ -99,7 +99,7 @@ module Ezid
|
|
99
99
|
def self.define_element_accessors
|
100
100
|
elements.each do |accessor, element|
|
101
101
|
define_method(accessor) { reader(element.name) }
|
102
|
-
|
102
|
+
|
103
103
|
if element.writer
|
104
104
|
define_method("#{accessor}=") { |value| writer(element.name, value) }
|
105
105
|
end
|
@@ -127,7 +127,7 @@ module Ezid
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
private_class_method :register_element, :register_elements, :register_reserved_elements,
|
130
|
+
private_class_method :register_element, :register_elements, :register_reserved_elements,
|
131
131
|
:register_profile_elements, :define_element_accessors
|
132
132
|
|
133
133
|
def initialize(data={})
|
@@ -202,7 +202,7 @@ module Ezid
|
|
202
202
|
def unescape(value)
|
203
203
|
value.gsub(UNESCAPE_RE) { |m| URI.decode_www_form_component(m) }
|
204
204
|
end
|
205
|
-
|
205
|
+
|
206
206
|
# Coerce a string of metadata (e.g., from EZID host) into a Hash
|
207
207
|
# @note EZID host does not send comments or line continuations.
|
208
208
|
# @param data [String] the string to coerce
|
data/lib/ezid/request.rb
CHANGED
@@ -10,7 +10,6 @@ module Ezid
|
|
10
10
|
#
|
11
11
|
class Request < SimpleDelegator
|
12
12
|
|
13
|
-
HOST = "https://ezid.cdlib.org"
|
14
13
|
CHARSET = "UTF-8"
|
15
14
|
CONTENT_TYPE = "text/plain"
|
16
15
|
|
@@ -21,10 +20,9 @@ module Ezid
|
|
21
20
|
end
|
22
21
|
|
23
22
|
# @param method [Symbol] the Net::HTTP constant for the request method
|
24
|
-
# @param
|
25
|
-
def initialize(method, path)
|
23
|
+
# @param uri [URI] the uri
|
24
|
+
def initialize(method, uri) # path)
|
26
25
|
http_method = Net::HTTP.const_get(method)
|
27
|
-
uri = URI.parse([HOST, path].join)
|
28
26
|
super(http_method.new(uri))
|
29
27
|
set_content_type(CONTENT_TYPE, charset: CHARSET)
|
30
28
|
end
|
@@ -32,11 +30,15 @@ module Ezid
|
|
32
30
|
# Executes the request and returns the response
|
33
31
|
# @return [Ezid::Response] the response
|
34
32
|
def execute
|
35
|
-
http_response = Net::HTTP.start(uri.host, use_ssl:
|
33
|
+
http_response = Net::HTTP.start(uri.host, use_ssl: use_ssl?) do |http|
|
36
34
|
http.request(__getobj__)
|
37
35
|
end
|
38
36
|
Response.new(http_response)
|
39
37
|
end
|
40
38
|
|
39
|
+
def use_ssl?
|
40
|
+
uri.is_a?(URI::HTTPS)
|
41
|
+
end
|
42
|
+
|
41
43
|
end
|
42
44
|
end
|
data/lib/ezid/session.rb
CHANGED
data/lib/ezid/status.rb
CHANGED
@@ -15,7 +15,7 @@ module Ezid
|
|
15
15
|
|
16
16
|
def subsystems
|
17
17
|
return {} unless content[1]
|
18
|
-
content[1].split(/\r?\n/).each_with_object({}) do |line, memo|
|
18
|
+
content[1].split(/\r?\n/).each_with_object({}) do |line, memo|
|
19
19
|
subsystem, status = line.split(": ", 2)
|
20
20
|
memo[subsystem] = status
|
21
21
|
end
|
data/lib/ezid/test_helper.rb
CHANGED
@@ -6,12 +6,15 @@ module Ezid
|
|
6
6
|
TEST_ARK_SHOULDER = "ark:/99999/fk4"
|
7
7
|
TEST_DOI_SHOULDER = "doi:10.5072/FK2"
|
8
8
|
TEST_USER = "apitest"
|
9
|
+
TEST_HOST = Configuration::HOST
|
9
10
|
|
10
11
|
def ezid_test_mode!
|
11
12
|
Ezid::Client.configure do |config|
|
12
13
|
config.user = TEST_USER
|
13
|
-
# Contact EZID for password
|
14
|
+
# Contact EZID for password, or use your own user name and password
|
14
15
|
# config.password = "********"
|
16
|
+
config.host = TEST_HOST
|
17
|
+
config.use_ssl = true
|
15
18
|
config.logger = Logger.new(File::NULL)
|
16
19
|
config.default_shoulder = TEST_ARK_SHOULDER
|
17
20
|
end
|
@@ -21,4 +24,3 @@ module Ezid
|
|
21
24
|
end
|
22
25
|
|
23
26
|
include Ezid::TestHelper
|
24
|
-
|
@@ -2,7 +2,7 @@ module Ezid
|
|
2
2
|
RSpec.describe Client do
|
3
3
|
|
4
4
|
shared_examples "an EZID client" do |client|
|
5
|
-
it "should mint and modify" do
|
5
|
+
it "should mint and modify" do
|
6
6
|
minted = client.mint_identifier(TEST_ARK_SHOULDER, "_status: reserved")
|
7
7
|
expect(minted).to be_success
|
8
8
|
@id = minted.id
|
@@ -25,7 +25,7 @@ module Ezid
|
|
25
25
|
expect(client.session).to be_open
|
26
26
|
end
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
29
29
|
|
30
30
|
describe "authentication" do
|
31
31
|
describe "#login" do
|
data/spec/unit/client_spec.rb
CHANGED
@@ -1,40 +1,47 @@
|
|
1
1
|
module Ezid
|
2
2
|
RSpec.describe Client do
|
3
3
|
|
4
|
+
let(:stub_response) { Response.new(http_response) }
|
5
|
+
let(:stub_uri) { double }
|
6
|
+
|
4
7
|
describe "initialization without a block" do
|
5
8
|
it "should not login" do
|
6
9
|
expect_any_instance_of(described_class).not_to receive(:login)
|
7
10
|
described_class.new
|
8
11
|
end
|
9
|
-
end
|
12
|
+
end
|
10
13
|
|
11
14
|
describe "#create_identifier" do
|
12
15
|
let(:id) { "ark:/99999/fk4fn19h88" }
|
13
16
|
let(:http_response) { double(body: "success: ark:/99999/fk4fn19h88") }
|
14
|
-
let(:stub_response) { Response.new(http_response) }
|
15
17
|
before do
|
16
|
-
allow(
|
18
|
+
allow(subject).to receive(:build_uri).with("/id/#{id}") { stub_uri }
|
19
|
+
allow(Request).to receive(:execute).with(:Put, stub_uri) { stub_response }
|
17
20
|
end
|
18
|
-
subject { described_class.new.create_identifier(id) }
|
19
21
|
it "should be a success" do
|
20
|
-
|
21
|
-
expect(
|
22
|
+
response = subject.create_identifier(id)
|
23
|
+
expect(response).to be_success
|
24
|
+
expect(response.id).to eq(id)
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
28
|
describe "#mint_identifier" do
|
29
|
+
before do
|
30
|
+
allow(Request).to receive(:execute).with(:Post, stub_uri) { stub_response }
|
31
|
+
end
|
26
32
|
describe "which is an ARK" do
|
27
|
-
let(:
|
28
|
-
before
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
let(:http_response) { double(body: "success: ark:/99999/fk4fn19h88") }
|
34
|
+
before do
|
35
|
+
allow(subject).to receive(:build_uri).with("/shoulder/#{TEST_ARK_SHOULDER}") { stub_uri }
|
36
|
+
end
|
37
|
+
it "should be a success" do
|
38
|
+
response = subject.mint_identifier(TEST_ARK_SHOULDER)
|
39
|
+
expect(response).to be_success
|
40
|
+
expect(response.id).to eq("ark:/99999/fk4fn19h88")
|
33
41
|
end
|
34
42
|
end
|
35
43
|
describe "which is a DOI" do
|
36
44
|
let(:http_response) { double(body: "success: doi:10.5072/FK2TEST | ark:/99999/fk4fn19h88") }
|
37
|
-
let(:stub_response) { Response.new(http_response) }
|
38
45
|
let(:metadata) do
|
39
46
|
<<-EOS
|
40
47
|
datacite.title: Test
|
@@ -44,38 +51,41 @@ datacite.publicationyear: 2014
|
|
44
51
|
datacite.resourcetype: Other
|
45
52
|
EOS
|
46
53
|
end
|
47
|
-
before
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
expect(
|
54
|
+
before do
|
55
|
+
allow(subject).to receive(:build_uri).with("/shoulder/#{TEST_DOI_SHOULDER}") { stub_uri }
|
56
|
+
end
|
57
|
+
it "should be a sucess" do
|
58
|
+
response = subject.mint_identifier(TEST_DOI_SHOULDER, metadata)
|
59
|
+
expect(response).to be_success
|
60
|
+
expect(response.id).to eq("doi:10.5072/FK2TEST")
|
61
|
+
expect(response.shadow_ark).to eq("ark:/99999/fk4fn19h88")
|
53
62
|
end
|
54
63
|
end
|
55
64
|
describe "when a shoulder is not given" do
|
56
|
-
let(:
|
65
|
+
let(:http_response) { double(body: "success: ark:/99999/fk4fn19h88") }
|
57
66
|
context "and the :default_shoulder config option is set" do
|
58
|
-
subject { described_class.new.mint_identifier }
|
59
67
|
before do
|
60
|
-
allow(
|
61
|
-
allow(Client.config).to receive(:default_shoulder) { TEST_ARK_SHOULDER }
|
68
|
+
allow(subject).to receive(:build_uri).with("/shoulder/#{TEST_ARK_SHOULDER}") { stub_uri }
|
69
|
+
allow(Client.config).to receive(:default_shoulder) { TEST_ARK_SHOULDER }
|
62
70
|
end
|
63
71
|
it "should use the default shoulder" do
|
64
|
-
|
72
|
+
response = subject.mint_identifier
|
73
|
+
expect(response).to be_success
|
65
74
|
end
|
66
75
|
end
|
67
76
|
context "and the :default_shoulder config option is not set" do
|
68
77
|
before { allow(Client.config).to receive(:default_shoulder) { nil } }
|
69
78
|
it "should raise an exception" do
|
70
|
-
expect {
|
79
|
+
expect { subject.mint_identifier }.to raise_error
|
71
80
|
end
|
72
81
|
end
|
73
82
|
end
|
74
83
|
end
|
75
84
|
|
76
85
|
describe "#get_identifier_metadata" do
|
77
|
-
let(:
|
78
|
-
|
86
|
+
let(:id) { "ark:/99999/fk4fn19h88" }
|
87
|
+
let(:http_response) do
|
88
|
+
double(body: <<-EOS
|
79
89
|
success: ark:/99999/fk4fn19h88
|
80
90
|
_updated: 1416507086
|
81
91
|
_target: http://ezid.cdlib.org/id/ark:/99999/fk4fn19h88
|
@@ -86,14 +96,16 @@ _export: yes
|
|
86
96
|
_created: 1416507086
|
87
97
|
_status: public
|
88
98
|
EOS
|
89
|
-
)
|
99
|
+
)
|
90
100
|
end
|
91
101
|
before do
|
92
|
-
allow(
|
102
|
+
allow(subject).to receive(:build_uri).with("/id/#{id}") { stub_uri }
|
103
|
+
allow(Request).to receive(:execute).with(:Get, stub_uri) { stub_response }
|
93
104
|
end
|
94
|
-
subject { described_class.new.get_identifier_metadata("ark:/99999/fk4fn19h88") }
|
95
105
|
it "should retrieve the metadata" do
|
96
|
-
|
106
|
+
response = subject.get_identifier_metadata(id)
|
107
|
+
expect(response).to be_success
|
108
|
+
expect(response.metadata).to eq <<-EOS
|
97
109
|
_updated: 1416507086
|
98
110
|
_target: http://ezid.cdlib.org/id/ark:/99999/fk4fn19h88
|
99
111
|
_profile: erc
|
@@ -113,28 +125,25 @@ success: EZID is up
|
|
113
125
|
noid: up
|
114
126
|
ldap: up
|
115
127
|
EOS
|
116
|
-
)
|
128
|
+
)
|
117
129
|
end
|
118
|
-
let(:stub_response) { Response.new(http_response) }
|
119
130
|
before do
|
120
|
-
allow(
|
131
|
+
allow(subject).to receive(:build_uri).with("/status?subsystems=*") { stub_uri }
|
132
|
+
allow(Request).to receive(:execute).with(:Get, stub_uri) { stub_response }
|
121
133
|
end
|
122
|
-
subject { described_class.new.server_status("*") }
|
123
134
|
it "should report the status of EZID and subsystems" do
|
124
|
-
|
125
|
-
expect(
|
126
|
-
expect(
|
127
|
-
expect(
|
128
|
-
expect(
|
129
|
-
expect(
|
135
|
+
response = subject.server_status("*")
|
136
|
+
expect(response).to be_success
|
137
|
+
expect(response).to be_up
|
138
|
+
expect(response.message).to eq("EZID is up")
|
139
|
+
expect(response.noid).to eq("up")
|
140
|
+
expect(response.ldap).to eq("up")
|
141
|
+
expect(response.datacite).to eq("not checked")
|
130
142
|
end
|
131
143
|
end
|
132
144
|
|
133
145
|
describe "error handling" do
|
134
|
-
let(:
|
135
|
-
before do
|
136
|
-
allow(Request).to receive(:execute) { stub_response }
|
137
|
-
end
|
146
|
+
let(:http_response) { double(body: "error: bad request - no such identifier") }
|
138
147
|
it "should raise an exception" do
|
139
148
|
expect { subject.get_identifier_metadata("invalid") }.to raise_error
|
140
149
|
end
|
@@ -3,7 +3,7 @@ module Ezid
|
|
3
3
|
|
4
4
|
describe ".create" do
|
5
5
|
let(:attrs) { {shoulder: TEST_ARK_SHOULDER, profile: "dc", target: "http://example.com"} }
|
6
|
-
it "should instantiate a new Identifier and save it" do
|
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 }
|
9
9
|
described_class.create(attrs)
|
@@ -67,7 +67,7 @@ module Ezid
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
describe "#update" do
|
72
72
|
let(:metadata) { {"status" => "unavailable"} }
|
73
73
|
subject { described_class.new(id: "id") }
|
@@ -169,19 +169,19 @@ module Ezid
|
|
169
169
|
describe "boolean status methods" do
|
170
170
|
context "when the status is 'public'" do
|
171
171
|
before { allow(subject.metadata).to receive(:status) { Identifier::PUBLIC } }
|
172
|
-
it { is_expected.to be_public }
|
172
|
+
it { is_expected.to be_public }
|
173
173
|
it { is_expected.not_to be_reserved }
|
174
174
|
it { is_expected.not_to be_unavailable }
|
175
175
|
end
|
176
176
|
context "when the status is 'reserved'" do
|
177
177
|
before { allow(subject.metadata).to receive(:status) { Identifier::RESERVED } }
|
178
|
-
it { is_expected.not_to be_public }
|
178
|
+
it { is_expected.not_to be_public }
|
179
179
|
it { is_expected.to be_reserved }
|
180
180
|
it { is_expected.not_to be_unavailable }
|
181
181
|
end
|
182
182
|
context "when the status is 'unavailable'" do
|
183
183
|
before { allow(subject.metadata).to receive(:status) { Identifier::UNAVAILABLE } }
|
184
|
-
it { is_expected.not_to be_public }
|
184
|
+
it { is_expected.not_to be_public }
|
185
185
|
it { is_expected.not_to be_reserved }
|
186
186
|
it { is_expected.to be_unavailable }
|
187
187
|
end
|
data/spec/unit/metadata_spec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Ezid
|
2
2
|
RSpec.describe Metadata do
|
3
|
-
|
3
|
+
|
4
4
|
describe "reserved elements" do
|
5
5
|
describe "readers" do
|
6
|
-
Metadata::RESERVED_ELEMENTS.each do |element|
|
6
|
+
Metadata::RESERVED_ELEMENTS.each do |element|
|
7
7
|
it "should have a reader for '#{element}'" do
|
8
8
|
expect(subject).to receive(:reader).with(element)
|
9
9
|
reader = (element == "_crossref") ? element : element.sub("_", "")
|
@@ -29,7 +29,7 @@ module Ezid
|
|
29
29
|
expect(subject).to receive(:writer).with(element, "value")
|
30
30
|
writer = ((element == "_crossref") ? element : element.sub("_", "")).concat("=")
|
31
31
|
subject.send(writer, "value")
|
32
|
-
end
|
32
|
+
end
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -37,7 +37,7 @@ module Ezid
|
|
37
37
|
Metadata::PROFILES.each do |profile, elements|
|
38
38
|
describe "the '#{profile}' metadata profile" do
|
39
39
|
describe "readers" do
|
40
|
-
elements.each do |element|
|
40
|
+
elements.each do |element|
|
41
41
|
it "should have a reader for '#{profile}.#{element}'" do
|
42
42
|
expect(subject).to receive(:reader).with("#{profile}.#{element}")
|
43
43
|
subject.send("#{profile}_#{element}")
|
@@ -45,7 +45,7 @@ module Ezid
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
describe "writers" do
|
48
|
-
elements.each do |element|
|
48
|
+
elements.each do |element|
|
49
49
|
it "should have a writer for '#{profile}.#{element}'" do
|
50
50
|
expect(subject).to receive(:writer).with("#{profile}.#{element}", "value")
|
51
51
|
subject.send("#{profile}_#{element}=", "value")
|
@@ -66,7 +66,7 @@ module Ezid
|
|
66
66
|
end
|
67
67
|
|
68
68
|
describe "ANVL output" do
|
69
|
-
let(:elements) do
|
69
|
+
let(:elements) do
|
70
70
|
{ "_target" => "http://example.com/path%20with%20spaces",
|
71
71
|
"_erc" => "who: Proust, Marcel\nwhat: Remembrance of Things Past",
|
72
72
|
"_status" => "public" }
|
@@ -122,7 +122,7 @@ EOS
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
context "of a hash-like object" do
|
125
|
-
let(:hsh) do
|
125
|
+
let(:hsh) do
|
126
126
|
{ "_updated" => "1416507086",
|
127
127
|
"_target" => "http://ezid.cdlib.org/id/ark:/99999/fk4fn19h87",
|
128
128
|
"_profile" => "erc",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ezid-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Chandek-Stark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|