class TicketMaster::Provider::Rally::Comment

The comment class for ticketmaster-rally

Remaps

id => oid author => user_name body => text created_at => creation_date updated_at => creation_date

Public Class Methods

create(*options) click to toggle source
# File lib/provider/comment.rb, line 82
def self.create(*options)
  options = options.shift
  project = provider_parent(self)::Project.find_by_id(options[:project_id])
  ticket = provider_parent(self)::Ticket.find_by_id(options[:project_id], options[:ticket_id])
  comment = {
    :project => project.system_data[:client],
    :artifact => ticket.system_data[:client],
    :text => options[:body]
  }
  new_comment = TicketMaster::Provider::Rally.rally.create(:conversation_post, comment)
  self.new new_comment
end
find_by_attributes(project_id, ticket_id, attributes = {}) click to toggle source

Accepts a project id, ticket id and attributes hash and returns all comments matching the project, ticket and those attributes in an array Should return all ticket comments if the attributes hash is empty

# File lib/provider/comment.rb, line 67
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) click to toggle source
# File lib/provider/comment.rb, line 56
def self.find_by_id(project_id, ticket_id, id)
  project = self.rally_project(project_id)
  # Rally Ruby REST API expects IDs as strings
  # For id.to_s see note on Project::id
  query_result = TicketMaster::Provider::Rally.rally.find(:conversation_post, :fetch => false, :project => project) { equal :object_i_d, id.to_s }
  self.new query_result.first, project_id
end
new(*object) click to toggle source
Calls superclass method
# File lib/provider/comment.rb, line 14
def initialize(*object)
  if object.first
    args = object
    comment = args.shift
    project_id = args.shift
    ticket_id = args.shift
    @system_data = {:client => comment}
    hash = {
      :oid         => comment.oid,
      :project_id  => project_id,
      :ticket_id   => ticket_id,
      :author      => comment.user_name,
      :body        => comment.text,
      :created_at  => comment.creation_date,
      :updated_at  => comment.creation_date,
      :post_number => comment.post_number,
    }
    super(hash)
  end
end

Private Class Methods

rally_project(project_id) click to toggle source
# File lib/provider/comment.rb, line 97
def self.rally_project(project_id)
  ticketmaster_project = provider_parent(self)::Project.find_by_id(project_id)
  ticketmaster_project.system_data[:client]
end
to_rally_object(hash) click to toggle source
# File lib/provider/comment.rb, line 102
def self.to_rally_object(hash)
  ticket = {
    :name => hash[:title],
    :description => hash[:description],
    :schedule_state => hash[:resolution] ||= "Defined", 
    :state => hash[:status] ||= "Submitted"     
  }
  # Rally optional attributes
  ticket[:submitted_by] = hash[:requestor] if hash[:requestor]
  ticket[:owner] = hash[:assignee] if hash[:assignee]
  ticket[:priority] = hash[:priority] if hash[:priority]
  ticket[:work_product] = hash[:work_product] if hash[:work_product]
  ticket          
end

Public Instance Methods

created_at() click to toggle source
# File lib/provider/comment.rb, line 35
def created_at
  Time.parse(self[:created_at])
end
id() click to toggle source

Rally REST API aliases String and Fixnum :to_q :to_s However, it does not alias Bignum If a ID is a Bignum, the API will throw undefined method Because of this, we pass all IDs to API as strings Ticketmaster specs set IDs as integers, so coerce type on get

# File lib/provider/comment.rb, line 48
def id
  self[:oid].to_i
end
id=(id) click to toggle source
# File lib/provider/comment.rb, line 52
def id=(id)
  self[:oid] = id.to_s
end
updated_at() click to toggle source
# File lib/provider/comment.rb, line 39
def updated_at
  Time.parse(self[:updated_at])
end