Class: Spectre::Curl::SpectreHttpResponse
Instance Method Summary collapse
- #body ⇒ Object
- #code ⇒ Object
- #headers ⇒ Object
-
#initialize(res) ⇒ SpectreHttpResponse
constructor
A new instance of SpectreHttpResponse.
- #json ⇒ Object
- #message ⇒ Object
- #pretty ⇒ Object
- #protocol ⇒ Object
- #success? ⇒ Boolean
- #version ⇒ Object
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
#body ⇒ Object
111 112 113 |
# File 'lib/spectre/curl.rb', line 111 def body @res[:body] end |
#code ⇒ Object
91 92 93 |
# File 'lib/spectre/curl.rb', line 91 def code @res[:code] end |
#headers ⇒ Object
107 108 109 |
# File 'lib/spectre/curl.rb', line 107 def headers SpectreHttpHeader.new @res[:headers] end |
#json ⇒ Object
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 |
#message ⇒ Object
95 96 97 |
# File 'lib/spectre/curl.rb', line 95 def @res[:message] end |
#pretty ⇒ Object
133 134 135 |
# File 'lib/spectre/curl.rb', line 133 def pretty @res.pretty end |
#protocol ⇒ Object
99 100 101 |
# File 'lib/spectre/curl.rb', line 99 def protocol @res[:protocol] end |
#success? ⇒ Boolean
129 130 131 |
# File 'lib/spectre/curl.rb', line 129 def success? @res[:code] < 400 end |
#version ⇒ Object
103 104 105 |
# File 'lib/spectre/curl.rb', line 103 def version @res[:version] end |