rubydora 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.textile CHANGED
@@ -1,3 +1,11 @@
1
+ h3. 0.5.4
2
+ * Query Benchmarking
3
+ * Custom exception classes
4
+
5
+ h3. 0.5.3
6
+ * Issue 11, cast versionable strings to boolean
7
+ * Allow versionable to be set to false
8
+
1
9
  h3. 0.5.2
2
10
  * Force checksum query when you call dsChecksumValid, unless it's already in the profile.
3
11
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.3
1
+ 0.5.4
@@ -6,6 +6,7 @@ module Rubydora
6
6
  module RestApiClient
7
7
 
8
8
  include Rubydora::FedoraUrlHelpers
9
+ include ActiveSupport::Benchmarkable
9
10
 
10
11
  VALID_CLIENT_OPTIONS = [:user, :password, :timeout, :open_timeout, :ssl_client_cert, :ssl_client_key]
11
12
  # Create an authorized HTTP client for the Fedora REST API
@@ -38,10 +39,10 @@ module Rubydora
38
39
  options[:format] ||= 'xml'
39
40
  begin
40
41
  return client[next_pid_url(options)].post nil
41
- rescue => e
42
+ rescue RestClient::InternalServerError => e
42
43
  logger.error e.response
43
44
  logger.flush if logger.respond_to? :flush
44
- raise "Error getting nextPID. See logger for details"
45
+ raise FedoraInvalidRequest, "Error getting nextPID. See logger for details"
45
46
  end
46
47
  end
47
48
 
@@ -49,7 +50,7 @@ module Rubydora
49
50
  # @param [Hash] options
50
51
  # @return [String]
51
52
  def find_objects options = {}, &block_response
52
- raise "" if options[:terms] and options[:query]
53
+ raise ArgumentError,"Cannot have both :terms and :query parameters" if options[:terms] and options[:query]
53
54
  options[:resultFormat] ||= 'xml'
54
55
 
55
56
  begin
@@ -58,10 +59,10 @@ module Rubydora
58
59
  resource.options[:block_response] = block_response
59
60
  end
60
61
  return resource.get
61
- rescue => e
62
+ rescue RestClient::InternalServerError => e
62
63
  logger.error e.response
63
64
  logger.flush if logger.respond_to? :flush
64
- raise "Error finding objects. See logger for details"
65
+ raise FedoraInvalidRequest, "Error finding objects. See logger for details"
65
66
  end
66
67
  end
67
68
 
@@ -76,10 +77,10 @@ module Rubydora
76
77
  return client[object_url(pid, options)].get
77
78
  rescue RestClient::ResourceNotFound => e
78
79
  raise e
79
- rescue => e
80
+ rescue RestClient::InternalServerError => e
80
81
  logger.error e.response
81
82
  logger.flush if logger.respond_to? :flush
82
- raise "Error getting object #{pid}. See logger for details"
83
+ raise FedoraInvalidRequest, "Error getting object #{pid}. See logger for details"
83
84
  end
84
85
  end
85
86
 
@@ -92,10 +93,13 @@ module Rubydora
92
93
  file = options.delete(:file)
93
94
  begin
94
95
  return client[object_url(pid, options)].post file, :content_type => 'text/xml'
95
- rescue => e
96
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e
97
+ logger.error "Unable to connect to Fedora at #{@client.url}"
98
+ raise e
99
+ rescue RestClient::InternalServerError => e
96
100
  logger.error e.response
97
101
  logger.flush if logger.respond_to? :flush
98
- raise "Error ingesting object #{pid}. See logger for details"
102
+ raise FedoraInvalidRequest, "Error ingesting object #{pid}. See logger for details"
99
103
  end
100
104
  end
101
105
 
@@ -107,9 +111,9 @@ module Rubydora
107
111
  pid = options.delete(:pid)
108
112
  begin
109
113
  return client[export_object_url(pid, options)].get
110
- rescue => e
114
+ rescue RestClient::InternalServerError => e
111
115
  logger.error e.response
112
- raise "Error exporting object #{pid}. See logger for details"
116
+ raise FedoraInvalidRequest, "Error exporting object #{pid}. See logger for details"
113
117
  end
114
118
  end
115
119
 
@@ -121,10 +125,10 @@ module Rubydora
121
125
  pid = options.delete(:pid)
122
126
  begin
123
127
  return client[object_url(pid, options)].put nil
124
- rescue => e
128
+ rescue RestClient::InternalServerError => e
125
129
  logger.error e.response
126
130
  logger.flush if logger.respond_to? :flush
