Class: Typhoeus::Response

Inherits:
Object
  • Object
show all
Includes:
CurlHelper
Defined in:
lib/labclient/http.rb

Overview

Add Data : OJ Parsing

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CurlHelper

#curl

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



72
73
74
# File 'lib/labclient/http.rb', line 72

def client
  @client
end

#pathObject (readonly)

Returns the value of attribute path.



72
73
74
# File 'lib/labclient/http.rb', line 72

def path
  @path
end

Instance Method Details

#dataObject



74
75
76
77
78
# File 'lib/labclient/http.rb', line 74

def data
  return @data if @data

  @data = process_body
end

#friendly_errorObject



97
98
99
100
101
102
103
104
# File 'lib/labclient/http.rb', line 97

def friendly_error
  message = if data
              data[:message] || data[:error] || data
            else
              return_message
            end
  "#{code} - #{message}"
end

#inspectObject



68
69
70
# File 'lib/labclient/http.rb', line 68

def inspect
  "#<TyphoeusResponse code: #{code}>"
end

#process_bodyObject



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/labclient/http.rb', line 85

def process_body
  if body.empty?
    nil
  elsif headers['content-type']&.include? 'text/plain'
    body
  else
    result = Oj.load(body, mode: :compat, object_class: LabClient::LabStruct)
    result.instance_variable_set(:@response, self) if result.instance_of?(LabClient::LabStruct)
    result
  end
end

#responseObject

Shim for CurlHelper



81
82
83
# File 'lib/labclient/http.rb', line 81

def response
  self
end