Module: Intercom::ApiOperations::Save

Included in:
Company, Contact, Conversation, Event, Message, Note, Segment, Subscription, Tag, User
Defined in:
lib/intercom/api_operations/save.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



22
23
24
# File 'lib/intercom/api_operations/save.rb', line 22

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#identity_hashObject



36
37
38
# File 'lib/intercom/api_operations/save.rb', line 36

def identity_hash
  respond_to?(:identity_vars) ? SliceableHash.new(to_hash).slice(*(identity_vars.map(&:to_s))) : {}
end

#saveObject



26
27
28
29
30
31
32
33
34
# File 'lib/intercom/api_operations/save.rb', line 26

def save
  collection_name = Utils.resource_class_to_collection_name(self.class)
  if id_present? && !posted_updates?
    response = Intercom.put("/#{collection_name}/#{id}", to_submittable_hash)
  else
    response = Intercom.post("/#{collection_name}", to_submittable_hash.merge(identity_hash))
  end
  from_response(response) if response # may be nil we received back a 202
end