Class: IContact::Response

Inherits:
Object
  • Object
show all
Includes:
ActiveAttr::BasicModel
Defined in:
lib/i_contact/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resp) ⇒ Response



9
10
11
12
13
14
15
16
17
# File 'lib/i_contact/response.rb', line 9

def initialize(resp)
  @parsed_response = JSON.parse(resp.body)
  if resp.status != 200
    @errors = ["Server responded with a #{resp.status}: #{resp.body}"]
  else
    @errors = @parsed_response['errors'] || []
    @warnings = @parsed_response['warnings'] || []
  end
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/i_contact/response.rb', line 5

def errors
  @errors
end

#parsed_responseObject (readonly)

Returns the value of attribute parsed_response.



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

def parsed_response
  @parsed_response
end

#warningsObject (readonly)

Returns the value of attribute warnings.



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

def warnings
  @warnings
end

Instance Method Details

#valid?Boolean



19
20
21
# File 'lib/i_contact/response.rb', line 19

def valid?
  errors.size == 0
end