Class: Atom::Entry

Inherits:
Element
  • Object
show all
Defined in:
lib/sword2ruby/entry.rb

Overview

Extensions to the atom-tools Atom::Entry class to support Sword2 operations. These methods are additive to those supplied by the atom-tools gem.

Please see the atom-tools documentation for a complete list of attributes and methods.

Instance Method Summary collapse

Instance Method Details

#add_dublin_core_extension!(name, value) ⇒ Object

This method adds a new Dublin Core element to the entry,

Parameters

name

a valid Dublin Core Term Name, e.g. “abstract”, “title” or “publisher” etc

value

the string value of the new Dublin Core element, e.g. “A report on Burritos”, “History of Burritos” or “Burrito King” etc

For more information, see the Dublin Core Metadata Terms specification.



88
89
90
91
92
93
# File 'lib/sword2ruby/entry.rb', line 88

def add_dublin_core_extension!(name, value)
  extension = REXML::Element.new(name)
  extension.add_namespace("http://purl.org/dc/terms/")
  extension.text = value
  extensions << extension
end

#alternate_uriObject

This method returns the URI string of the <link rel=“alternate”> tag (usually contained in the DepositReceipt Entry), or nil if it is not defined.



14
15
16
# File 'lib/sword2ruby/entry.rb', line 14

def alternate_uri
  Utility.find_link_uri(links, "alternate")
end

#delete!(params = {}) ⇒ Object

This method removes the container by performing a Delete on the entry-edit URI. The method will return a Sword2Ruby::DepositReceipt object, or raise a Sword2Ruby::Exception in the case of an error.

Parameters (passed as a hash collection)

:entry_edit_uri

(optional) an override to the existing entry’s entry-edit URI. If not supplied, this will default to the existing entry’s entry-edit URI.

:on_behalf_of

(optional) username on whos behalf the operation is being performed.

:connection

(optional) Sword2Ruby::Connection object used to perform the operation. If not supplied, the existing entry’s connection will be used.

Note that you should call <collection>.feed.updated! followed by <collection>.feed.update! after making updates to a collection.

For more information, see the Sword2 specification: section 6.8. “Deleting the Container”.



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/sword2ruby/entry.rb', line 537

def delete!(params = {})
  Utility.check_argument_class('params', params, Hash)
  defaults = {
    :entry_edit_uri => entry_edit_uri,
    :on_behalf_of => nil,
    :connection => @http
  }
  options = defaults.merge(params)

  #Validate parameters
  Utility.check_argument_class(':entry_edit_uri', options[:entry_edit_uri], String)
  Utility.check_argument_class(':on_behalf_of', options[:on_behalf_of], String) if options[:on_behalf_of]
  Utility.check_argument_class(':connection', options[:connection], Sword2Ruby::Connection)

  headers = {}
  headers["On-Behalf-Of"] = options[:on_behalf_of] if options[:on_behalf_of]

  response = options[:connection].delete(options[:entry_edit_uri], nil, headers)

  if response.is_a? Net::HTTPSuccess
    return DepositReceipt.new(response, options[:connection])
  else
   raise Sword2Ruby::Exception.new("Failed to do delete!(#{options[:entry_edit_uri]}): server returned #{response.code} #{response.message}")
  end
end

#delete_dublin_core_extension!(name) ⇒ Object

This method searches for the specified Dublin Core term in the entry and removes it where found.

Parameters

name

a valid Dublin Core Term Name, e.g. “isReferencedBy”, “title” or “accrualPolicy” etc

For more information, see the Dublin Core Metadata Terms specification.



100
101
102
# File 'lib/sword2ruby/entry.rb', line 100

def delete_dublin_core_extension!(name)
  extensions.delete_if {|e| e.namespace == "http://purl.org/dc/terms/" && e.name == name}
end

#delete_media!(params = {}) ⇒ Object

This method removes all the content of a resource (without removing the resource itself) by performing a Delete on the edit-media URI. The method will return a Sword2Ruby::DepositReceipt object, or raise a Sword2Ruby::Exception in the case of an error.

Parameters (passed as a hash collection)

:edit_media_uri

