Class: Gooru::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(weary_response) ⇒ Response

Returns a new instance of Response.



6
7
8
9
# File 'lib/gooru/response.rb', line 6

def initialize(weary_response)
  @data = parse(weary_response.body)
  @status = weary_response.status
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/gooru/response.rb', line 3

def data
  @data
end

#statusObject (readonly)

Returns the value of attribute status.



4
5
6
# File 'lib/gooru/response.rb', line 4

def status
  @status
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/gooru/response.rb', line 11

def error?
  has_error_key? ||
  internal_server_error?
end

#error_messageObject



16
17
18
19
20
21
22
23
24
# File 'lib/gooru/response.rb', line 16

def error_message
  if has_error_key?
    data["error"]
  elsif internal_server_error?
    data["status"]
  else
    ""
  end
end

#success?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/gooru/response.rb', line 26

def success?
  !error?
end