ezid-client 0.12.0 → 0.13.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: 06c4a2e03acdbef8b3da067ca693fd51f8a5ba1e
4
- data.tar.gz: 5347307f3892f3beaac5ea59e2a8d091b2ad12ac
3
+ metadata.gz: a879db606f554ad22f27d2a94de3ea22b13b4b45
4
+ data.tar.gz: cbf0e449920590e6c7e5bbf83fade23fca94a474
5
5
  SHA512:
6
- metadata.gz: acb785db04eaae33f870c1dd7ab1e292ca58b5b4dab7647b2ac15cb0daae37c3d82b4065f60380efb6530353e83c204d25d7206ec506636c19d77d751549293e
7
- data.tar.gz: 34a9362e2dc610bf0a03c14d4174726556286d8e892a04b4eee9e4a06d9f916802bd668a64679f9e4b67402e66c1613948ed2487859301f01bf4160140aef99b
6
+ metadata.gz: f4edff18cfd3337b0445ea6aa57fcaa43cdfaa70c0f2538c8df63feb37901f51b155b45039849359bbff5cd0c574183a5efb521102f15f145b643c5b77a22085
7
+ data.tar.gz: 70325ab88f390c26180dc130b7862f4b0b6e70584c4178e8c707f8c2a9ae78f098fc06b4e6eb37225ddc1f650d36760e0364d8ea938f2a258e57adebe3cf1ca7
data/README.md CHANGED
@@ -29,8 +29,8 @@ Or install it yourself as:
29
29
 
30
30
  ```
31
31
  >> identifier = Ezid::Identifier.create(shoulder: "ark:/99999/fk4")
32
- I, [2014-12-04T15:06:02.428445 #86655] INFO -- : EZID MINT ark:/99999/fk4 -- success: ark:/99999/fk4rx9d523
33
- I, [2014-12-04T15:06:03.249793 #86655] INFO -- : EZID GET ark:/99999/fk4rx9d523 -- success: ark:/99999/fk4rx9d523
32
+ I, [2014-12-04T15:06:02.428445 #86655] INFO -- : EZID MintIdentifier -- success: ark:/99999/fk4rx9d523
33
+ I, [2014-12-04T15:06:03.249793 #86655] INFO -- : EZID GetIdentifierMetadata -- success: ark:/99999/fk4rx9d523
34
34
  => #<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">
35
35
  >> identifier.id
36
36
  => "ark:/99999/fk4rx9d523"
@@ -60,8 +60,8 @@ New identifiers will then be minted on the default shoulder when a shoulder is n
60
60
 
61
61
  ```
62
62
  >> identifier = Ezid::Identifier.create