(optional) an override to the existing entry’s edit-media URI. If not supplied, this will default to the existing entry’s first edit-media URI.

:on_behalf_of

(optional) username on whos behalf the submission is being performed.

:connection

(optional) Sword2Ruby::Connection object used to perform the operation. If not supplied, the existing entry’s connection will be used.

Note that you should call <collection>.feed.updated! followed by <collection>.feed.update! after making updates to a collection.

For more information, see the Sword2 specification: section 6.6. “Deleting the content of a Resource”.



574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
# File 'lib/sword2ruby/entry.rb', line 574

def delete_media!(params = {})
  Utility.check_argument_class('params', params, Hash)
  defaults = {
    :edit_media_uri => edit_media_links.first.href,
    :on_behalf_of => nil,
    :connection => @http
  }
  options = defaults.merge(params)

  #Validate parameters
  Utility.check_argument_class(':edit_media_uri', options[:edit_media_uri], String)
  Utility.check_argument_class(':on_behalf_of', options[:on_behalf_of], String) if options[:on_behalf_of]
  Utility.check_argument_class(':connection', options[:connection], Sword2Ruby::Connection)

  headers = {}
  headers["On-Behalf-Of"] = options[:on_behalf_of] if options[:on_behalf_of]

  response = options[:connection].delete(options[:edit_media_uri], nil, headers)

  if response.is_a? Net::HTTPSuccess
    return DepositReceipt.new(response, options[:connection])
  else
    raise Sword2Ruby::Exception.new("Failed to do delete_media!(#{options[:edit_media_uri]}): server returned #{response.code} #{response.message}")
  end
end

#dublin_core_extensionsObject

This method returns an array of the Dublin Core elements (usually contained in the DepositReceipt Entry), or an empty array [ ] if none are defined.

For more information, see the Dublin Core Metadata Terms specification.



78
79
80
# File 'lib/sword2ruby/entry.rb', line 78

def dublin_core_extensions
  Utility.find_elements_by_namespace(extensions, "http://purl.org/dc/terms/")
end

This method returns an array of Atom::Links for the Atom Edit Media <link rel=“edit-media”> tags (usually contained in the DepositReceipt Entry), or an empty array [ ] if none are defined. They are also known as the Media Resource URIs or EM-URIs.



27
28
29
# File 'lib/sword2ruby/entry.rb', line 27

def edit_media_links #media_resource_links
  Utility.find_links_all_types(links, "edit-media")
end

#entry_edit_uriObject Also known as: media_entry_uri

This method returns the URI string of the Atom Entry Edit <link rel=“edit”> tag (usually contained in the DepositReceipt Entry), or nil if it is not defined. It is also known as the Media Entry URI or Edit-URI.



20
21
22
# File 'lib/sword2ruby/entry.rb', line 20

def entry_edit_uri #media_entry_uri
  Utility.find_link_uri(links, "edit")
end

#post!(params = {}) ⇒ Object

This method posts a new entry to an existing entry’s sword-edit URI, adding to the existing entry’s metadata (i.e. not overwriting existing metadata). It does not create a new entry in the collection. The method will return a Sword2Ruby::DepositReceipt object, or raise a Sword2Ruby::Exception in the case of an error.

Parameters (passed as a hash collection)

:entry

(optional) a new Atom::Entry with metadata to be added to an existing Atom::Entry. If not supplied, this will default to itself.

:sword_edit_uri

(optional) an override to the existing entry’s sword-edit URI. If not supplied, this will default to the existing entry’s sword-edit URI.

:in_progress

(optional) boolean value indicating whether the existing entry will be completed at a later date.

:on_behalf_of

(optional) username on whos behalf the submission is being performed.

:connection

(optional) Sword2Ruby::Connection object used to perform the operation. If not supplied, the existing entry’s connection will be used.

Note that you should call <collection>.feed.updated! followed by <collection>.feed.update! after making updates to a collection.

Example BROKEN

