Class: TempoIQ::HttpResult

Inherits:
Object
  • Object
show all
Defined in:
lib/tempoiq/remoter/http_result.rb

Constant Summary collapse

OK =
200
MULTI =
207
BAD_REQUEST =
400
UNAUTHORIZED =
401
NOT_FOUND =
404
UNPROCESSABLE =
422
INTERNAL =
500

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, headers, body) ⇒ HttpResult

Returns a new instance of HttpResult.



24
25
26
27
28
# File 'lib/tempoiq/remoter/http_result.rb', line 24

def initialize(code, headers, body)
  @code = code
  @headers = headers
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



22
23
24
# File 'lib/tempoiq/remoter/http_result.rb', line 22

def body
  @body
end

#codeObject (readonly)

Returns the value of attribute code.



22
23
24
# File 'lib/tempoiq/remoter/http_result.rb', line 22

def code
  @code
end

#headersObject (readonly)

Returns the value of attribute headers.



22
23
24
# File 'lib/tempoiq/remoter/http_result.rb', line 22

def headers
  @headers
end

Instance Method Details

#on_success(&block) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/tempoiq/remoter/http_result.rb', line 30

def on_success(&block)
  if success?
    yield self
  else
    raise HttpException.new(self), "HTTP returned non-success response: #{code}, #{body}"
  end
end

#success?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/tempoiq/remoter/http_result.rb', line 38

def success?
  code / 100 == 2
end