Class: Crm::Activity

Overview

A JustRelate WebCRM activity is a record of an action or a sequence of actions, for example a support case. It can be associated with an account or a contact.

Comments

Comments can be read be means of #comments. In order to add a comment, set the following write-only attributes on Activity.create or #update:

  • comment_notes (String) - the comment text.

  • comment_contact_id (String) - the contact ID of the comment author (optional).

  • comment_published (Boolean) - whether the comment should be visible to the associated contact of this activity (item.contact_id). Default: false.

  • comment_attachments (Array<String, #read>) - the comment attachments (optional). Every array element may either be an attachment ID or an object that implements #read (e.g. an open file). In the latter case, the content will be uploaded automatically. See Core::AttachmentStore for manually uploading attachments.

Defined Under Namespace

Classes: Comment

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Core::Mixins::Findable::ClassMethods

find

Methods included from Core::Mixins::Modifiable::ClassMethods

create

Methods included from Core::Mixins::Searchable::ClassMethods

all, first, query, search_configurator, where, where_not

Methods included from Core::Mixins::Inspectable

#inspect

Methods included from Core::Mixins::ChangeLoggable

#changes

Methods included from Core::Mixins::Modifiable

#delete

Methods inherited from Core::BasicResource

base_type, #eql?, #id, path, #path, #reload, resource_name, #type

Methods included from Core::Mixins::AttributeProvider

#[], #attributes, #initialize, #method_missing, #methods, #raw, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Crm::Core::Mixins::AttributeProvider

Instance Attribute Details

#commentsArray<Comment> (readonly)

Returns the comments of this activity.

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/crm/activity.rb', line 118

def self.filter_attributes(attributes)
  attachments = attributes.delete('comment_attachments') ||
      attributes.delete(:comment_attachments)
  if attachments
    attributes['comment_attachments'] = attachments.map do |attachment|
      if attachment.respond_to?(:read)
        Core::AttachmentStore.upload(attachment)
      else
        attachment
      end
    end
  end
  attributes
end

Class Method Details

.create(attributes = {}) ⇒ self

Creates a new activity using the given params. See Modifiable.create for details.

Returns:

  • (self)

    the created activity.



35
36
37
# File 'lib/crm/activity.rb', line 35

def self.create(attributes = {})
  super(filter_attributes(attributes))
end

.filter_attributes(attributes) ⇒ Array<Comment>

Returns the comments of this activity.

Returns:



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/crm/activity.rb', line 118

def self.filter_attributes(attributes)
  attachments = attributes.delete('comment_attachments') ||
      attributes.delete(:comment_attachments)
  if attachments
    attributes['comment_attachments'] = attachments.map do |attachment|
      if attachment.respond_to?(:read)
        Core::AttachmentStore.upload(attachment)
      else
        attachment
      end
    end
  end
  attributes
end

Instance Method Details

#update(attributes = {}) ⇒ self

Updates the attributes of this activity. See Modifiable#update for details.

Returns:

  • (self)

    the updated activity.



43
44
45
# File 'lib/crm/activity.rb', line 43

def update(attributes = {})
  super(self.class.filter_attributes(attributes))
end