# feed = collection.feed # assuming that you have retrieved a collection from the service document # feed.update! # get all the entry data # existing_entry = feed.entries.first additional_entry = Atom::Entry.new() additional_entry.title = “The Improved Burrito” additional_entry.summary = “Adding some extra metadata to the existing entry” additional_entry.add_dublin_core_extension!(“publisher”, “Burrito King”) deposit_receipt = existing_entry.post!(:entry => additional_entry, :in_progress => true) feed.updated! #flag that the feed has been updated feed.update! #get the updates

For more information, see the Sword2 specification: section 6.7.2. “Adding New Metadata to a Container”.



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/sword2ruby/entry.rb', line 159

def post!(params = {})
  Utility.check_argument_class('params', params, Hash)
  defaults = {
    :entry => self,
    :sword_edit_uri => sword_edit_uri,
    :in_progress => nil,
    :on_behalf_of => nil,
    :connection => @http
  }
  options = defaults.merge(params)
 
  #Validate parameters
  Utility.check_argument_class(':entry', options[:entry], ::Atom::Entry)
  Utility.check_argument_class(':sword_edit_uri', options[:sword_edit_uri], String)
  Utility.check_argument_class(':on_behalf_of', options[:on_behalf_of], String) if options[:on_behalf_of]
  Utility.check_argument_class(':connection', options[:connection], Sword2Ruby::Connection)
        
  headers = {"Content-Type" => "application/atom+xml;type=entry" }
  headers["In-Progress"] = options[:in_progress].to_s.downcase if (options[:in_progress] == true || options[:in_progress] == false)
  headers["On-Behalf-Of"] = options[:on_behalf_of] if options[:on_behalf_of]
  response = options[:connection].post(options[:sword_edit_uri], options[:entry].to_s, headers)
  if response.is_a? Net::HTTPSuccess
    return DepositReceipt.new(response, options[:connection])
  else
    raise Sword2Ruby::Exception.new("Failed to do post!(#{options[:sword_edit_uri]}): server returned code #{response.code} #{response.message}")
  end
end

#post_media!(params = {}) ⇒ Object

This method posts a file to an existing entry’s edit-media URI, adding to the existing entry’s media resources (i.e. not overwriting existing media resources). It does not create a new entry in the collection. An MD5-digest will be calculated automatically from the file and sent to the server with the request. The method will return a Sword2Ruby::DepositReceipt object, or raise a Sword2Ruby::Exception in the case of an error.

Parameters (passed as a hash collection)

:filepath

a filepath string indicating the file to be posted. The file must be readable by the process.

:content_type

the mime content-type string of the file, e.g. “application/zip” or “text/plain”

:packaging

(optional) the Sword packaging string of the file, e.g. “purl.org/net/sword/package/METSDSpaceSIP

:edit_media_uri

(optional) an override to the existing entry’s edit media URI (media resource URI). If not supplied, this will default to the existing entry’s first edit media URI (as there can be multiple edit media URIs).

:on_behalf_of

(optional) username on whos behalf the submission is being performed

:metadata_relevant

(optional) boolean value indicating whether the server should consider the file or package a potential source of metadata.

:connection

(optional) Sword2Ruby::Connection object used to perform the operation. If not supplied, the existing entry’s connection will be used.

Note that you should call <collection>.feed.updated! followed by <collection>.feed.update! after making updates to a collection.

For more information, see the Sword2 specification: section 6.7.1. “Adding Content to the Media Resource”.



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'lib/sword2ruby/entry.rb', line 202

