Class: Typhoeus::Response
- Inherits:
-
Object
- Object
- Typhoeus::Response
- Includes:
- CurlHelper
- Defined in:
- lib/labclient/http.rb
Overview
Add Data : OJ Parsing
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #data ⇒ Object
-
#find_friendly_error ⇒ Object
Print Error information 1.
- #friendly_error ⇒ Object
- #inspect ⇒ Object
-
#json_body? ⇒ Boolean
Check if response body can be parsed.
- #process_body ⇒ Object
-
#response ⇒ Object
Shim for CurlHelper.
-
#retry? ⇒ Boolean
Retry Helper Accessor.
Methods included from CurlHelper
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
75 76 77 |
# File 'lib/labclient/http.rb', line 75 def client @client end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
75 76 77 |
# File 'lib/labclient/http.rb', line 75 def path @path end |
Instance Method Details
#data ⇒ Object
77 78 79 80 81 |
# File 'lib/labclient/http.rb', line 77 def data @data ||= process_body @data end |
#find_friendly_error ⇒ Object
Print Error information
-
Use Typheous ‘return_message` if there isn’t any return body
For network/uri/dns related issues
-
Use body for parsed responses
For Bad Request, invalid params
-
Return raw data
For non body responses
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/labclient/http.rb', line 122 def find_friendly_error case data when nil when LabClient::LabStruct data[:message] || data[:error] else # Handle String as well data end end |
#friendly_error ⇒ Object
133 134 135 |
# File 'lib/labclient/http.rb', line 133 def friendly_error "#{code} - #{find_friendly_error}" end |
#inspect ⇒ Object
71 72 73 |
# File 'lib/labclient/http.rb', line 71 def inspect "#<TyphoeusResponse code: #{code}>" end |
#json_body? ⇒ Boolean
Check if response body can be parsed
89 90 91 92 93 94 95 96 |
# File 'lib/labclient/http.rb', line 89 def json_body? content_type = headers['content-type'] return false unless content_type return true if content_type.include? 'application/json' false end |
#process_body ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/labclient/http.rb', line 98 def process_body return nil if body.empty? if json_body? result = Oj.load(body, mode: :compat, symbol_keys: true, object_class: LabClient::LabStruct) result.instance_variable_set(:@response, self) if result.instance_of?(LabClient::LabStruct) result else body end end |
#response ⇒ Object
Shim for CurlHelper
84 85 86 |
# File 'lib/labclient/http.rb', line 84 def response self end |
#retry? ⇒ Boolean
Retry Helper Accessor
111 112 113 |
# File 'lib/labclient/http.rb', line 111 def retry? code == 429 end |