Class: Spectre::Curl::SpectreHttpResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/spectre/curl.rb

Instance Method Summary collapse

Constructor Details

#initialize(res) ⇒ SpectreHttpResponse

Returns a new instance of SpectreHttpResponse.



86
87
88
89
# File 'lib/spectre/curl.rb', line 86

def initialize res
  @res = res
  @data = nil
end

Instance Method Details

#bodyObject



111
112
113
# File 'lib/spectre/curl.rb', line 111

def body
  @res[:body]
end

#codeObject



91
92
93
# File 'lib/spectre/curl.rb', line 91

def code
  @res[:code]
end

#headersObject



107
108
109
# File 'lib/spectre/curl.rb', line 107

def headers
  SpectreHttpHeader.new @res[:headers]
end

#jsonObject



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/spectre/curl.rb', line 115

def json
  return nil unless @res[:body]

  if @data == nil
    begin
      @data = JSON.parse(@res[:body], object_class: OpenStruct)
    rescue
      raise 'invalid json'
    end
  end

  @data
end

#messageObject



95
96
97
# File 'lib/spectre/curl.rb', line 95

def message
  @res[:message]
end

#prettyObject



133
134
135
# File 'lib/spectre/curl.rb', line 133

def pretty
  @res.pretty
end

#protocolObject



99
100
101
# File 'lib/spectre/curl.rb', line 99

def protocol
  @res[:protocol]
end

#success?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/spectre/curl.rb', line 129

def success?
  @res[:code] < 400
end

#versionObject



103
104
105
# File 'lib/spectre/curl.rb', line 103

def version
  @res[:version]
end