def post_media!(params = {})
  Utility.check_argument_class('params', params, Hash)
  defaults = {
    :filepath => nil,
    :content_type => nil,
    :packaging => nil,
    :edit_media_uri => edit_media_links.first.href,
    :on_behalf_of => nil,
    :metadata_relevant => nil,
    :connection => @http
  }
  options = defaults.merge(params)
  
  #Validate parameters
  Utility.check_argument_class(':filepath', options[:filepath], String)
  Utility.check_argument_class(':content_type', options[:content_type], String)
  Utility.check_argument_class(':packaging', options[:packaging], String) if options[:packaging]
  Utility.check_argument_class(':edit_media_uri', options[:edit_media_uri], String)
  Utility.check_argument_class(':on_behalf_of', options[:on_behalf_of], String) if options[:on_behalf_of]
  Utility.check_argument_class(':connection', options[:connection], Sword2Ruby::Connection)
     
  filename, md5, data = Utility.read_file(options[:filepath])

  headers = {"Content-Type" => options[:content_type]}
  headers["Content-Disposition"] = "attachment; filename=#{filename}"
  headers["Content-MD5"] = md5
  headers["Packaging"] = options[:packaging] if options[:packaging]
  headers["Metadata-Relevant"] = options[:metadata_relevant].to_s.downcase if (options[:metadata_relevant] == true || options[:metadata_relevant] == false)
  headers["On-Behalf-Of"] = options[:on_behalf_of] if options[:on_behalf_of]

  response = options[:connection].post(options[:edit_media_uri], data, headers)

  if response.is_a? Net::HTTPSuccess
    return DepositReceipt.new(response, options[:connection])
  else
   raise Sword2Ruby::Exception.new("Failed to do post_media!(#{options[:edit_media_uri]}): server returned #{response.code} #{response.message}")
  end
end

#post_multipart!(params = {}) ⇒ Object

This method posts an entry and a file to an existing entry’s sword-edit URI, adding to the existing entry’s metadata and media resources (i.e. not overwriting existing metadata and media resources). It does not create a new entry in the collection. An MD5-digest will be calculated automatically from the file and sent to the server with the request. The method will return a Sword2Ruby::DepositReceipt object, or raise a Sword2Ruby::Exception in the case of an error.

Parameters (passed as a hash collection)

:entry

(optional) a new Atom::Entry with metadata to be added to an existing Atom::Entry. If not supplied, this will default to itself.

:filepath

a filepath string indicating the file to be posted. The file must be readable by the process.

:content_type

the mime content-type string of the file, e.g. “application/zip” or “text/plain”

:packaging

(optional) the Sword packaging string of the file, e.g. “purl.org/net/sword/package/METSDSpaceSIP

:sword_edit_uri

(optional) an override to the existing entry’s sword edit URI. If not supplied, this will default to the existing entry’s sword edit URI.

:in_progress

(optional) boolean value indicating whether the existing entry will be completed at a later date.

:on_behalf_of

(optional) username on whos behalf the submission is being performed

:metadata_relevant

(optional) boolean value indicating whether the server should consider the file or package a potential source of metadata.

:connection

(optional) Sword2Ruby::Connection object used to perform the operation. If not supplied, the existing entry’s connection will be used.

Note that you should call <collection>.feed.updated! followed by <collection>.feed.update! after making updates to a collection.

For more information, see the Sword2 specification: section 6.7.3. “Adding Content to the Media Resource”.



260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/sword2ruby/entry.rb', line 260

