Class: Comment

Inherits:
Services show all
Defined in:
lib/jirarest2/services/comment.rb

Overview

Work with all the comments that an issue might have

Instance Method Summary collapse

Methods inherited from Services

#delete, #post, #put

Constructor Details

#initialize(connection, issueid, commentid = nil) ⇒ Comment

Set our uritail

Parameters:

  • connection (Connection)
  • issueid (String)

    The id or key of the issue in question



63
64
65
66
67
68
69
70
# File 'lib/jirarest2/services/comment.rb', line 63

def initialize(connection, issueid, commentid = nil)
  if commentid then
    @uritail = "issue/#{issueid}/comment/#{commentid}"
  else
    @uritail = "issue/#{issueid}/comment"
  end
  super(connection)
end

Instance Method Details

#add(text) ⇒ Result

Add a comment to an issue

Parameters:

  • text (String)

    to add

Returns:

  • (Result)

    The result as constructed by Connection.execute



75
76
77
# File 'lib/jirarest2/services/comment.rb', line 75

def add(text)
  post({"body" => text})
end

#get(data = "") ⇒ Nil, Array(CommentElement)

Get a certain comment

Parameters:

  • data (String) (defaults to: "")

    Additional data to send via GET

Returns:

  • (Nil)

    If there is no comment in the Project

  • (Array(CommentElement))

    If there is one or more than one result - TODO See if this is going to be changed for a special type that keeps startAt, maxResults and total



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/jirarest2/services/comment.rb', line 96

def get(data = "")
  result = super("")
  if result["comments"].nil? then
    return [create_element(result)]
  elsif result["comments"].empty? then
    return nil
  else
    resultarray = Array.new
    result["comments"].each { |singleresult|
       resultarray << create_element(singleresult)
    }
    return resultarray
  end
end

#update(text) ⇒ CommentElement

Update an comment

Parameters:

  • text (String)

    The new text for the comment

Returns:



114
115
116
117
# File 'lib/jirarest2/services/comment.rb', line 114

def update(text)
  result =  put({"body" => text})
  return CommentElement.new(result["updateAuthor"]["displayName"], result["body"], result["created"], result["updated"])
end