rubydora 0.5.11 → 0.5.12
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.
- data/VERSION +1 -1
- data/lib/rubydora/rest_api_client.rb +87 -68
- data/lib/rubydora/transactions.rb +5 -0
- data/lib/rubydora.rb +1 -0
- data/spec/lib/transactions_spec.rb +20 -1
- metadata +7 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.12
|
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'active_support/core_ext/hash/indifferent_access'
|
2
2
|
require 'active_support/core_ext/class'
|
3
3
|
require 'active_support/core_ext/module'
|
4
|
-
require 'hooks'
|
5
4
|
|
6
5
|
module Rubydora
|
7
6
|
|
@@ -64,8 +63,9 @@ module Rubydora
|
|
64
63
|
# @param [Hash] options
|
65
64
|
# @return [String]
|
66
65
|
def next_pid options = {}
|
67
|
-
|
68
|
-
|
66
|
+
query_options = options.dup
|
67
|
+
query_options[:format] ||= 'xml'
|
68
|
+
client[next_pid_url(query_options)].post nil
|
69
69
|
rescue Exception => exception
|
70
70
|
rescue_with_handler(exception) || raise
|
71
71
|
end
|
@@ -74,12 +74,13 @@ module Rubydora
|
|
74
74
|
# @param [Hash] options
|
75
75
|
# @return [String]
|
76
76
|
def find_objects options = {}, &block_response
|
77
|
-
|
78
|
-
|
77
|
+
query_options = options.dup
|
78
|
+
raise ArgumentError,"Cannot have both :terms and :query parameters" if query_options[:terms] and query_options[:query]
|
79
|
+
query_options[:resultFormat] ||= 'xml'
|
79
80
|
|
80
|
-
resource = client[find_objects_url(
|
81
|
+
resource = client[find_objects_url(query_options)]
|
81
82
|
if block_given?
|
82
|
-
resource.
|
83
|
+
resource.query_options[:block_response] = block_response
|
83
84
|
end
|
84
85
|
return resource.get
|
85
86
|
rescue Exception => exception
|
@@ -91,9 +92,10 @@ module Rubydora
|
|
91
92
|
# @option options [String] :pid
|
92
93
|
# @return [String]
|
93
94
|
def object options = {}
|
94
|
-
|
95
|
-
|
96
|
-
|
95
|
+
query_options = options.dup
|
96
|
+
pid = query_options.delete(:pid)
|
97
|
+
query_options[:format] ||= 'xml'
|
98
|
+
client[object_url(pid, query_options)].get
|
97
99
|
rescue Exception => exception
|
98
100
|
rescue_with_handler(exception) || raise
|
99
101
|
end
|
@@ -103,9 +105,10 @@ module Rubydora
|
|
103
105
|
# @option options [String] :pid
|
104
106
|
# @return [String]
|
105
107
|
def ingest options = {}
|
106
|
-
|
107
|
-
|
108
|
-
|
108
|
+
query_options = options.dup
|
109
|
+
pid = query_options.delete(:pid) || 'new'
|
110
|
+
file = query_options.delete(:file)
|
111
|
+
assigned_pid = client[object_url(pid, query_options)].post file, :content_type => 'text/xml'
|
109
112
|
run_hook :after_ingest, :pid => assigned_pid, :file => file, :options => options
|
110
113
|
assigned_pid
|
111
114
|
rescue Exception => exception
|
@@ -117,8 +120,9 @@ module Rubydora
|
|
117
120
|
# @option options [String] :pid
|
118
121
|
# @return [String]
|
119
122
|
def export options = {}
|
120
|
-
|
121
|
-
|
123
|
+
query_options = options.dup
|
124
|
+
pid = query_options.delete(:pid)
|
125
|
+
client[export_object_url(pid, query_options)].get
|
122
126
|
rescue Exception => exception
|
123
127
|
rescue_with_handler(exception) || raise
|
124
128
|
end
|
@@ -128,9 +132,10 @@ module Rubydora
|
|
128
132
|
# @option options [String] :pid
|
129
133
|
# @return [String]
|
130
134
|
def modify_object options = {}
|
131
|
-
|
135
|
+
query_options = options.dup
|
136
|
+
pid = query_options.delete(:pid)
|
132
137
|
run_hook :before_modify_object, :pid => pid, :options => options
|
133
|
-
client[object_url(pid,
|
138
|
+
client[object_url(pid, query_options)].put nil
|
134
139
|
rescue Exception => exception
|
135
140
|
rescue_with_handler(exception) || raise
|
136
141
|
end
|
@@ -140,9 +145,10 @@ module Rubydora
|
|
140
145
|
# @option options [String] :pid
|
141
146
|
# @return [String]
|
142
147
|
def purge_object options = {}
|
143
|
-
|
148
|
+
query_options = options.dup
|
149
|
+
pid = query_options.delete(:pid)
|
144
150
|
run_hook :before_purge_object, :pid => pid, :options => options
|
145
|
-
client[object_url(pid,
|
151
|
+
client[object_url(pid, query_options)].delete
|
146
152
|
rescue Exception => exception
|
147
153
|
rescue_with_handler(exception) || raise
|
148
154
|
end
|
@@ -152,10 +158,11 @@ module Rubydora
|
|
152
158
|
# @option options [String] :pid
|
153
159
|
# @return [String]
|
154
160
|
def object_versions options = {}
|
155
|
-
|
156
|
-
|
161
|
+
query_options = options.dup
|
162
|
+
pid = query_options.delete(:pid)
|
163
|
+
query_options[:format] ||= 'xml'
|
157
164
|
raise ArgumentError, "Must have a pid" unless pid
|
158
|
-
client[object_versions_url(pid,
|
165
|
+
client[object_versions_url(pid, query_options)].get
|
159
166
|
rescue Exception => exception
|
160
167
|
rescue_with_handler(exception) || raise
|
161
168
|
end
|
@@ -165,10 +172,11 @@ module Rubydora
|
|
165
172
|
# @option options [String] :pid
|
166
173
|
# @return [String]
|
167
174
|
def object_xml options = {}
|
168
|
-
|
175
|
+
query_options = options.dup
|
176
|
+
pid = query_options.delete(:pid)
|
169
177
|
raise ArgumentError, "Missing required parameter :pid" unless pid
|
170
|
-
|
171
|
-
client[object_xml_url(pid,
|
178
|
+
query_options[:format] ||= 'xml'
|
179
|
+
client[object_xml_url(pid, query_options)].get
|
172
180
|
rescue Exception => exception
|
173
181
|
rescue_with_handler(exception) || raise
|
174
182
|
end
|
@@ -181,18 +189,19 @@ module Rubydora
|
|
181
189
|
# @option options [String] :validateChecksum
|
182
190
|
# @return [String]
|
183
191
|
def datastream options = {}
|
184
|
-
|
185
|
-
|
186
|
-
|
192
|
+
query_options = options.dup
|
193
|
+
pid = query_options.delete(:pid)
|
194
|
+
dsid = query_options.delete(:dsid)
|
195
|
+
query_options[:format] ||= 'xml'
|
187
196
|
val = nil
|
188
197
|
message = dsid.nil? ? "Loaded datastream list for #{pid}" : "Loaded datastream #{pid}/#{dsid}"
|
189
198
|
benchmark message, :level=>:debug do
|
190
|
-
val = client[datastream_url(pid, dsid,
|
199
|
+
val = client[datastream_url(pid, dsid, query_options)].get
|
191
200
|
end
|
192
201
|
|
193
202
|
val
|
194
203
|
rescue RestClient::Unauthorized => e
|
195
|
-
logger.error "Unauthorized at #{client.url}/#{datastream_url(pid, dsid,
|
204
|
+
logger.error "Unauthorized at #{client.url}/#{datastream_url(pid, dsid, query_options)}"
|
196
205
|
raise e
|
197
206
|
rescue Exception => exception
|
198
207
|
rescue_with_handler(exception) || raise
|
@@ -206,10 +215,11 @@ module Rubydora
|
|
206
215
|
# @option options [String] :dsid
|
207
216
|
# @return [String]
|
208
217
|
def set_datastream_options options = {}
|
209
|
-
|
210
|
-
|
218
|
+
query_options = options.dup
|
219
|
+
pid = query_options.delete(:pid)
|
220
|
+
dsid = query_options.delete(:dsid)
|
211
221
|
run_hook :before_set_datastream_options, :pid => pid, :dsid => dsid, :options => options
|
212
|
-
client[datastream_url(pid, dsid,
|
222
|
+
client[datastream_url(pid, dsid, query_options)].put nil
|
213
223
|
rescue Exception => exception
|
214
224
|
rescue_with_handler(exception) || raise
|
215
225
|
end
|
@@ -220,11 +230,12 @@ module Rubydora
|
|
220
230
|
# @option options [String] :dsid
|
221
231
|
# @return [String]
|
222
232
|
def datastream_versions options = {}
|
223
|
-
|
224
|
-
|
233
|
+
query_options = options.dup
|
234
|
+
pid = query_options.delete(:pid)
|
235
|
+
dsid = query_options.delete(:dsid)
|
225
236
|
raise ArgumentError, "Must supply dsid" unless dsid
|
226
|
-
|
227
|
-
client[datastream_history_url(pid, dsid,
|
237
|
+
query_options[:format] ||= 'xml'
|
238
|
+
client[datastream_history_url(pid, dsid, query_options)].get
|
228
239
|
rescue RestClient::ResourceNotFound => e
|
229
240
|
#404 Resource Not Found: No datastream history could be found. There is no datastream history for the digital object "changeme:1" with datastream ID of "descMetadata
|
230
241
|
return nil
|
@@ -240,15 +251,16 @@ module Rubydora
|
|
240
251
|
# @option options [String] :dsid
|
241
252
|
# @return [String]
|
242
253
|
def datastream_dissemination options = {}, &block_response
|
243
|
-
|
244
|
-
|
245
|
-
|
254
|
+
query_options = options.dup
|
255
|
+
pid = query_options.delete(:pid)
|
256
|
+
dsid = query_options.delete(:dsid)
|
257
|
+
method = query_options.delete(:method)
|
246
258
|
method ||= :get
|
247
259
|
raise self.class.name + "#datastream_dissemination requires a DSID" unless dsid
|
248
260
|
if block_given?
|
249
|
-
resource = safe_subresource(datastream_content_url(pid, dsid,
|
261
|
+
resource = safe_subresource(datastream_content_url(pid, dsid, query_options), :block_response => block_response)
|
250
262
|
else
|
251
|
-
resource = client[datastream_content_url(pid, dsid,
|
263
|
+
resource = client[datastream_content_url(pid, dsid, query_options)]
|
252
264
|
end
|
253
265
|
resource.send(method)
|
254
266
|
rescue Exception => exception
|
@@ -261,12 +273,13 @@ module Rubydora
|
|
261
273
|
# @option options [String] :dsid
|
262
274
|
# @return [String]
|
263
275
|
def add_datastream options = {}
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
276
|
+
query_options = options.dup
|
277
|
+
pid = query_options.delete(:pid)
|
278
|
+
dsid = query_options.delete(:dsid)
|
279
|
+
file = query_options.delete(:content)
|
280
|
+
content_type = query_options.delete(:content_type) || query_options[:mimeType] || (MIME::Types.type_for(file.path).first if file.respond_to? :path) || 'application/octet-stream'
|
268
281
|
run_hook :before_add_datastream, :pid => pid, :dsid => dsid, :file => file, :options => options
|
269
|
-
client[datastream_url(pid, dsid,
|
282
|
+
client[datastream_url(pid, dsid, query_options)].post file, :content_type => content_type.to_s, :multipart => true
|
270
283
|
rescue Exception => exception
|
271
284
|
rescue_with_handler(exception) || raise
|
272
285
|
end
|
@@ -277,10 +290,11 @@ module Rubydora
|
|
277
290
|
# @option options [String] :dsid
|
278
291
|
# @return [String]
|
279
292
|
def modify_datastream options = {}
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
293
|
+
query_options = options.dup
|
294
|
+
pid = query_options.delete(:pid)
|
295
|
+
dsid = query_options.delete(:dsid)
|
296
|
+
file = query_options.delete(:content)
|
297
|
+
content_type = query_options.delete(:content_type) || query_options[:mimeType] || (MIME::Types.type_for(file.path).first if file.respond_to? :path) || 'application/octet-stream'
|
284
298
|
|
285
299
|
rest_client_options = {}
|
286
300
|
if file
|
@@ -289,7 +303,7 @@ module Rubydora
|
|
289
303
|
end
|
290
304
|
|
291
305
|
run_hook :before_modify_datastream, :pid => pid, :dsid => dsid, :file => file, :content_type => content_type, :options => options
|
292
|
-
client[datastream_url(pid, dsid,
|
306
|
+
client[datastream_url(pid, dsid, query_options)].put(file, rest_client_options)
|
293
307
|
|
294
308
|
rescue Exception => exception
|
295
309
|
rescue_with_handler(exception) || raise
|
@@ -301,10 +315,11 @@ module Rubydora
|
|
301
315
|
# @option options [String] :dsid
|
302
316
|
# @return [String]
|
303
317
|
def purge_datastream options = {}
|
304
|
-
|
305
|
-
|
318
|
+
query_options = options.dup
|
319
|
+
pid = query_options.delete(:pid)
|
320
|
+
dsid = query_options.delete(:dsid)
|
306
321
|
run_hook :before_purge_datastream, :pid => pid, :dsid => dsid
|
307
|
-
client[datastream_url(pid, dsid,
|
322
|
+
client[datastream_url(pid, dsid, query_options)].delete
|
308
323
|
rescue Exception => exception
|
309
324
|
rescue_with_handler(exception) || raise
|
310
325
|
end
|
@@ -314,10 +329,11 @@ module Rubydora
|
|
314
329
|
# @option options [String] :pid
|
315
330
|
# @return [String]
|
316
331
|
def relationships options = {}
|
317
|
-
|
332
|
+
query_options = options.dup
|
333
|
+
pid = query_options.delete(:pid) || query_options[:subject]
|
318
334
|
raise ArgumentError, "Missing required parameter :pid" unless pid
|
319
|
-
|
320
|
-
client[object_relationship_url(pid,
|
335
|
+
query_options[:format] ||= 'xml'
|
336
|
+
client[object_relationship_url(pid, query_options)].get
|
321
337
|
rescue Exception => exception
|
322
338
|
rescue_with_handler(exception) || raise
|
323
339
|
end
|
@@ -327,9 +343,10 @@ module Rubydora
|
|
327
343
|
# @option options [String] :pid
|
328
344
|
# @return [String]
|
329
345
|
def add_relationship options = {}
|
330
|
-
|
346
|
+
query_options = options.dup
|
347
|
+
pid = query_options.delete(:pid) || query_options[:subject]
|
331
348
|
run_hook :before_add_relationship, :pid => pid, :options => options
|
332
|
-
client[new_object_relationship_url(pid,
|
349
|
+
client[new_object_relationship_url(pid, query_options)].post nil
|
333
350
|
rescue Exception => exception
|
334
351
|
rescue_with_handler(exception) || raise
|
335
352
|
end
|
@@ -339,9 +356,10 @@ module Rubydora
|
|
339
356
|
# @option options [String] :pid
|
340
357
|
# @return [String]
|
341
358
|
def purge_relationship options = {}
|
342
|
-
|
359
|
+
query_options = options.dup
|
360
|
+
pid = query_options.delete(:pid) || query_options[:subject]
|
343
361
|
run_hook :before_purge_relationship, :pid => pid, :options => options
|
344
|
-
client[object_relationship_url(pid,
|
362
|
+
client[object_relationship_url(pid, query_options)].delete
|
345
363
|
rescue Exception => exception
|
346
364
|
rescue_with_handler(exception) || raise
|
347
365
|
end
|
@@ -353,14 +371,15 @@ module Rubydora
|
|
353
371
|
# @option options [String] :method
|
354
372
|
# @return [String]
|
355
373
|
def dissemination options = {}, &block_response
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
374
|
+
query_options = options.dup
|
375
|
+
pid = query_options.delete(:pid)
|
376
|
+
sdef = query_options.delete(:sdef)
|
377
|
+
method = query_options.delete(:method)
|
378
|
+
query_options[:format] ||= 'xml' unless pid and sdef and method
|
360
379
|
if block_given?
|
361
|
-
resource = safe_subresource(dissemination_url(pid,sdef,method,
|
380
|
+
resource = safe_subresource(dissemination_url(pid,sdef,method,query_options), :block_response => block_response)
|
362
381
|
else
|
363
|
-
resource = client[dissemination_url(pid,sdef,method,
|
382
|
+
resource = client[dissemination_url(pid,sdef,method,query_options)]
|
364
383
|
end
|
365
384
|
resource.get
|
366
385
|
|
@@ -85,6 +85,9 @@ module Rubydora
|
|
85
85
|
|
86
86
|
class Transaction
|
87
87
|
attr_reader :repository
|
88
|
+
include Hooks
|
89
|
+
define_hook "after_rollback"
|
90
|
+
|
88
91
|
def initialize repository, &block
|
89
92
|
@repository = repository
|
90
93
|
with_transactions(&block)
|
@@ -150,6 +153,8 @@ module Rubydora
|
|
150
153
|
# no-op
|
151
154
|
end
|
152
155
|
|
156
|
+
run_hook :after_rollback, :pid => options[:pid], :method => method, :options => options
|
157
|
+
|
153
158
|
end
|
154
159
|
end
|
155
160
|
true
|
data/lib/rubydora.rb
CHANGED
@@ -8,8 +8,27 @@ describe Rubydora::Transactions do
|
|
8
8
|
repository = Rubydora::Repository.new :url => 'http://example.org'
|
9
9
|
}
|
10
10
|
|
11
|
-
|
12
11
|
describe "#rollback" do
|
12
|
+
|
13
|
+
it "should fire a after_rollback hook" do
|
14
|
+
i = 0
|
15
|
+
Rubydora::Transaction.after_rollback do
|
16
|
+
i+=1
|
17
|
+
end
|
18
|
+
|
19
|
+
subject.transaction do |t|
|
20
|
+
subject.append_to_transactions_log :asdf, :pid => 'asdf'
|
21
|
+
subject.append_to_transactions_log :asdf, :pid => 'asdf'
|
22
|
+
subject.append_to_transactions_log :asdf, :pid => 'asdf'
|
23
|
+
subject.append_to_transactions_log :asdf, :pid => 'asdf'
|
24
|
+
subject.append_to_transactions_log :asdf, :pid => 'asdf'
|
25
|
+
subject.append_to_transactions_log :asdf, :pid => 'asdf'
|
26
|
+
t.rollback
|
27
|
+
end
|
28
|
+
|
29
|
+
i.should == 6
|
30
|
+
end
|
31
|
+
|
13
32
|
it "ingest" do
|
14
33
|
subject.client.stub_chain(:[], :post).and_return 'asdf'
|
15
34
|
subject.should_receive(:purge_object).with(hash_including(:pid => 'asdf'))
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubydora
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -310,12 +310,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
310
310
|
- - ! '>='
|
311
311
|
- !ruby/object:Gem::Version
|
312
312
|
version: '0'
|
313
|
+
segments:
|
314
|
+
- 0
|
315
|
+
hash: -1776488300066485637
|
313
316
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
314
317
|
none: false
|
315
318
|
requirements:
|
316
319
|
- - ! '>='
|
317
320
|
- !ruby/object:Gem::Version
|
318
321
|
version: '0'
|
322
|
+
segments:
|
323
|
+
- 0
|
324
|
+
hash: -1776488300066485637
|
319
325
|
requirements: []
|
320
326
|
rubyforge_project:
|
321
327
|
rubygems_version: 1.8.24
|