def post_multipart!(params = {})
  Utility.check_argument_class('params', params, Hash)
  defaults = {
    :entry => self,
    :filepath => nil,
    :content_type => nil,
    :packaging => nil,
    :sword_edit_uri => sword_edit_uri,
    :in_progress => nil,
    :on_behalf_of => nil,
    :metadata_relevant => nil,
    :connection => @http
  }
  options = defaults.merge(params)

  #Validate parameters
  Utility.check_argument_class(':entry', options[:entry], ::Atom::Entry)
  Utility.check_argument_class(':filepath', options[:filepath], String)
  Utility.check_argument_class(':content_type', options[:content_type], String)
  Utility.check_argument_class(':packaging', options[:packaging], String) if options[:packaging]
  Utility.check_argument_class(':sword_edit_uri', options[:sword_edit_uri], String)
  Utility.check_argument_class(':on_behalf_of', options[:on_behalf_of], String) if options[:on_behalf_of]
  Utility.check_argument_class(':connection', options[:connection], Sword2Ruby::Connection)

  tmp = ""
  boundary = "========" + Time.now.to_i.to_s + "=="
  filename, md5, data = Utility.read_file(options[:filepath])
  

  headers = {"Content-Type" => 'multipart/related; boundary="' + boundary + '"; type="application/atom+xml"'}
  headers["In-Progress"] = options[:in_progress].to_s.downcase if (options[:in_progress] == true || options[:in_progress] == false)
  headers["On-Behalf-Of"] = options[:on_behalf_of] if options[:on_behalf_of]
  headers["MIME-Version"] = "1.0"


  # write boundary identifer to temp
  tmp << "--#{boundary}\r\n"

  # write entry relevant headers to temp
  tmp << "Content-Type: application/atom+xml; charset=\"utf-8\"\r\n"
  tmp << "Content-Disposition: attachment; name=atom\r\n"
  tmp << "MIME-Version: 1.0\r\n\r\n"

  # write entry to temp
  tmp << options[:entry].to_s + "\r\n"

  # write boundary identifier to temp
  tmp << "--#{boundary}\r\n"

  # write media part relevant headers to temp      
  tmp << "Content-Type: #{options[:content_type]}\r\n"
  tmp << "Content-Disposition: attachment; name=payload; filename=#{filename}\r\n"
  tmp << "Content-MD5: #{md5}\r\n"
  tmp << "Packaging: #{options[:packaging]}\r\n" if options[:packaging]
  tmp << "Metadata-Relevant: #{options[:metadata_relevant].to_s.downcase}\r\n" if (options[:metadata_relevant] == true || options[:metadata_relevant] == false)
  tmp << "MIME-Version: 1.0\r\n\r\n"

  # write the file base64 encoded to temp
  tmp << Base64.encode64(data)

  # write boundary identifier to temp
  tmp << "--#{boundary}--\r\n" #The last two dashes (--) are important!

  response = options[:connection].post(options[:sword_edit_uri], tmp, headers)

  if response.is_a? Net::HTTPSuccess
    return DepositReceipt.new(response, options[:connection])
  else
    raise Sword2Ruby::Exception.new("Failed to do post_multipart!(#{options[:sword_edit_uri]}): server returned #{response.code} #{response.message}")
  end
end

#put!(params = {}) ⇒ Object

This method replaces an existing entry’s metadata by performing a Put on the entry-edit URI. It does not create a new entry in the collection. The method will return a Sword2Ruby::DepositReceipt object, or raise a Sword2Ruby::Exception in the case of an error.

Example

feed = collection.feed # assuming that you have retrieved a collection from the service document feed.update! # get all the entry data existing_entry = feed.entries.first existing_entry.title = “The Improved Burrito” existing_entry.summary = “Replacing the metadata of an existing entry” existing_entry.add_dublin_core_extension!(“publisher”, “Burrito King”) existing_entry.put!

Parameters (passed as a hash collection)

:entry

(optional) a new Atom::Entry with metadata to replace an existing Atom::Entry. If not supplied, this will default to itself.

:entry_edit_uri

(optional) an override to the existing entry’s entry-edit URI. If not supplied, this will default to the existing entry’s entry-edit URI.

:in_progress

(optional) boolean value indicating whether the existing entry will be completed at a later date.

:on_behalf_of

(optional) username on whos behalf the submission is being performed.

:connection

(optional) Sword2Ruby::Connection object used to perform the operation. If not supplied, the existing entry’s connection will be used.

Note that you should call <collection>.feed.updated! followed by <collection>.feed.update! after making updates to a collection.

For more information, see the Sword2 specification: section 6.5.2. “Replacing the Metadata of a Resource”.



355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/sword2ruby/entry.rb', line 355

def put!(params = {})
  Utility.check_argument_class('params', params, Hash)
  defaults = {
    :entry => self,
    :entry_edit_uri => entry_edit_uri,
    :in_progress => nil,
    :on_behalf_of => nil,
    :connection => @http
  }
  options = defaults.merge(params)
 
  #Validate parameters
  Utility.check_argument_class(':entry', options[:entry], ::Atom::Entry)
  Utility.check_argument_class(':entry_edit_uri', options[:entry_edit_uri], String)
  Utility.check_argument_class(':on_behalf_of', options[:on_behalf_of], String) if options[:on_behalf_of]
  Utility.check_argument_class(':connection', options[:connection], Sword2Ruby::Connection)
        
  headers = {"Content-Type" => "application/atom+xml;type=entry" }
  headers["In-Progress"] = options[:in_progress].to_s.downcase if (options[:in_progress] == true || options[:in_progress] == false)
  headers["On-Behalf-Of"] = options[:on_behalf_of] if options[:on_behalf_of]
  response = options[:connection].put(options[:entry_edit_uri], options[:entry].to_s, headers)
  if response.is_a? Net::HTTPSuccess
    return DepositReceipt.new(response, options[:connection])
  else
    raise Sword2Ruby::Exception.new("Failed to do put!(#{options[:entry_edit_uri]}): server returned code #{response.code} #{response.message}")
  end