63
- I, [2014-12-09T11:22:34.499860 #32279] INFO -- : EZID MINT ark:/99999/fk4 -- success: ark:/99999/fk43f4wd4v
64
- I, [2014-12-09T11:22:35.317181 #32279] INFO -- : EZID GET ark:/99999/fk43f4wd4v -- success: ark:/99999/fk43f4wd4v
63
+ I, [2014-12-09T11:22:34.499860 #32279] INFO -- : EZID MintIdentifier -- success: ark:/99999/fk43f4wd4v
64
+ I, [2014-12-09T11:22:35.317181 #32279] INFO -- : EZID GetIdentifierMetadata -- success: ark:/99999/fk43f4wd4v
65
65
  => #<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">
66
66
  ```
67
67
 
@@ -69,8 +69,8 @@ I, [2014-12-09T11:22:35.317181 #32279] INFO -- : EZID GET ark:/99999/fk43f4wd4v
69
69
 
70
70
  ```
71
71
  >> identifier = Ezid::Identifier.create(id: "ark:/99999/fk4rx9d523/12345")
72
- I, [2014-12-09T11:21:42.077297 #32279] INFO -- : EZID CREATE ark:/99999/fk4rx9d523/12345 -- success: ark:/99999/fk4rx9d523/12345
73
- I, [2014-12-09T11:21:42.808534 #32279] INFO -- : EZID GET ark:/99999/fk4rx9d523/12345 -- success: ark:/99999/fk4rx9d523/12345
72
+ I, [2014-12-09T11:21:42.077297 #32279] INFO -- : EZID CreateIdentifier -- success: ark:/99999/fk4rx9d523/12345
73
+ I, [2014-12-09T11:21:42.808534 #32279] INFO -- : EZID GetIdentifierMetadata -- success: ark:/99999/fk4rx9d523/12345
74
74
  => #<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">
75
75
  ```
76
76
 
@@ -78,7 +78,7 @@ I, [2014-12-09T11:21:42.808534 #32279] INFO -- : EZID GET ark:/99999/fk4rx9d523
78
78
 
79
79
  ```
80
80
  >> identifier = Ezid::Identifier.find("ark:/99999/fk4rx9d523")
81
- I, [2014-12-04T15:07:00.648676 #86655] INFO -- : EZID GET ark:/99999/fk4rx9d523 -- success: ark:/99999/fk4rx9d523
81
+ I, [2014-12-04T15:07:00.648676 #86655] INFO -- : EZID GetIdentifierMetadata -- success: ark:/99999/fk4rx9d523
82
82
  => #<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">
83
83
  ```
84
84
 
@@ -90,8 +90,8 @@ I, [2014-12-04T15:07:00.648676 #86655] INFO -- : EZID GET ark:/99999/fk4rx9d523
90
90
  >> identifier.target = "http://example.com"
91
91
  => "http://example.com"
92
92
  >> identifier.save
93
- I, [2014-12-09T11:24:26.321801 #32279] INFO -- : EZID MODIFY ark:/99999/fk43f4wd4v -- success: ark:/99999/fk43f4wd4v
94
- I, [2014-12-09T11:24:27.039288 #32279] INFO -- : EZID GET ark:/99999/fk43f4wd4v -- success: ark:/99999/fk43f4wd4v
93
+ I, [2014-12-09T11:24:26.321801 #32279] INFO -- : EZID ModifyIdentifier -- success: ark:/99999/fk43f4wd4v
94
+ I, [2014-12-09T11:24:27.039288 #32279] INFO -- : EZID GetIdentifierMetadata -- success: ark:/99999/fk43f4wd4v
95
95
  => #<Ezid::Identifier id="ark:/99999/fk43f4wd4v" status="public" target="http://example.com" created="2014-12-09 16:22:35 UTC">
96
96
  >> identifier.target
97
97
  => "http://example.com"
@@ -103,14 +103,32 @@ I, [2014-12-09T11:24:27.039288 #32279] INFO -- : EZID GET ark:/99999/fk43f4wd4v
103
103
 
104
104
  ```
105
105
  >> identifier = Ezid::Identifier.create(shoulder: "ark:/99999/fk4", status: "reserved")
106
- I, [2014-12-04T15:12:39.976930 #86734] INFO -- : EZID MINT ark:/99999/fk4 -- success: ark:/99999/fk4n58pc0r
107
- I, [2014-12-04T15:12:40.693256 #86734] INFO -- : EZID GET ark:/99999/fk4n58pc0r -- success: ark:/99999/fk4n58pc0r
106
+ I, [2014-12-04T15:12:39.976930 #86734] INFO -- : EZID MintIdentifier -- success: ark:/99999/fk4n58pc0r
107
+ I, [2014-12-04T15:12:40.693256 #86734] INFO -- : EZID GetIdentifierMetadata -- success: ark:/99999/fk4n58pc0r
108
108
  => #<Ezid::Identifier id="ark:/99999/fk4n58pc0r" status="reserved" target="http://ezid.cdlib.org/id/ark:/99999/fk4n58pc0r" created="2014-12-04 20:12:39 UTC">
109
109
  >> identifier.delete
110
- I, [2014-12-04T15:12:48.853964 #86734] INFO -- : EZID DELETE ark:/99999/fk4n58pc0r -- success: ark:/99999/fk4n58pc0r
110
+ I, [2014-12-04T15:12:48.853964 #86734] INFO -- : EZID DeleteIdentifier -- success: ark:/99999/fk4n58pc0r
111
111
  => #<Ezid::Identifier id="ark:/99999/fk4n58pc0r" DELETED>
112
112
  ```
113
113
 
114
+ ## Batch Download
115
+
116
+ Instantiate an `Ezid::Client` and call `batch_download` with hash options -- see http://ezid.cdlib.org/doc/apidoc.html#parameters. Repeated values should be given as an array value for the parameter key.
117
+
118
+ Note that, due to the asynchronous nature of this request, the response only returns the URL at which the batch will be available to download (as described in the EZID documentation). Use the `notify` option to specify one or more email addresses to receive notification when the download file is actually available.
119
+
120
+ **Example**
121
+
122
+ ```
123
+ >> c = Ezid::Client.new
124
+ => #<Ezid::Client connection=#<Net::HTTP ezid.cdlib.org:443 open=false> user="eziduser" session=CLOSED>
125
+ >> response = c.batch_download(format: "csv", notify: "eziduser@example.com", column: ["_id", "_target", "_status", "_profile", "_export", "_created", "_updated"], convertTimestamps: "yes", permanence: "real", owner: "eziduser")
126
+ I, [2015-02-20T15:16:53.462660 #55850] INFO -- : EZID BatchDownload -- success: http://ezid.cdlib.org/download/473deecb96.csv.gz
127
+ => #<Net::HTTPOK 200 OK readbody=true>
128
+ >> response.download_url
129
+ => "http://ezid.cdlib.org/download/da543b91a0.csv.gz"
130
+ ```
131
+
114
132
  ## Metadata handling
115
133
 
116
134
  Accessors are provided to ease the use of 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):
@@ -169,8 +187,8 @@ Then new identifiers will receive the defaults:
169
187
 
170
188
  ```
171
189
  >> identifier = Ezid::Identifier.create(shoulder: "ark:/99999/fk4")
172
- I, [2014-12-09T11:38:37.335136 #32279] INFO -- : EZID MINT ark:/99999/fk4 -- success: ark:/99999/fk4zs2w500
173
- I, [2014-12-09T11:38:38.153546 #32279] INFO -- : EZID GET ark:/99999/fk4zs2w500 -- success: ark:/99999/fk4zs2w500
190
+ I, [2014-12-09T11:38:37.335136 #32279] INFO -- : EZID MintIdentifier -- success: ark:/99999/fk4zs2w500
191
+ I, [2014-12-09T11:38:38.153546 #32279] INFO -- : EZID GetIdentifierMetadata -- success: ark:/99999/fk4zs2w500
174
192
  => #<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">
175
193
  >> identifier.profile
176
194
  => "dc"
@@ -232,6 +250,30 @@ end
232
250
  client = Ezid::Client.new(host: "localhost", port: 80)
233
251
  ```
234
252
 
253
+ ## HTTP Timeout
254
+
255
+ The default HTTP timeout is set to 300 seconds (5 minutes). The setting can be customized:
256
+
257
+ - By environment variable:
258
+
259
+ ```sh
260
+ export EZID_TIMEOUT=600
261
+ ```
262
+
263
+ - Client configuration:
264
+
265
+ ```ruby
266
+ Ezid::Client.configure do |config|
267
+ config.timeout = 600
268
+ end
269
+ ```
270
+
271
+ - At client initialization
272
+
273
+ ```ruby
274
+ client = Ezid::Client.new(timeout: 600)
275
+ ```
276
+
235
277
  ## Test Helper
236
278
 
237
279
  If you have tests that (directly or indirectly) use `ezid-client` you may want to require the test helper module:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.12.0
1
+ 0.13.0
data/lib/ezid/client.rb CHANGED
@@ -42,12 +42,13 @@ module Ezid
42
42
  end
43
43
  end
44
44
 
45
- attr_reader :user, :password, :host, :port, :use_ssl
45
+ attr_reader :user, :password, :host, :port, :use_ssl, :timeout
46
46
 
47
47
  def initialize(opts = {})
48
48
  @host = opts[:host] || config.host
49
49
  @port = (opts[:port] || config.port).to_i
50
50
  @use_ssl = opts[:use_ssl] || config.use_ssl
51
+ @timeout = (opts[:timeout] || config.timeout).to_i
51
52
  @user = opts[:user] || config.user
52
53
  @password = opts[:password] || config.password
53
54
  if block_given?
@@ -169,6 +170,14 @@ module Ezid
169
170
  execute ServerStatusRequest, *subsystems
170
171
  end
171
172
 
173
+ # Submit a batch download request
174
+ # @see http://ezid.cdlib.org/doc/apidoc.html#batch-download
175
+ # @param format [String] format of results - one of "anvl", "csv", "xml"
176
+ # @param params [Hash] optional request parameters
177
+ def batch_download(params={})
178
+ execute BatchDownloadRequest, params
179
+ end
180
+
172
181
  # The Net::HTTP object used to connect to EZID
173
182
  # @return [Net::HTTP] the connection
174
183
  def connection
@@ -184,6 +193,7 @@ module Ezid
184
193
  def build_connection
185
194
  conn = Net::HTTP.new(host, port)
186
195
  conn.use_ssl = use_ssl?
196
+ conn.read_timeout = timeout
187
197
  conn
188
198
  end
189
199
 
@@ -12,31 +12,27 @@ module Ezid
12
12
 
13
13
  HOST = "ezid.cdlib.org"
14
14
  PORT = 443
15
+ TIMEOUT = 300
15
16
 
16
17
  # EZID host name
17
- # Default: value of `EZID_HOST` environment variable, if present, or
18
- # the EZID service host "ezid.cdlib.org".
19
18
  attr_accessor :host
20
19
 
21
20
  # EZID TCP/IP port
22
- # Default: value of `EZID_PORT` variable
23
21
  attr_accessor :port
24
22
 
25
23
  # Use HTTPS?
26
- # Default: `nil`; `true` if `EZID_USE_SSL` environment variable is set
27
- # to the string "true".
28
24
  attr_accessor :use_ssl
29
25
 
26
+ # HTTP read timeout (seconds)
27
+ attr_accessor :timeout
28
+
30
29
  # EZID user name
31
- # Default: value of `EZID_USER` environment variable
32
30
  attr_accessor :user
33
31
 
34
32
  # EZID password
35
- # Default: value of `EZID_PASSWORD` environment variable
36
33
  attr_accessor :password
37
34
 
38
35
  # Ruby logger instance
39
- # Default device: STDERR
40
36
  attr_writer :logger
41
37
 
42
38
  # Default shoulder for minting (scheme + NAAN + shoulder)
@@ -48,7 +44,8 @@ module Ezid
48
44
  @password = ENV["EZID_PASSWORD"]
49
45
  @host = ENV["EZID_HOST"] || HOST
50
46
  @port = ENV["EZID_PORT"] || PORT
51
- @use_ssl = true if ENV["EZID_USE_SSL"] == true.to_s
47
+ @use_ssl = vvciujcrdjhcbtrue if ENV["EZID_USE_SSL"] == true.to_s
48
+ @timeout = ENV["EZID_TIMEOUT"] || TIMEOUT
52
49
  @default_shoulder = ENV["EZID_DEFAULT_SHOULDER"]
53
50
  end
54
51
 
@@ -0,0 +1,22 @@
1
+ require_relative "request"
2
+
3
+ module Ezid
4
+ class BatchDownloadRequest < Request
5
+
6
+ self.http_method = POST
7
+ self.path = "/download_request"
8
+ self.response_class = BatchDownloadResponse
9
+
10
+ attr_reader :params
11
+
12
+ def initialize(client, params={})
13
+ @params = params
14
+ super
15
+ end
16
+
17
+ def customize_request
18
+ set_form_data(params)
19
+ end
20
+
21
+ end
22
+ end
@@ -15,9 +15,6 @@ module Ezid
15
15
  class Request < SimpleDelegator
16
16
  extend Forwardable
17
17
 
18
- CHARSET = "UTF-8"
19
- CONTENT_TYPE = "text/plain"
20
-
21
18
  # HTTP methods
22
19
  GET = Net::HTTP::Get
23
20
  PUT = Net::HTTP::Put
@@ -45,6 +42,7 @@ module Ezid
45
42
  def initialize(client, *args)
46
43
  @client = client
47
44
  super build_request
45
+ customize_request
48
46
  end
49
47
 
50
48
  # Executes the request and returns the response
@@ -93,13 +91,16 @@ module Ezid
93
91
 
94
92
  def get_response_for_request
95
93
  connection.start do |conn|
96
- set_content_type(CONTENT_TYPE, charset: CHARSET)
97
94
  add_authentication if authentication_required?
98
95
  add_metadata if has_metadata?
99
96
  conn.request(__getobj__)
100
97
  end
101
98
  end
102
99
 
100
+ def customize_request
101
+ set_content_type("text/plain", charset: "UTF-8")
102
+ end
103
+
103
104
  def build_request
104
105
  self.class.http_method.new(uri)
105
106
  end
@@ -0,0 +1,11 @@
1
+ require_relative "response"
2
+
3
+ module Ezid
4
+ class BatchDownloadResponse < Response
5
+
6
+ def download_url
7
+ message
8
+ end
9
+
10
+ end
11
+ end
@@ -1,3 +1,5 @@
1
+ require "time"
2
+
1
3
  module Ezid
2
4
  RSpec.describe Client do
3
5
 
@@ -9,7 +11,6 @@ module Ezid
9
11
  modified = client.modify_identifier(@id, "dc.title" => "Test")
10
12
  expect(modified).to be_success
11
13
  retrieved = client.get_identifier_metadata(@id)
12
- puts retrieved.class.to_s
13
14
  expect(retrieved).to be_success
14
15
  expect(retrieved.metadata).to match(/dc.title: Test/)
15
16
  deleted = client.delete_identifier(@id)
@@ -63,5 +64,19 @@ module Ezid
63
64
  end
64
65
  end
65
66
 
67
+ describe "batch download" do
68
+ before do
69
+ r = subject.mint_identifier
70
+ r = subject.get_identifier_metadata(r.id)
71
+ metadata = Metadata.new(r.metadata)
72
+ @created = metadata.created.iso8601
73
+ end
74
+ it "should return a valid URL" do
75
+ response = subject.batch_download(format: "anvl", createdAfter: @created, permanence: "test")
76
+ expect(response).to be_success
77
+ expect(response.download_url).to match(/^http:\/\/ezid.cdlib.org\/download\/[^\/]+.gz$/)
78
+ end
79
+ end
80
+
66
81
  end
67
82
  end
@@ -0,0 +1,26 @@
1
+ module Ezid
2
+ RSpec.describe BatchDownloadRequest do
3
+
4
+ let(:client) { Client.new }
5
+ let(:params) do
6
+ { format: "xml",
7
+ notify: "noreply@example.com",
8
+ convertTimestamps: "yes",
9
+ exported: "no",
10
+ owner: ["you", "me"],
11
+ status: ["reserved", "unavailable"],
12
+ type: "ark"
13
+ }
14
+ end
15
+ subject { described_class.new(client, params) }
16
+
17
+ it "should add the request params to the request body" do
18
+ expect(subject.body).to eq("format=xml&notify=noreply%40example.com&convertTimestamps=yes&exported=no&owner=you&owner=me&status=reserved&status=unavailable&type=ark")
19
+ end
20
+
21
+ it "should have the correct content type" do
22
+ expect(subject.content_type).to eq("application/x-www-form-urlencoded")
23
+ end
24
+
25
+ end
26
+ end
@@ -137,6 +137,19 @@ EOS
137
137
  end
138
138
  end
139
139
 
140
+ describe "batch download" do
141
+ let(:stub_response) { BatchDownloadResponse.new(http_response) }
142
+ let(:http_response) { double(body: "success: http://ezid.cdlib.org/download/da543b91a0.xml.gz") }
143
+ before do
144
+ allow(BatchDownloadRequest).to receive(:execute).with(subject, format: "xml") { stub_response }
145
+ end
146
+ it "should return the URL to download the batch" do
147
+ response = subject.batch_download(format: "xml")
148
+ expect(response).to be_success
149
+ expect(response.download_url).to eq("http://ezid.cdlib.org/download/da543b91a0.xml.gz")
150
+ end
151
+ end
152
+
140
153
  describe "error handling" do
141
154
  let(:http_response) { double(body: "error: bad request - no such identifier") }
142
155
  it "should raise an exception" do
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.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Chandek-Stark
@@ -74,6 +74,7 @@ files:
74
74
  - lib/ezid/error.rb
75
75
  - lib/ezid/identifier.rb
76
76
  - lib/ezid/metadata.rb
77
+ - lib/ezid/requests/batch_download_request.rb
77
78
  - lib/ezid/requests/create_identifier_request.rb
78
79
  - lib/ezid/requests/delete_identifier_request.rb
79
80
  - lib/ezid/requests/get_identifier_metadata_request.rb
@@ -85,6 +86,7 @@ files:
85
86
  - lib/ezid/requests/modify_identifier_request.rb
86
87
  - lib/ezid/requests/request.rb
87
88
  - lib/ezid/requests/server_status_request.rb
89
+ - lib/ezid/responses/batch_download_response.rb
88
90
  - lib/ezid/responses/create_identifier_response.rb
89
91
  - lib/ezid/responses/delete_identifier_response.rb
90
92
  - lib/ezid/responses/get_identifier_metadata_response.rb
@@ -101,6 +103,7 @@ files:
101
103
  - spec/integration/client_spec.rb
102
104
  - spec/integration/identifier_spec.rb
103
105
  - spec/spec_helper.rb
106
+ - spec/unit/batch_download_request_spec.rb
104
107
  - spec/unit/client_spec.rb
105
108
  - spec/unit/identifier_spec.rb
106
109
  - spec/unit/metadata_spec.rb
@@ -132,6 +135,7 @@ test_files:
132
135
  - spec/integration/client_spec.rb
133
136
  - spec/integration/identifier_spec.rb
134
137
  - spec/spec_helper.rb
138
+ - spec/unit/batch_download_request_spec.rb
135
139
  - spec/unit/client_spec.rb
136
140
  - spec/unit/identifier_spec.rb
137
141
  - spec/unit/metadata_spec.rb