Class: Sword2Ruby::DepositReceipt
- Inherits:
-
Object
- Object
- Sword2Ruby::DepositReceipt
- Defined in:
- lib/sword2ruby/deposit_receipt.rb
Overview
The DepositReceipt object is returned following Post, Put and Delete operations on the Sword server. In some cases (e.g. Post), an Atom::Entry will usually be returned describing the newly created entry. Operations such as Delete do not return an Atom::Entry. If the Sword server does not automatically return the Atom::Entry but instead provides a link to it, the DepositReceipt object will automatically fetch it.
For more information, see the Sword2 specification: section 10 “Deposit Receipt”.
Instance Attribute Summary collapse
-
#entry ⇒ Object
readonly
The Atom::Entry associated with this receipt, or nil if not supplied.
-
#has_entry ⇒ Object
readonly
Boolean value indicating whether there is an Atom::Entry associated with this receipt.
-
#location ⇒ Object
readonly
The location header returned by the Sword server, usually after Posting or Putting.
-
#status_code ⇒ Object
readonly
The http status code returned by the Sword server.
-
#status_message ⇒ Object
readonly
The http status message returned by the Sword server.
Instance Method Summary collapse
-
#initialize(response, connection) ⇒ DepositReceipt
constructor
Create a new DepositReceipt using the Response object returned by the server.
Constructor Details
#initialize(response, connection) ⇒ DepositReceipt
Create a new DepositReceipt using the Response object returned by the server.
Parameters
- response
-
the response object returned by the request
- connection
-
a Sword2Ruby::Connection object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/sword2ruby/deposit_receipt.rb', line 28 def initialize(response, connection) @location = response.header["location"] @status_code = response.code @status_message = response. if response.body #If a receipt was returned, parse it begin #ensure that there are not parse errors. If there are, warn, rather then raise @entry = ::Atom::Entry.parse(response.body) @has_entry = true @entry.http = connection rescue Exception => @has_entry = false $stderr.puts "ERROR: An error occured processing the Response XML: #{}" rescue StandardError => error @has_entry = false $stderr.puts "WARN: The deposit was successful, but there was an issue with Response XML. It could be missing. (#{error})" end else #if the receipt was not returned, try and retrieve it if @location @entry = ::Atom::Entry.parse(connection.get(@location).body) @has_entry = true else #Otherwise, there is no receipt (e.g. for a delete) @has_entry = false @entry = nil end end end |
Instance Attribute Details
#entry ⇒ Object (readonly)
The Atom::Entry associated with this receipt, or nil if not supplied. The Atom::Entry will be automatically fetched from the server when necessary.
13 14 15 |
# File 'lib/sword2ruby/deposit_receipt.rb', line 13 def entry @entry end |
#has_entry ⇒ Object (readonly)
Boolean value indicating whether there is an Atom::Entry associated with this receipt.
10 11 12 |
# File 'lib/sword2ruby/deposit_receipt.rb', line 10 def has_entry @has_entry end |
#location ⇒ Object (readonly)
The location header returned by the Sword server, usually after Posting or Putting.
16 17 18 |
# File 'lib/sword2ruby/deposit_receipt.rb', line 16 def location @location end |
#status_code ⇒ Object (readonly)
The http status code returned by the Sword server.
19 20 21 |
# File 'lib/sword2ruby/deposit_receipt.rb', line 19 def status_code @status_code end |
#status_message ⇒ Object (readonly)
The http status message returned by the Sword server.
22 23 24 |
# File 'lib/sword2ruby/deposit_receipt.rb', line 22 def @status_message end |