Sha256: 5d9cfe7eb4b00a01f53f6cc0d4fcb6ae203503bfcbf7019119badc36c8afc16b

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

module TaskMapper::Provider
  module Zendesk
    # The comment class for taskmapper-zendesk
    #
    # Do any mapping between taskmapper and your system's comment model here
    # versions of the ticket.
    #
    class Comment < TaskMapper::Provider::Base::Comment
      # declare needed overloaded methods here

      USER_API = ZendeskAPI::User

      def initialize(*object)
        @system_data = {}
        @cache = {}
        first = object.shift
        case first
        when Hash
          super first.to_hash
        else
          @system_data[:client] = first
          super first.attributes
        end
      end

      def author
        USER_API.find(comment.author_id).email
      end

      def id
        self.comment_id
      end

      def created_at
        Time.parse(self[:created_at])
      end

      def updated_at
        Time.parse(self[:updated_at])
      end

      class << self
        def search(project_id, ticket_id, options = {}, limit = 1000)
          comment_id = 0
          ZendeskAPI::Ticket.find(ticket_id).comments.collect do |comment|
            comment_id += 1
            self.new comment.attributes.merge!(:project_id => project_id,
                                               :ticket_id => ticket_id,
                                               :comment_id => comment_id)
          end
        end

        def find_by_id(project_id, ticket_id, id) 
          search(project_id, ticket_id).find { |ticket| ticket.id == id } 
        end

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
taskmapper-zendesk-0.7.0 lib/provider/comment.rb
taskmapper-zendesk-0.6.0 lib/provider/comment.rb
taskmapper-zendesk-0.5.1 lib/provider/comment.rb