Class: RedHatSupportLib::Brokers::Comment

Inherits:
Broker
  • Object
show all
Defined in:
lib/brokers/comment.rb

Instance Attribute Summary

Attributes inherited from Broker

#connection

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Comment

Returns a new instance of Comment.



4
5
6
# File 'lib/brokers/comment.rb', line 4

def initialize(connection)
  super
end

Instance Method Details

#add(text, case_number, is_draft, is_public = true) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/brokers/comment.rb', line 32

def add(text, case_number, is_draft, is_public=true)
  headers = {:content_type => 'application/xml'}
  data = create_comment(text, case_number, is_draft, is_public)
  result = @connection.post("/rs/cases/#{case_number}/comments", data, headers) do |code, headers|
    if code == 201
      location = headers[:location]
      return get_id(location)
    end
  end
end

#create_comment(comment, case_number, is_draft, is_public = true) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/brokers/comment.rb', line 43

def create_comment(comment, case_number, is_draft, is_public=true)
  #for now use xml version
  filter = StringIO.new
  filter << '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
  filter << '<tns:comment xmlns:tns="http://www.redhat.com/gss/strata"' << " caseNumber=\"#{case_number}\">"
  filter << "<tns:text>#{comment}</tns:text>"
  if is_public
    filter << "<tns:public>true</tns:public>"
  else
    filter << "<tns:public>false</tns:public>"
  end
  if is_draft
    filter << "<tns:draft>true</tns:draft>"
  else
    filter << "<tns:draft>false</tns:draft>"
  end
  filter << "</tns:comment>"
  filter.string
end

#get(case_number, comment_id) ⇒ Object



8
9
10
11
12
13
# File 'lib/brokers/comment.rb', line 8

def get(case_number, comment_id)
  #TODO check params
  params =[];
  result = @connection.get("/rs/cases/#{case_number}/comments/#{comment_id}",
                           {:accept => :json})
end

#get_id(uri) ⇒ Object



63
64
65
66
# File 'lib/brokers/comment.rb', line 63

def get_id(uri)
  parts = uri.split("/")
  parts.pop
end

#list(case_number, start_date, end_date, filter = []) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/brokers/comment.rb', line 15

def list(case_number, start_date, end_date, filter=[])

  uri = "/rs/cases/#{case_number}/comments"
  param = ''
  if start_date
    param = "?startDate=#{start_date}"
  end
  if end_date
    if start_date
      param = param + "&endDate=#{end_date}"
    else
      param = param + "?endDate=#{end_date}"
    end
  end
  result = @connection.get(uri+param, {:accept => :json})
end