Class: NetHTTP::Response
- Inherits:
-
Object
- Object
- NetHTTP::Response
- Defined in:
- lib/response/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#body_obj ⇒ Object
Returns the value of attribute body_obj.
-
#body_os ⇒ Object
Returns the value of attribute body_os.
-
#code ⇒ Object
Returns the value of attribute code.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#headers_hash ⇒ Object
Returns the value of attribute headers_hash.
-
#headers_os ⇒ Object
Returns the value of attribute headers_os.
- #logger ⇒ Object writeonly
- #response ⇒ Object writeonly
Instance Method Summary collapse
- #content_type ⇒ Object
-
#initialize(opts = {}) ⇒ Response
constructor
A new instance of Response.
- #log_response ⇒ Object
- #parse_json(body, logger) ⇒ Object
- #parse_xml(body, logger) ⇒ Object
- #valid_html? ⇒ Boolean
- #valid_json? ⇒ Boolean
- #valid_xml? ⇒ Boolean
Constructor Details
#initialize(opts = {}) ⇒ Response
Returns a new instance of Response.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/response/response.rb', line 21 def initialize(opts = {}) send('logger=', opts[:logger]) @response = opts[:response] send('response=', opts[:response]) send('code=') send('headers=') send('headers_hash=') send('headers_os=') send('body=') send('body_obj=') send('body_os=') log_response end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
11 12 13 |
# File 'lib/response/response.rb', line 11 def body @body end |
#body_obj ⇒ Object
Returns the value of attribute body_obj.
11 12 13 |
# File 'lib/response/response.rb', line 11 def body_obj @body_obj end |
#body_os ⇒ Object
Returns the value of attribute body_os.
11 12 13 |
# File 'lib/response/response.rb', line 11 def body_os @body_os end |
#code ⇒ Object
Returns the value of attribute code.
11 12 13 |
# File 'lib/response/response.rb', line 11 def code @code end |
#headers ⇒ Object
Returns the value of attribute headers.
11 12 13 |
# File 'lib/response/response.rb', line 11 def headers @headers end |
#headers_hash ⇒ Object
Returns the value of attribute headers_hash.
11 12 13 |
# File 'lib/response/response.rb', line 11 def headers_hash @headers_hash end |
#headers_os ⇒ Object
Returns the value of attribute headers_os.
11 12 13 |
# File 'lib/response/response.rb', line 11 def headers_os @headers_os end |
#logger=(logger = nil) ⇒ Object
123 124 125 |
# File 'lib/response/response.rb', line 123 def logger=(logger = nil) @logger = Core.get_logger(logger) end |
#response=(response) ⇒ Object
86 87 88 |
# File 'lib/response/response.rb', line 86 def response=(response) @response = response end |
Instance Method Details
#content_type ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/response/response.rb', line 59 def content_type content_type = headers_hash.select { |k,v| k.to_s.downcase == 'content_type' } return nil if content_type.empty? content_type[:content_type] end |
#log_response ⇒ Object
127 128 129 130 131 132 133 |
# File 'lib/response/response.rb', line 127 def log_response logger.debug('Response Code => ' + code) logger.debug('Response Headers => ') logger.debug(headers) logger.debug('Response Body => ') logger.debug(body) end |
#parse_json(body, logger) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/response/response.rb', line 90 def parse_json(body, logger) begin NetHTTP::Core::Utilities.json_2_hash(body, 'symbol', logger) rescue JSON::ParserError => err logger.debug(err) return {} end end |
#parse_xml(body, logger) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/response/response.rb', line 99 def parse_xml(body, logger) begin NetHTTP::Core::Utilities.xml_2_hash(body, 'symbol', logger) rescue Nokogiri::XML::SyntaxError => err logger.debug(err) return {} end end |
#valid_html? ⇒ Boolean
116 117 118 |
# File 'lib/response/response.rb', line 116 def valid_html? NetHTTP::Core::Utilities.valid_html?(body, logger) end |
#valid_json? ⇒ Boolean
108 109 110 |
# File 'lib/response/response.rb', line 108 def valid_json? NetHTTP::Core::Utilities.valid_json?(body, logger) end |
#valid_xml? ⇒ Boolean
112 113 114 |
# File 'lib/response/response.rb', line 112 def valid_xml? NetHTTP::Core::Utilities.valid_xml?(body, logger) end |