end

#put_media!(params = {}) ⇒ Object

This method replaces an existing entry’s file content of a resource by performing a Put on the edit-media URI. It does not create a new entry in the collection. The method will return a Sword2Ruby::DepositReceipt object, or raise a Sword2Ruby::Exception in the case of an error.

Parameters (passed as a hash collection)

:filepath

a filepath string indicating the file to be sent. The file must be readable by the process.

:content_type

the mime content-type string of the file, e.g. “application/zip” or “text/plain”

:packaging

(optional) the Sword packaging string of the file, e.g. “purl.org/net/sword/package/METSDSpaceSIP

:edit_media_uri

(optional) an override to the existing entry’s edit-media URI. If not supplied, this will default to the existing entry’s first edit-media URI.

:on_behalf_of

(optional) username on whos behalf the submission is being performed.

:metadata_relevant

(optional) boolean value indicating whether the server should consider the file or package a potential source of metadata.

:connection

(optional) Sword2Ruby::Connection object used to perform the operation. If not supplied, the existing entry’s connection will be used.

Note that you should call <collection>.feed.updated! followed by <collection>.feed.update! after making updates to a collection.

For more information, see the Sword2 specification: section 6.5.1. “Replacing the File Content of a Resource”.



399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'lib/sword2ruby/entry.rb', line 399

def put_media!(params = {})
  Utility.check_argument_class('params', params, Hash)
  defaults = {
    :filepath => nil,
    :content_type => nil,
    :packaging => nil,
    :edit_media_uri => edit_media_links.first.href,
    :on_behalf_of => nil,
    :metadata_relevant => nil,
    :connection => @http
  }
  options = defaults.merge(params)
  
  #Validate parameters
  Utility.check_argument_class(':filepath', options[:filepath], String)
  Utility.check_argument_class(':content_type', options[:content_type], String)
  Utility.check_argument_class(':packaging', options[:packaging], String) if options[:packaging]
  Utility.check_argument_class(':edit_media_uri', options[:edit_media_uri], String)
  Utility.check_argument_class(':on_behalf_of', options[:on_behalf_of], String) if options[:on_behalf_of]
  Utility.check_argument_class(':connection', options[:connection], Sword2Ruby::Connection)
  
  filename, md5, data = Utility.read_file(options[:filepath])

  headers = {"Content-Type" => options[:content_type]}
  headers["Content-Disposition"] = "attachment; filename=#{filename}"
  headers["Content-MD5"] = md5
  headers["Packaging"] = options[:packaging] if options[:packaging]
  headers["Metadata-Relevant"] = options[:metadata_relevant].to_s.downcase if (options[:metadata_relevant] == true || options[:metadata_relevant] == false)
  headers["On-Behalf-Of"] = options[:on_behalf_of] if options[:on_behalf_of]

  response = options[:connection].put(options[:edit_media_uri], data, headers)

  if response.is_a? Net::HTTPSuccess
    return DepositReceipt.new(response, options[:connection])
  else
   raise Sword2Ruby::Exception.new("Failed to do put_media!(#{options[:edit_media_uri]}): server returned #{response.code} #{response.message}")
  end
end

#put_multipart!(params = {}) ⇒ Object

This method replaces an existing entry’s metadata and file content of a resource by performing a Put on the entry-edit URI. It does not create a new entry in the collection. The method will return a Sword2Ruby::DepositReceipt object, or raise a Sword2Ruby::Exception in the case of an error.

Parameters (passed as a hash collection)

:entry

(optional) a new Atom::Entry with metadata to replace an existing Atom::Entry. If not supplied, this will default to itself.

