lib/intercom/api_operations/save.rb in intercom-2.4.4 vs lib/intercom/api_operations/save.rb in intercom-2.5.4

- old
+ new

@@ -3,11 +3,18 @@ module Intercom module ApiOperations module Save module ClassMethods - def create(params) + PARAMS_NOT_PROVIDED = Object.new + def create(params = PARAMS_NOT_PROVIDED) + if self.ancestors.include?(Intercom::Contact) && params == PARAMS_NOT_PROVIDED + params = Hash.new + elsif params == PARAMS_NOT_PROVIDED + raise ArgumentError, '.create requires 1 parameter' + end + instance = self.new(params) instance.mark_fields_as_changed!(params.keys) instance.save end end @@ -24,21 +31,21 @@ 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 + def identity_hash + respond_to?(:identity_vars) ? SliceableHash.new(to_hash).slice(*(identity_vars.map(&:to_s))) : {} + end + private def id_present? id && id.to_s != '' end def posted_updates? respond_to?(:update_verb) && update_verb == 'post' - end - - def identity_hash - respond_to?(:identity_vars) ? SliceableHash.new(to_hash).slice(*(identity_vars.map(&:to_s))) : {} end end end end