Class: WssAgent::Response
- Inherits:
-
Object
- Object
- WssAgent::Response
- Defined in:
- lib/wss_agent/response.rb
Direct Known Subclasses
Constant Summary collapse
- SUCCESS_STATUS =
1- BAD_REQUEST_STATUS =
2- SERVER_ERROR_STATUS =
3
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#response_data ⇒ Object
readonly
Returns the value of attribute response_data.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
- #parse_error ⇒ Object
- #parse_response ⇒ Object
- #response_success? ⇒ Boolean
- #success? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 14 15 16 |
# File 'lib/wss_agent/response.rb', line 9 def initialize(response) @response = response if response.is_a?(Faraday::Error::ClientError) parse_error else parse_response end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/wss_agent/response.rb', line 7 def data @data end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
7 8 9 |
# File 'lib/wss_agent/response.rb', line 7 def end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/wss_agent/response.rb', line 7 def response @response end |
#response_data ⇒ Object (readonly)
Returns the value of attribute response_data.
7 8 9 |
# File 'lib/wss_agent/response.rb', line 7 def response_data @response_data end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/wss_agent/response.rb', line 7 def status @status end |
Instance Method Details
#parse_error ⇒ Object
18 19 20 21 |
# File 'lib/wss_agent/response.rb', line 18 def parse_error @status = SERVER_ERROR_STATUS = response. end |
#parse_response ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/wss_agent/response.rb', line 23 def parse_response if response.success? begin @response_data = MultiJson.load(response.body) @status = @response_data['status'].to_i = @response_data['message'] rescue @status = SERVER_ERROR_STATUS = response.body end else @status = SERVER_ERROR_STATUS = response.body end end |
#response_success? ⇒ Boolean
39 40 41 42 43 44 45 |
# File 'lib/wss_agent/response.rb', line 39 def response_success? if response.is_a?(Faraday::Error::ClientError) false else response.success? end end |
#success? ⇒ Boolean
47 48 49 |
# File 'lib/wss_agent/response.rb', line 47 def success? response_success? && status == SUCCESS_STATUS end |