127
- raise "Error modifying object #{pid}. See logger for details"
131
+ raise FedoraInvalidRequest, "Error modifying object #{pid}. See logger for details"
128
132
  end
129
133
  end
130
134
 
@@ -138,10 +142,10 @@ module Rubydora
138
142
  return client[object_url(pid, options)].delete
139
143
  rescue RestClient::ResourceNotFound => e
140
144
  raise e
141
- rescue => e
145
+ rescue RestClient::InternalServerError => e
142
146
  logger.error e.response
143
147
  logger.flush if logger.respond_to? :flush
144
- raise "Error purging object #{pid}. See logger for details"
148
+ raise FedoraInvalidRequest, "Error purging object #{pid}. See logger for details"
145
149
  end
146
150
  end
147
151
 
@@ -152,13 +156,13 @@ module Rubydora
152
156
  def object_versions options = {}
153
157
  pid = options.delete(:pid)
154
158
  options[:format] ||= 'xml'
155
- raise "" unless pid
159
+ raise ArgumentError, "Must have a pid" unless pid
156
160
  begin
157
161
  return client[object_versions_url(pid, options)].get
158
- rescue => e
162
+ rescue RestClient::InternalServerError => e
159
163
  logger.error e.response
160
164
  logger.flush if logger.respond_to? :flush
161
- raise "Error getting versions for object #{pid}. See logger for details"
165
+ raise FedoraInvalidRequest, "Error getting versions for object #{pid}. See logger for details"
162
166
  end
163
167
  end
164
168
 
@@ -168,14 +172,14 @@ module Rubydora
168
172
  # @return [String]
169
173
  def object_xml options = {}
170
174
  pid = options.delete(:pid)
171
- raise "" unless pid
175
+ raise ArgumentError, "Missing required parameter :pid" unless pid
172
176
  options[:format] ||= 'xml'
173
177
  begin
174
178
  return client[object_xml_url(pid, options)].get
175
- rescue => e
179
+ rescue RestClient::InternalServerError => e
176
180
  logger.error e.response
177
181
  logger.flush if logger.respond_to? :flush
178
- raise "Error getting objectXML for object #{pid}. See logger for details"
182
+ raise FedoraInvalidRequest, "Error getting objectXML for object #{pid}. See logger for details"
179
183
  end
180
184
  end
181
185
 
@@ -191,13 +195,21 @@ module Rubydora
191
195
  dsid = options.delete(:dsid)
192
196
  options[:format] ||= 'xml'
193
197
  begin
194
- return client[datastream_url(pid, dsid, options)].get
198
+ val = nil
199
+ message = dsid.nil? ? "Loaded datastream list for #{pid}" : "Loaded datastream #{pid}/#{dsid}"
200
+ benchmark message, :level=>:debug do
201
+ val = client[datastream_url(pid, dsid, options)].get
202
+ end
203
+ return val
204
+ rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH => e
205
+ logger.error "Unable to connect to Fedora at #{@client.url}"
206
+ raise e
195
207
  rescue RestClient::ResourceNotFound => e
196
208
  raise e
197
- rescue => e
209
+ rescue RestClient::InternalServerError => e
198
210
  logger.error e.response
199
211
  logger.flush if logger.respond_to? :flush
200
- raise "Error getting datastream '#{dsid}' for object #{pid}. See logger for details"
212
+ raise FedoraInvalidRequest, "Error getting datastream '#{dsid}' for object #{pid}. See logger for details"
201
213
  end
202
214
  end
203
215
 
@@ -213,10 +225,10 @@ module Rubydora
213
225
  dsid = options.delete(:dsid)
214
226
  begin
215
227
  return client[datastream_url(pid, dsid, options)].put nil
216
- rescue => e
228
+ rescue RestClient::InternalServerError => e
217
229
  logger.error e.response
218
230
  logger.flush if logger.respond_to? :flush
219
- raise "Error setting datastream options on #{dsid} for object #{pid}. See logger for details"
231
+ raise FedoraInvalidRequest, "Error setting datastream options on #{dsid} for object #{pid}. See logger for details"
220
232
  end
221
233
  end
222
234
 
@@ -235,11 +247,10 @@ module Rubydora
235
247
  rescue RestClient::ResourceNotFound => e
236
248
  #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
237
249
  return nil
238
- rescue => e
239
- raise e
250
+ rescue RestClient::InternalServerError => e
240
251
  logger.error e.response
241
252
  logger.flush if logger.respond_to? :flush
