app/models/mautic/contact.rb in mautic-2.3.5 vs app/models/mautic/contact.rb in mautic-2.3.6

- old
+ new

@@ -10,16 +10,43 @@ def name "#{firstname} #{lastname}" end + # @param [Hash] hash + # option hash [Integer] :id + # option hash [String] :firstName + # option hash [String] :lastName + def owner=(hash) + raise ArgumentError, "must be a hash !" unless hash.is_a?(Hash) + + @table["owner"] = hash["id"] + @owner = hash + end + + # @return [Hash] + # @example {id: 12, firstName: "Joe", lastName: "Doe"} + def owner + @owner || {} + end + + # Assign mautic User ID as owner - for example for update author of contact + # @see https://developer.mautic.org/#edit-contact set owner + # @param [Integer] int + def owner_id=(int) + @table["owner"] = int + end + def assign_attributes(source = nil) super + if source + self.owner = source['owner'] || {} self.attributes = { tags: (source['tags'] || []).collect { |t| Mautic::Tag.new(@connection, t) }.sort_by(&:name), doNotContact: source['doNotContact'] || [], + owner: owner['id'], } end end def events @@ -30,10 +57,11 @@ # @see https://developer.mautic.org/#add-do-not-contact def do_not_contact? doNotContact.present? end + alias dnc? do_not_contact? # @return [Array[Hash]] def do_not_contact return unless do_not_contact? @@ -62,10 +90,11 @@ self.errors = e.errors end self.errors.blank? end + alias add_dnc do_not_contact! def remove_do_not_contact! begin json = @connection.request(:post, "api/contacts/#{id}/dnc/email/remove", body: {}) @@ -75,9 +104,10 @@ self.errors = e.errors end self.errors.blank? end + alias remove_dnc remove_do_not_contact! # !endgroup private \ No newline at end of file