Class: Net::HTTPResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/s33r/s33r_http.rb

Overview

Adds some convenience functions for checking response status, parsing error messages from

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#body=(value) ⇒ Object (writeonly)

Sets the attribute body

Parameters:

  • value

    the value to set the attribute body to.



6
7
8
# File 'lib/s33r/s33r_http.rb', line 6

def body=(value)
  @body = value
end

#s3_errorObject (readonly)

An exception wrapped around the response from S3



9
10
11
# File 'lib/s33r/s33r_http.rb', line 9

def s3_error
  @s3_error
end

Instance Method Details

#conveniencify(method) ⇒ Object

Wrap responses properly so the S3 error codes don’t have to be read.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/s33r/s33r_http.rb', line 12

def conveniencify(method)
  if '200' == code
    @ok = true
    @s3_message = 'Request successful'
  # 204 returned for successful bucket or item deletes
  elsif '204' == code and 'DELETE' == method
    @s3_message = 'Successfully deleted'
    @ok = true
  else
    @ok = false
    if body.nil?
      @s3_error = S33r::S3Exception.error(code)
    else
      # Get the S3 error message and code
      error_response = XML.get_xml_doc(body)
      s3_code = error_response.xget('//Code')
      s3_message = error_response.xget('//Message')
      
      @s3_error = S33r::S3Exception.error(s3_code, s3_message)
    end
  end
end

#ok?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/s33r/s33r_http.rb', line 35

def ok?
  @ok || false
end

#to_sObject



39
40
41
# File 'lib/s33r/s33r_http.rb', line 39

def to_s
  body
end