Class: TaskMapper::Provider::Basecamp::Comment

Inherits:
TaskMapper::Provider::Base::Comment
  • Object
show all
Defined in:
lib/provider/comment.rb

Overview

The comment class for taskmapper-basecamp

Do any mapping between taskmapper and your system’s comment model here versions of the ticket.

Constant Summary collapse

API =

declare needed overloaded methods here

::Basecamp::Comment

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*object) ⇒ Comment

Returns a new instance of Comment.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/provider/comment.rb', line 12

def initialize(*object)
  if object.first
    object = object.first
    unless object.is_a? Hash
      hash = {:id => object.id,
        :body => object.body,
        :author => object.author_name,
        :created_at => object.created_at,
        :project_id => object.project_id,
        :ticket_id => object.ticket_id}
    else
      hash = object
    end
    super hash
  end
end

Class Method Details

.create(ticket_id, attributes) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/provider/comment.rb', line 43

def self.create(ticket_id, attributes)
  new_comment = API.new attributes.merge(:todo_item_id => ticket_id)
  new_comment.save

  reloaded_comment = find_bc_comment(ticket_id, new_comment.id)
  self.new reloaded_comment.attributes.merge!(:ticket_id => ticket_id) 
end

.find_by_attributes(project_id, ticket_id, attributes = {}) ⇒ Object



34
35
36
# File 'lib/provider/comment.rb', line 34

def self.find_by_attributes(project_id, ticket_id, attributes = {})
  self.search(project_id, ticket_id, attributes)
end

.find_by_id(project_id, ticket_id, id) ⇒ Object



29
30
31
32
# File 'lib/provider/comment.rb', line 29

def self.find_by_id(project_id, ticket_id, id)
  basecamp_comment = self::API.find(id, :params => {:todo_item_id => ticket_id})
  self.new basecamp_comment.attributes.merge!(:project_id => project_id, :ticket_id => ticket_id)
end

.search(project_id, ticket_id, options = {}, limit = 1000) ⇒ Object



38
39
40
41
# File 'lib/provider/comment.rb', line 38

def self.search(project_id, ticket_id, options = {}, limit = 1000)
  comments = API.find(:all, :params => {:todo_item_id => ticket_id}).collect {|c| self.new(c.attributes.merge!(:project_id => project_id, :ticket_id => ticket_id)) }
  search_by_attribute(comments, options, limit)
end

Instance Method Details

#saveObject



51
52
53
54
55
# File 'lib/provider/comment.rb', line 51

def save
  bc_comment = self.class.find_bc_comment ticket_id, id
  bc_comment.body = self.body
  bc_comment.save
end