rubydora 0.2.5 → 0.2.6

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 CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -40,12 +40,16 @@ module Rubydora
40
40
  # {include:RestApiClient::API_DOCUMENTATION}
41
41
  # @param [Hash] options
42
42
  # @return [String]
43
- def find_objects options = {}
43
+ def find_objects options = {}, &block_response
44
44
  raise "" if options[:terms] and options[:query]
45
45
  options[:resultFormat] ||= 'xml'
46
46
 
47
47
  begin
48
- return client[object_url(nil, options)].get
48
+ resource = client[object_url(nil, options)]
49
+ if block_given?
50
+ resource.options[:block_response] = block_response
51
+ end
52
+ return resource.get
49
53
  rescue => e
50
54
  logger.error e.response
51
55
  raise "Error finding objects. See logger for details"
@@ -206,12 +210,18 @@ module Rubydora
206
210
  # @option options [String] :pid
207
211
  # @option options [String] :dsid
208
212
  # @return [String]
209
- def datastream_dissemination options = {}
213
+ def datastream_dissemination options = {}, &block_response
210
214
  pid = options.delete(:pid)
211
215
  dsid = options.delete(:dsid)
212
- raise "" unless dsid
216
+ method = options.delete(:method)
217
+ method ||= :get
218
+ raise self.class.name + "#datastream_dissemination requires a DSID" unless dsid
213
219
  begin
214
- return client[url_for(datastream_url(pid, dsid) + "/content", options)].get
220
+ resource = client[url_for(datastream_url(pid, dsid) + "/content", options)]
221
+ if block_given?
222
+ resource.options[:block_response] = block_response
223
+ end
224
+ return resource.send(method)
215
225
  rescue RestClient::ResourceNotFound => e
216
226
  raise e
217
227
  rescue => e
@@ -329,13 +339,17 @@ module Rubydora
329
339
  # @option options [String] :sdef
330
340
  # @option options [String] :method
331
341
  # @return [String]
332
- def dissemination options = {}
342
+ def dissemination options = {}, &block_response
333
343
  pid = options.delete(:pid)
334
344
  sdef = options.delete(:sdef)
335
345
  method = options.delete(:method)
336
346
  options[:format] ||= 'xml' unless pid and sdef and method
337
347
  begin
338
- return client[dissemination_url(pid,sdef,method,options)].get
348
+ resource = client[dissemination_url(pid,sdef,method,options)]
349
+ if block_given?
350
+ resource.options[:block_response] = block_response
351
+ end
352
+ return resource.get
339
353
  rescue => e
340
354
  logger.error e.response
341
355
  raise "Error getting dissemination for #{pid}. See logger for details"
@@ -119,6 +119,15 @@ describe Rubydora::RestApiClient do
119
119
  RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa/content"))
120
120
  @mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa'
121
121
  end
122
+ it "should allow http methods besides GET on datastream_dissemination" do
123
+ RestClient::Request.should_receive(:execute).with(hash_including(:method => :head))
124
+ @mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa', :method => :head
125
+ end
126
+ it "should pass a block to the rest client to process the response in datastream_dissemination" do
127
+ _proc = lambda { |x| x }
128
+ RestClient::Request.should_receive(:execute).with(hash_including(:block_response => _proc))
129
+ @mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa', &_proc
130
+ end
122
131
  it "should raise not found exception when retrieving datastream_dissemination" do
123
132
  RestClient::Request.should_receive(:execute).with(hash_including(:url => "http://example.org/objects/mypid/datastreams/aaa/content")).and_raise( RestClient::ResourceNotFound)
124
133
  lambda {@mock_repository.datastream_dissemination :pid => 'mypid', :dsid => 'aaa'}.should raise_error RestClient::ResourceNotFound
@@ -195,4 +204,10 @@ describe Rubydora::RestApiClient do
195
204
  @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef', :method => 'method'
196
205
  end
197
206
 
207
+ it "should pass a block to the rest client to process the response in datastream_dissemination" do
208
+ _proc = lambda { |x| x }
209
+ RestClient::Request.should_receive(:execute).with(hash_including(:block_response => _proc))
210
+ @mock_repository.dissemination :pid => 'mypid', :sdef => 'sdef', :method => 'method', &_proc
211
+ end
212
+
198
213
  end
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.2.5
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -211,7 +211,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
211
211
  version: '0'
212
212
  segments:
213
213
  - 0
214
- hash: 4297992764557344518
214
+ hash: -3469536483199493796
215
215
  required_rubygems_version: !ruby/object:Gem::Requirement
216
216
  none: false
217
217
  requirements:
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  version: '0'
221
221
  segments:
222
222
  - 0
223
- hash: 4297992764557344518
223
+ hash: -3469536483199493796
224
224
  requirements: []
225
225
  rubyforge_project:
226
226
  rubygems_version: 1.8.10