242
- raise "Error getting versions for datastream #{dsid} for object #{pid}. See logger for details"
253
+ raise FedoraInvalidRequest, "Error getting versions for datastream #{dsid} for object #{pid}. See logger for details"
243
254
  end
244
255
  end
245
256
 
@@ -264,10 +275,10 @@ raise e
264
275
  return resource.send(method)
265
276
  rescue RestClient::ResourceNotFound => e
266
277
  raise e
267
- rescue => e
278
+ rescue RestClient::InternalServerError => e
268
279
  logger.error e.response
269
280
  logger.flush if logger.respond_to? :flush
270
- raise "Error getting dissemination for datastream #{dsid} for object #{pid}. See logger for details"
281
+ raise FedoraInvalidRequest, "Error getting dissemination for datastream #{dsid} for object #{pid}. See logger for details"
271
282
  end
272
283
  end
273
284
 
@@ -283,10 +294,10 @@ raise e
283
294
  content_type = options.delete(:content_type) || options[:mimeType] || (MIME::Types.type_for(file.path).first if file.respond_to? :path) || 'application/octet-stream'
284
295
  begin
285
296
  return client[datastream_url(pid, dsid, options)].post file, :content_type => content_type.to_s, :multipart => true
286
- rescue => e
297
+ rescue RestClient::InternalServerError => e
287
298
  logger.error e.response
288
299
  logger.flush if logger.respond_to? :flush
289
- raise "Error adding datastream #{dsid} for object #{pid}. See logger for details"
300
+ raise FedoraInvalidRequest, "Error adding datastream #{dsid} for object #{pid}. See logger for details"
290
301
  end
291
302
  end
292
303
 
@@ -309,10 +320,10 @@ raise e
309
320
 
310
321
  begin
311
322
  return client[datastream_url(pid, dsid, options)].put(file, rest_client_options)
312
- rescue => e
323
+ rescue RestClient::InternalServerError => e
313
324
  logger.error e.response
314
325
  logger.flush if logger.respond_to? :flush
315
- raise "Error modifying datastream #{dsid} for #{pid}. See logger for details"
326
+ raise FedoraInvalidRequest, "Error modifying datastream #{dsid} for #{pid}. See logger for details"
316
327
  end
317
328
  end
318
329
 
@@ -326,10 +337,10 @@ raise e
326
337
  dsid = options.delete(:dsid)
327
338
  begin
328
339
  client[datastream_url(pid, dsid, options)].delete
329
- rescue => e
340
+ rescue RestClient::InternalServerError => e
330
341
  logger.error e.response
331
342
  logger.flush if logger.respond_to? :flush
332
- raise "Error purging datastream #{dsid} for #{pid}. See logger for details"
343
+ raise FedoraInvalidRequest, "Error purging datastream #{dsid} for #{pid}. See logger for details"
333
344
  end
334
345
  end
335
346
 
@@ -339,14 +350,14 @@ raise e
339
350
  # @return [String]
340
351
  def relationships options = {}
341
352
  pid = options.delete(:pid) || options[:subject]
342
- raise "" unless pid
353
+ raise ArgumentError, "Missing required parameter :pid" unless pid
343
354
  options[:format] ||= 'xml'
344
355
  begin
345
356
  return client[object_relationship_url(pid, options)].get
346
- rescue => e
357
+ rescue RestClient::InternalServerError => e
347
358
  logger.error e.response
348
359
  logger.flush if logger.respond_to? :flush
349
- raise "Error getting relationships for #{pid}. See logger for details"
360
+ raise FedoraInvalidRequest, "Error getting relationships for #{pid}. See logger for details"
350
361
  end
351
362
  end
352
363
 
@@ -358,10 +369,10 @@ raise e
358
369
  pid = options.delete(:pid) || options[:subject]
359
370
  begin
360
371
  return client[new_object_relationship_url(pid, options)].post nil
361
- rescue => e
372
+ rescue RestClient::InternalServerError => e
362
373
  logger.error e.response
363
374
  logger.flush if logger.respond_to? :flush
364
- raise "Error adding relationship for #{pid}. See logger for details"
375
+ raise FedoraInvalidRequest, "Error adding relationship for #{pid}. See logger for details"
365
376
  end
366
377
  end
367
378
 
@@ -373,10 +384,10 @@ raise e
373
384
  pid = options.delete(:pid) || options[:subject]
374
385
  begin
375
386
  return client[object_relationship_url(pid, options)].delete
376
- rescue => e
387
+ rescue RestClient::InternalServerError => e
377
388
  logger.error e.response
378
389
  logger.flush if logger.respond_to? :flush