:filepath

a filepath string indicating the file to be sent. The file must be readable by the process.

:content_type

the mime content-type string of the file, e.g. “application/zip” or “text/plain”

:packaging

(optional) the Sword packaging string of the file, e.g. “purl.org/net/sword/package/METSDSpaceSIP

:entry_edit_uri

(optional) an override to the existing entry’s entry-edit URI. If not supplied, this will default to the existing entry’s entry-edit URI.

:on_behalf_of

(optional) username on whos behalf the submission is being performed.

:metadata_relevant

(optional) boolean value indicating whether the server should consider the file or package a potential source of metadata.

:connection

(optional) Sword2Ruby::Connection object used to perform the operation. If not supplied, the existing entry’s connection will be used.

Note that you should call <collection>.feed.updated! followed by <collection>.feed.update! after making updates to a collection.

For more information, see the Sword2 specification: section 6.5.3. “Replacing the Metadata and File Content of a Resource”.



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/sword2ruby/entry.rb', line 456

def put_multipart!(params = {})
  Utility.check_argument_class('params', params, Hash)
  defaults = {
    :entry => self,
    :filepath => nil,
    :content_type => nil,
    :packaging => nil,
    :entry_edit_uri => entry_edit_uri,
    :in_progress => nil,
    :on_behalf_of => nil,
    :metadata_relevant => nil,
    :connection => @http
  }
  options = defaults.merge(params)

  #Validate parameters
  Utility.check_argument_class(':entry', options[:entry], ::Atom::Entry)
  Utility.check_argument_class(':filepath', options[:filepath], String)
  Utility.check_argument_class(':content_type', options[:content_type], String)
  Utility.check_argument_class(':packaging', options[:packaging], String) if options[:packaging]
  Utility.check_argument_class(':entry_edit_uri', options[:entry_edit_uri], String)
  Utility.check_argument_class(':on_behalf_of', options[:on_behalf_of], String) if options[:on_behalf_of]
  Utility.check_argument_class(':connection', options[:connection], Sword2Ruby::Connection)

  tmp = ""
  boundary = "========" + Time.now.to_i.to_s + "=="
  filename, md5, data = Utility.read_file(options[:filepath])

  
  headers = {"Content-Type" => 'multipart/related; boundary="' + boundary + '"; type="application/atom+xml"'}
  headers["In-Progress"] = options[:in_progress].to_s.downcase if (options[:in_progress] == true || options[:in_progress] == false)
  headers["On-Behalf-Of"] = options[:on_behalf_of] if options[:on_behalf_of]
  headers["MIME-Version"] = "1.0"

  # write boundary identifer to temp
  tmp << "--#{boundary}\r\n"

  # write entry relevant headers to temp
  tmp << "Content-Type: application/atom+xml; charset=\"utf-8\"\r\n"
  tmp << "Content-Disposition: attachment; name=atom\r\n"
  tmp << "MIME-Version: 1.0\r\n\r\n"

  # write entry to temp
  tmp << options[:entry].to_s + "\r\n"

  # write boundary identifier to temp
  tmp << "--#{boundary}\r\n"

  # write media part relevant headers to temp      
  tmp << "Content-Type: #{options[:content_type]}\r\n"
  tmp << "Content-Disposition: attachment; name=payload; filename=#{filename}\r\n"
  tmp << "Content-MD5: #{md5}\r\n"
  tmp << "Packaging: #{options[:packaging]}\r\n" if options[:packaging]
  tmp << "MIME-Version: 1.0\r\n\r\n"

  # write the file base64 encoded to temp
  tmp << Base64.encode64(data)

  # write boundary identifier to temp
  tmp << "--#{boundary}--\r\n" #The last two dashes (--) are important!

  response = options[:connection].put(options[:entry_edit_uri], tmp, headers)

  if response.is_a? Net::HTTPSuccess
    return DepositReceipt.new(response, options[:connection])
  else
    raise Sword2Ruby::Exception.new("Failed to do put_multipart!(#{options[:entry_edit_uri]}): server returned #{response.code} #{response.message}")
  end
end

#sword_deposited_byObject

