Class: MOCO::Comment
- Inherits:
-
BaseEntity
- Object
- BaseEntity
- MOCO::Comment
- Defined in:
- lib/moco/entities/comment.rb
Overview
Represents a MOCO comment/note (Notizen) Comments can be attached to various entities
Required attributes for create:
commentable_id - Integer, ID of the entity to attach comment to
commentable_type - String, entity type:
"Project", "Contact", "Company", "Deal", "User", "Unit",
"Invoice", "Offer", "Expense", "Receipt", "Purchase",
"DeliveryNote", "OfferConfirmation", "InvoiceReminder",
"InvoiceDeletion", "InvoiceBookkeepingExport",
"RecurringExpense", "ReceiptRefundRequest",
"PurchaseBookkeepingExport", "PurchaseDraft"
text - String, comment text (plain text or HTML)
Optional attributes:
attachment_filename - String, filename for attachment
attachment_content - String, base64-encoded file content
created_at - String, timestamp for data migration
Read-only attributes:
id, manual, user (Hash - creator), created_at, updated_at
Allowed HTML tags in text:
div, strong, em, u, pre, ul, ol, li, br
Example:
# Add comment to a project
moco.comments.create(
commentable_id: 123,
commentable_type: "Project",
text: "<div>Project kickoff on <strong>Jan 15</strong></div>"
)
Filtering:
moco.comments.where(commentable_type: "Project", commentable_id: 123)
moco.comments.where(user_id: 456)
moco.comments.where(manual: true) # user-created only
Instance Attribute Summary
Attributes inherited from BaseEntity
Class Method Summary collapse
-
.bulk_create(client, comments) ⇒ Array<Comment>
Bulk create comments.
Instance Method Summary collapse
- #to_s ⇒ Object
-
#user ⇒ Object
Associations.
Methods inherited from BaseEntity
#==, #association, #destroy, #eql?, #has_many, #hash, #id, #initialize, #inspect, #reload, #save, #to_h, #to_json, #update
Constructor Details
This class inherits a constructor from MOCO::BaseEntity
Class Method Details
.bulk_create(client, comments) ⇒ Array<Comment>
Bulk create comments
47 48 49 50 |
# File 'lib/moco/entities/comment.rb', line 47 def self.bulk_create(client, comments) response = client.post("comments/bulk", { bulk: comments }) response.map { |data| new(client, data) } end |
Instance Method Details
#to_s ⇒ Object
57 58 59 |
# File 'lib/moco/entities/comment.rb', line 57 def to_s text.to_s.truncate(50) end |
#user ⇒ Object
Associations
53 54 55 |
# File 'lib/moco/entities/comment.rb', line 53 def user association(:user) end |