Class: ContactsMerge

Inherits:
LogicalModel
  • Object
show all
Defined in:
app/models/contacts_merge.rb

Instance Method Summary collapse

Instance Method Details

#json_rootObject



19
20
21
# File 'app/models/contacts_merge.rb', line 19

def json_root
  'merge'
end

#last_create_message_hashHash

Returns a Hash with the message corresponding to last create result

Examples:

{ alert: ‘error’ }

{ notice: ‘success’ }

Returns:

  • (Hash)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/contacts_merge.rb', line 28

def last_create_message_hash
  case self.last_response_code
    when 400
      if self.errors.keys.include?(:similarity_of_contacts)
        {alert: I18n.t('contacts_merge.not_similar')}
      else
        {alert: self.errors.messages}
      end
    when 401
      {alert: I18n.t('contacts_merge.not_allowed', more: "[<a href='http://www.padma-support.com.ar/blog/n%C4%81o-tenho-permiss%C5%8Des-para-fundir-contatos' target='_blank'>?</a>]").html_safe}
    when 201
      {notice: I18n.t('contacts_merge.merged')}
    when 202
      case self.state
        when 'pending_confirmation'
          {notice: I18n.t('contacts_merge.pending_confirmation_of_admin')}
        else
          {notice: I18n.t('contacts_merge.started')}
      end
    else
      {alert: I18n.t('contacts.communication_failure')}
  end
end