Method: Mautic::ValidationError#initialize

Defined in:
lib/mautic.rb

#initialize(response, message = nil) ⇒ ValidationError

Returns a new instance of ValidationError.



37
38
39
40
41
42
43
# File 'lib/mautic.rb', line 37

def initialize(response, message = nil)
  @response = response
  json_body = JSON.parse(response.body) rescue {}
  @errors = Array(json_body['errors']).inject({}) { |mem, var| mem.merge!(var['details']); mem }
  message ||= @errors.collect { |field, msg| "#{field}: #{msg.join(', ')}" }.join('; ')
  super(response, message)
end