Class: Sword2Ruby::DepositReceipt

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.message
        
  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 => message
      @has_entry = false
      $stderr.puts "ERROR: An error occured processing the Response XML: #{message}"
    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

#entryObject (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_entryObject (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

#locationObject (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_codeObject (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_messageObject (readonly)

The http status message returned by the Sword server.



22
23
24
# File 'lib/sword2ruby/deposit_receipt.rb', line 22

def status_message
  @status_message
end