This method returns the string value of the <sword:depositedBy> tag (usually contained in the Sword Statement Atom Feed), or nil if it is not defined.



117
118
119
# File 'lib/sword2ruby/entry.rb', line 117

def sword_deposited_by
  Utility.find_element_text(extensions, "sword:depositedBy")
end

#sword_deposited_onObject

This method returns the time value of the <sword:depositedOn> tag (usually contained in the Sword Statement Atom Feed), or nil if it is not defined.



111
112
113
# File 'lib/sword2ruby/entry.rb', line 111

def sword_deposited_on
  Utility.find_element_time(extensions, "sword:depositedOn")
end

#sword_deposited_on_behalf_ofObject

This method returns the string value of the <sword:depositedOnBehalfOf> tag (usually contained in the Sword Statement Atom Feed), or nil if it is not defined.



123
124
125
# File 'lib/sword2ruby/entry.rb', line 123

def sword_deposited_on_behalf_of
  Utility.find_element_text(extensions, "sword:depositedOnBehalfOf")
end

This method returns an array of Atom::Links for the derived resource <link rel=“purl.org/net/sword/terms/derivedResource”> tags (usually contained in the DepositReceipt Entry), or an empty array [ ] if none are defined.



46
47
48
# File 'lib/sword2ruby/entry.rb', line 46

def sword_derived_resource_links
  Utility.find_links_all_types(links, "http://purl.org/net/sword/terms/derivedResource")
end

#sword_edit_uriObject

This method returns the URI string of the sword edit <link rel=“purl.org/net/sword/terms/add”> tag (usually contained in the DepositReceipt Entry), or nil if it is not defined.



34
35
36
# File 'lib/sword2ruby/entry.rb', line 34

def sword_edit_uri
  Utility.find_link_uri(links, "http://purl.org/net/sword/terms/add")
end

#sword_original_deposit_categoryObject

This method returns the Atom::Category of the original deposit (usually contained in the Sword Statement Atom Feed), or nil if it is not defined.



129
130
131
# File 'lib/sword2ruby/entry.rb', line 129

def sword_original_deposit_category
  Utility.find_element_by_scheme_and_term(categories, "http://purl.org/net/sword/terms/", "http://purl.org/net/sword/terms/originalDeposit")
end

#sword_original_deposit_uriObject

This method returns the URI string of the package or file deposited, as specified in the <link rel=“purl.org/net/sword/terms/originalDeposit”> tag (usually contained in the DepositReceipt Entry), or nil if it is not defined.



40
41
42
# File 'lib/sword2ruby/entry.rb', line 40

def sword_original_deposit_uri
  Utility.find_link_uri(links, "http://purl.org/net/sword/terms/originalDeposit")
end

#sword_packagingsObject

This method returns an array of string values for the sword packagings, from the <sword:packaging> tags (usually contained in the DepositReceipt Entry), or an empty array [ ] if none are defined.



58
59
60
# File 'lib/sword2ruby/entry.rb', line 58

def sword_packagings
  Utility.find_elements_text(extensions, "sword:packaging")
end

This method returns an array of Atom::Links for the sword statements, from the <link rel=“purl.org/net/sword/terms/statement”> tags (usually contained in the DepositReceipt Entry), or an empty array [ ] if none are defined.



52
53
54
# File 'lib/sword2ruby/entry.rb', line 52

def sword_statement_links
  Utility.find_links_all_types(links, "http://purl.org/net/sword/terms/statement")
end

#sword_treatmentObject

This method returns the string value of the sword treatment <sword:treatment> tag (usually contained in the DepositReceipt Entry), or nil if it is not defined.



64
65
66
# File 'lib/sword2ruby/entry.rb', line 64

def sword_treatment
  Utility.find_element_text(extensions, "sword:treatment")
end

#sword_verbose_descriptionObject

This method returns the string value of the sword verbose description <sword:verboseDescription> tag (usually contained in the DepositReceipt Entry), or nil if it is not defined.



70
71
72
# File 'lib/sword2ruby/entry.rb', line 70

def sword_verbose_description
  Utility.find_element_text(extensions, "sword:verboseDescription")
end