Class: DruidClient::Api::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/druid_client/api/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code:, body:, headers: {}, duration: nil) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
13
# File 'lib/druid_client/api/response.rb', line 8

def initialize(status_code:, body:, headers: {}, duration: nil)
  @status_code = status_code
  @body = body
  @headers = headers
  @duration = duration
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/druid_client/api/response.rb', line 6

def body
  @body
end

#durationObject (readonly)

Returns the value of attribute duration.



6
7
8
# File 'lib/druid_client/api/response.rb', line 6

def duration
  @duration
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/druid_client/api/response.rb', line 6

def headers
  @headers
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



6
7
8
# File 'lib/druid_client/api/response.rb', line 6

def status_code
  @status_code
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/druid_client/api/response.rb', line 21

def error?
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/druid_client/api/response.rb', line 15

def success?
  return false unless status_code

  (200..299).include?(status_code)
end

#to_sObject



25
26
27
# File 'lib/druid_client/api/response.rb', line 25

def to_s
  "#<Response status_code=#{status_code} duration=#{duration}s>"
end