379
- raise "Error purging relationships for #{pid}. See logger for details"
390
+ raise FedoraInvalidRequest, "Error purging relationships for #{pid}. See logger for details"
380
391
  end
381
392
  end
382
393
 
@@ -397,10 +408,10 @@ raise e
397
408
  resource.options[:block_response] = block_response
398
409
  end
399
410
  return resource.get
400
- rescue => e
411
+ rescue RestClient::InternalServerError => e
401
412
  logger.error e.response
402
413
  logger.flush if logger.respond_to? :flush
403
- raise "Error getting dissemination for #{pid}. See logger for details"
414
+ raise FedoraInvalidRequest, "Error getting dissemination for #{pid}. See logger for details"
404
415
  end
405
416
  end
406
417
  end
data/lib/rubydora.rb CHANGED
@@ -54,4 +54,10 @@ module Rubydora
54
54
  {:validateChecksum=>false}
55
55
  end
56
56
 
57
+ class RubydoraError < StandardError
58
+ end
59
+
60
+ class FedoraInvalidRequest < RubydoraError
61
+ end
62
+
57
63
  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.5.3
4
+ version: 0.5.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-27 00:00:00.000000000 Z
12
+ date: 2012-03-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fastercsv
16
- requirement: &70207867601020 !ruby/object:Gem::Requirement
16
+ requirement: &70336833980200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70207867601020
24
+ version_requirements: *70336833980200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &70207867611180 !ruby/object:Gem::Requirement
27
+ requirement: &70336833973900 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70207867611180
35
+ version_requirements: *70336833973900
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &70207867610600 !ruby/object:Gem::Requirement
38
+ requirement: &70336833994120 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70207867610600
46
+ version_requirements: *70336833994120
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: mime-types
49
- requirement: &70207867609920 !ruby/object:Gem::Requirement
49
+ requirement: &70336833991880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70207867609920
57
+ version_requirements: *70336833991880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activesupport
60
- requirement: &70207867609280 !ruby/object:Gem::Requirement
60
+ requirement: &70336833989860 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70207867609280
68
+ version_requirements: *70336833989860
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activemodel
71
- requirement: &70207867607060 !ruby/object:Gem::Requirement
71
+ requirement: &70336833987740 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *70207867607060
79
+ version_requirements: *70336833987740
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: savon
82
- requirement: &70207867604800 !ruby/object:Gem::Requirement
82
+ requirement: &70336834009180 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *70207867604800
90
+ version_requirements: *70336834009180
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rake
93
- requirement: &70207867631520 !ruby/object:Gem::Requirement
93
+ requirement: &70336834008120 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70207867631520
101
+ version_requirements: *70336834008120
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: shoulda
104
- requirement: &70207867628840 !ruby/object:Gem::Requirement
104
+ requirement: &70336834006880 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70207867628840
112
+ version_requirements: *70336834006880
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: bundler
115
- requirement: &70207867644580 !ruby/object:Gem::Requirement
115
+ requirement: &70336834005220 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 1.0.14
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70207867644580
123
+ version_requirements: *70336834005220
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rspec
126
- requirement: &70207867643500 !ruby/object:Gem::Requirement
126
+ requirement: &70336834001740 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70207867643500
134
+ version_requirements: *70336834001740
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: yard
137
- requirement: &70207867642360 !ruby/object:Gem::Requirement
137
+ requirement: &70336834022680 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70207867642360
145
+ version_requirements: *70336834022680
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: jettywrapper
148
- requirement: &70207867637120 !ruby/object:Gem::Requirement
148
+ requirement: &70336834021440 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,7 +153,7 @@ dependencies:
153
153
  version: '0'
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *70207867637120
156
+ version_requirements: *70336834021440
157
157
  description: ! 'Fedora Commons REST API ruby library : REQUIRES FCREPO 3.4+'
158
158
  email:
159
159
  - chris@cbeer.info
@@ -213,7 +213,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
213
213
  version: '0'
214
214
  segments:
215
215
  - 0
216
- hash: 4404235495484812155
216
+ hash: -1588477717339381900
217
217
  required_rubygems_version: !ruby/object:Gem::Requirement
218
218
  none: false
219
219
  requirements:
@@ -222,10 +222,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  version: '0'
223
223
  segments:
224
224
  - 0
225
- hash: 4404235495484812155
225
+ hash: -1588477717339381900
226
226
  requirements: []
227
227
  rubyforge_project:
228
- rubygems_version: 1.8.15
228
+ rubygems_version: 1.8.17
229
229
  signing_key:
230
230
  specification_version: 3
231
231
  summary: Fedora Commons REST API ruby library