Class: ContactAttribute
- Inherits:
-
LogicalModel
- Object
- LogicalModel
- ContactAttribute
- Extended by:
- CustomKeys
- Defined in:
- app/models/contact_attribute.rb,
app/models/contact_attribute/custom_keys.rb
Direct Known Subclasses
Address, CustomAttribute, DateAttribute, Email, Identification, Occupation, SocialNetworkId, Telephone
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
-
#primary ⇒ Object
Returns the value of attribute primary.
-
#public ⇒ Object
Returns the value of attribute public.
Instance Method Summary collapse
-
#_create(params = {}) ⇒ Object
creates model.
- #always_public? ⇒ Boolean
- #id ⇒ Object
- #id=(id) ⇒ Object
- #json_root ⇒ Object
- #new_record? ⇒ Boolean
- #to_key ⇒ Object
Methods included from CustomKeys
async_custom_keys, custom_keys
Instance Attribute Details
#primary ⇒ Object
Returns the value of attribute primary.
8 9 10 |
# File 'app/models/contact_attribute.rb', line 8 def primary @primary end |
#public ⇒ Object
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
29 30 31 |
# File 'app/models/contact_attribute.rb', line 29 def always_public? false end |
#id ⇒ Object
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_root ⇒ Object
33 34 35 |
# File 'app/models/contact_attribute.rb', line 33 def json_root :contact_attribute end |
#new_record? ⇒ Boolean
25 26 27 |
# File 'app/models/contact_attribute.rb', line 25 def new_record? self._id.blank? end |
#to_key ⇒ Object
37 38 39 |
# File 'app/models/contact_attribute.rb', line 37 def to_key [self._id] end |