Class: ContactAttribute

Inherits:
LogicalModel
  • Object
show all
Extended by:
CustomKeys
Defined in:
app/models/contact_attribute.rb,
app/models/contact_attribute/custom_keys.rb

Defined Under Namespace

Modules: CustomKeys

Constant Summary collapse

AVAILABLE_TYPES =
%w(telephone email identification address date_attribute custom_attribute social_network_id occupation)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CustomKeys

async_custom_keys, custom_keys

Instance Attribute Details

#primaryObject

Returns the value of attribute primary.



8
9
10
# File 'app/models/contact_attribute.rb', line 8

def primary
  @primary
end

#publicObject

Returns the value of attribute public.



8
9
10
# File 'app/models/contact_attribute.rb', line 8

def public
  @public
end

Instance Method Details

#_create(params = {}) ⇒ Object

creates model. Override to set the primary boolean based on what is returned from the service TODO this could be done in an after_create



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/models/contact_attribute.rb', line 53

def _create(params = {})
  return false unless valid?

  params = { self.json_root => self.attributes }.merge(params)
  params = self.class.merge_key(params)

  response = nil

  Timeout::timeout(self.class.timeout/1000) do
    response = Typhoeus::Request.post( self.class.resource_uri, :params => params, :timeout => self.class.timeout )
  end
  if response.code == 201
    log_ok(response)
    self.id = ActiveSupport::JSON.decode(response.body)["id"]
    #Set as primary according to json returned from service
    self.primary = ActiveSupport::JSON.decode(response.body)["primary"]
    return true
  elsif response.code == 400
    log_failed(response)
    ws_errors = ActiveSupport::JSON.decode(response.body)["errors"]
    ws_errors.each_key do |k|
      self.errors.add k, ws_errors[k]
    end
    return false
  else
    log_failed(response)
    return nil
  end
rescue Timeout::Error
  self.class.logger.warn "timeout"
  return nil
end

#always_public?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/contact_attribute.rb', line 29

def always_public?
  false
end

#idObject



41
42
43
# File 'app/models/contact_attribute.rb', line 41

def id
  self._id
end

#id=(id) ⇒ Object



45
46
47
# File 'app/models/contact_attribute.rb', line 45

def id= id
  self._id = id
end

#json_rootObject



33
34
35
# File 'app/models/contact_attribute.rb', line 33

def json_root
  :contact_attribute
end

#new_record?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'app/models/contact_attribute.rb', line 25

def new_record?
  self._id.blank?
end

#to_keyObject



37
38
39
# File 'app/models/contact_attribute.rb', line 37

def to_key
  [self._id]
end