Class: Ingenico::Connect::SDK::Response
- Inherits:
-
Object
- Object
- Ingenico::Connect::SDK::Response
- Defined in:
- lib/ingenico/connect/sdk/response.rb
Overview
Base class for HTTP responses. It provides access to the response headers, status code and response message body
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Response message body.
-
#headers ⇒ Object
readonly
Response headers as a ResponseHeader list.
-
#status_code ⇒ Object
readonly
HTTP status code.
Instance Method Summary collapse
-
#get_header(header_name) ⇒ Object
Returns the ResponseHeader that goes by the given header_name, or nil if this Response does not contain a header with the given name.
-
#get_header_value(header_name) ⇒ Object
Returns the header value of the header that goes by the given header_name, or nil if this Response does not contain a header with the given name.
-
#initialize(status_code, body, headers) ⇒ Response
constructor
- Create a new response object that stores the following: status_code
- HTTP status code body
- response message body, given as a string headers
-
response headers as a ResponseHeader list.
- #to_s ⇒ Object
Constructor Details
#initialize(status_code, body, headers) ⇒ Response
Create a new response object that stores the following:
- status_code
-
HTTP status code
- body
-
response message body, given as a string
- headers
-
response headers as a Ingenico::Connect::SDK::ResponseHeader list
10 11 12 13 14 15 16 17 18 |
# File 'lib/ingenico/connect/sdk/response.rb', line 10 def initialize(status_code, body, headers) @status_code = status_code @body = body if headers.nil? @headers = [].freeze else @headers = headers.dup.freeze end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Response message body
23 24 25 |
# File 'lib/ingenico/connect/sdk/response.rb', line 23 def body @body end |
#headers ⇒ Object (readonly)
Response headers as a Ingenico::Connect::SDK::ResponseHeader list
25 26 27 |
# File 'lib/ingenico/connect/sdk/response.rb', line 25 def headers @headers end |
#status_code ⇒ Object (readonly)
HTTP status code
21 22 23 |
# File 'lib/ingenico/connect/sdk/response.rb', line 21 def status_code @status_code end |
Instance Method Details
#get_header(header_name) ⇒ Object
Returns the Ingenico::Connect::SDK::ResponseHeader that goes by the given header_name, or nil if this Response does not contain a header with the given name.
29 30 31 32 33 34 35 36 |
# File 'lib/ingenico/connect/sdk/response.rb', line 29 def get_header(header_name) @headers.each { |header| if header.name.casecmp(header_name) == 0 return header end } return nil end |
#get_header_value(header_name) ⇒ Object
Returns the header value of the header that goes by the given header_name, or nil if this Response does not contain a header with the given name.
40 41 42 43 44 45 46 47 |
# File 'lib/ingenico/connect/sdk/response.rb', line 40 def get_header_value(header_name) header = get_header(header_name) if !header.nil? header.value else nil end end |
#to_s ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ingenico/connect/sdk/response.rb', line 49 def to_s str = self.class.name str += '[status_code=' + @status_code.to_s if !@body.nil? && @body.length > 0 str += ",body='" + @body + "'" end unless @headers.empty? || @headers.nil? str += ',headers=' + @headers.to_s end str += ']' str.to_s end |