Class: Dailycred::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
# File 'lib/dailycred/response.rb', line 6

def initialize response
  @body = response.body
  @json = JSON.parse(@body)
  @headers = response.headers
  @status = response.status
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



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

def body
  @body
end

#headersObject

Returns the value of attribute headers.



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

def headers
  @headers
end

#jsonObject

Returns the value of attribute json.



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

def json
  @json
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#errorsObject



21
22
23
24
25
26
27
# File 'lib/dailycred/response.rb', line 21

def errors
  begin
    json["errors"][0]
  rescue
    nil
  end
end

#errors?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/dailycred/response.rb', line 13

def errors?
  json["worked"] != true
end

#success?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/dailycred/response.rb', line 17

def success?
  @status == 200 && json["worked"] == true
end

#userObject



29
30
31
# File 'lib/dailycred/response.rb', line 29

def user
  json["user"]
end