ludo-roart 0.1.13 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +20 -0
- data/lib/roart/core/hash.rb +9 -15
- data/lib/roart/ticket.rb +17 -3
- data/roart.gemspec +2 -2
- data/spec/roart/core/hash_spec.rb +30 -22
- data/spec/roart/ticket_spec.rb +39 -1
- metadata +5 -8
- data/lib/roart/core/content_formatter.rb +0 -12
data/README.rdoc
CHANGED
@@ -68,6 +68,26 @@ If you are using Best Practical's Request Tracker (RT) and you need to interact
|
|
68
68
|
ticket = Ticket.find(23452)
|
69
69
|
ticket.comment("This is a lovely Ticket", :time_worked => 45, :cc => 'someone@example.com'))
|
70
70
|
|
71
|
+
* Attachments
|
72
|
+
|
73
|
+
RT REST does support attachments on ticket create and update.
|
74
|
+
Comments have to be used instead.
|
75
|
+
|
76
|
+
Forum link http://www.gossamer-threads.com/lists/rt/users/106049
|
77
|
+
Wiki link http://requesttracker.wikia.com/wiki/REST#Ticket_Attachments
|
78
|
+
|
79
|
+
ticket = Ticket.find(23452)
|
80
|
+
|
81
|
+
# File path
|
82
|
+
ticket.comment("This is a comment", :attachments => "/tmp/filename.txt")
|
83
|
+
|
84
|
+
# Attachment as a file descriptor
|
85
|
+
ticket.comment("This is a comment", :attachments => File.open("/tmp/filename.txt", "rb"))
|
86
|
+
|
87
|
+
# Attachment as a ActionDispatch::Http::UploadedFile instance
|
88
|
+
ticket.comment("This is a comment", :attachments => [params[:attachment_1], params[:attachment_2]])
|
89
|
+
|
90
|
+
|
71
91
|
|
72
92
|
== REQUIREMENTS:
|
73
93
|
|
data/lib/roart/core/hash.rb
CHANGED
@@ -1,23 +1,17 @@
|
|
1
1
|
class Hash
|
2
|
-
|
3
|
-
fields =
|
4
|
-
|
5
|
-
|
6
|
-
next if values.nil?
|
7
|
-
|
8
|
-
key_name =
|
2
|
+
def to_content_format
|
3
|
+
fields = self.map do |key,value|
|
4
|
+
unless value.nil?
|
5
|
+
value = Roart::ContentFormatter.format_string(value.to_s)
|
9
6
|
if key.to_s.match(/^cf_.+/)
|
10
|
-
"CF-#{key.to_s[3..key.to_s.length].gsub(/_/, " ").camelize.humanize}"
|
7
|
+
"CF-#{key.to_s[3..key.to_s.length].gsub(/_/, " ").camelize.humanize}: #{value}"
|
11
8
|
elsif key.to_s.match(/^CF-.+/)
|
12
|
-
"#{key.to_s}"
|
9
|
+
"#{key.to_s}: #{value}"
|
10
|
+
elsif key.to_s.match(/^[a|A]ttachments/)
|
11
|
+
"Attachment: #{value.join(",")}" if value.kind_of?(Array)
|
13
12
|
else
|
14
|
-
"#{key.to_s.camelize}"
|
13
|
+
"#{key.to_s.camelize}: #{value}"
|
15
14
|
end
|
16
|
-
|
17
|
-
values = [values] unless values.is_a?(Array)
|
18
|
-
values.each do |value|
|
19
|
-
value = Roart::ContentFormatter.format_string(value.to_s)
|
20
|
-
fields << "#{key_name}: #{value}"
|
21
15
|
end
|
22
16
|
end
|
23
17
|
content = fields.compact.sort.join("\n")
|
data/lib/roart/ticket.rb
CHANGED
@@ -67,12 +67,27 @@ module Roart
|
|
67
67
|
# Example:
|
68
68
|
# tix = Ticket.find(1000)
|
69
69
|
# tix.comment("This is a comment", :time_worked => 45, :cc => 'someone@example.com')
|
70
|
+
#
|
71
|
+
# Attachments
|
72
|
+
# tix.comment("This is a comment", :attachments => "/tmp/filename.txt")
|
73
|
+
#
|
74
|
+
# Attachment as a file descriptor
|
75
|
+
# tix.comment("This is a comment", :attachments => File.open("/tmp/filename.txt", "rb"))
|
76
|
+
#
|
77
|
+
# Attachment as a ActionDispatch::Http::UploadedFile instance
|
78
|
+
# tix.comment("This is a comment", :attachments => [params[:attachment_1], params[:attachment_2]])
|
79
|
+
#
|
70
80
|
def comment(comment, opt = {})
|
71
81
|
comment = {:text => comment, :action => 'Correspond'}.merge(opt)
|
72
82
|
|
73
83
|
uri = "#{self.class.connection.server}/REST/1.0/ticket/#{self.id}/comment"
|
74
|
-
|
75
|
-
|
84
|
+
|
85
|
+
attachments = Roart::Attachment.detect(comment[:attachments])
|
86
|
+
|
87
|
+
comment.merge!(:attachment => attachments.map(&:name).join(",")) unless attachments.empty?
|
88
|
+
|
89
|
+
resp = self.class.connection.post(uri, {:content => comment.to_content_format}.merge(attachments.to_payload))
|
90
|
+
|
76
91
|
resp = resp.split("\n")
|
77
92
|
raise TicketSystemError, "Ticket Comment Failed" unless resp.first.include?("200")
|
78
93
|
!!resp[2].match(/^# Message recorded/)
|
@@ -96,7 +111,6 @@ module Roart
|
|
96
111
|
uri = "#{self.class.connection.server}/REST/1.0/ticket/new"
|
97
112
|
payload = @attributes.to_content_format
|
98
113
|
resp = self.class.connection.post(uri, :content => payload)
|
99
|
-
|
100
114
|
process_save_response(resp, :create)
|
101
115
|
end
|
102
116
|
|
data/roart.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ludo-roart}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.14"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["PJ Davis"]
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.description = %q{Interface for working with Request Tracker (RT) tickets inspired by ActiveRecord.}
|
11
11
|
s.email = %q{pj.davis@gmail.com}
|
12
12
|
s.extra_rdoc_files = ["History.txt", "README.rdoc", "spec/test_data/full_history.txt", "spec/test_data/search_ticket.txt", "spec/test_data/single_history.txt", "spec/test_data/ticket.txt"]
|
13
|
-
s.files = ["History.txt", "README.rdoc", "Rakefile", "lib/roart.rb", "lib/roart/callbacks.rb", "lib/roart/connection.rb", "lib/roart/connection_adapter.rb", "lib/roart/connection_adapters/mechanize_adapter.rb", "lib/roart/core/hash.rb", "lib/roart/
|
13
|
+
s.files = ["History.txt", "README.rdoc", "Rakefile", "lib/roart.rb", "lib/roart/callbacks.rb", "lib/roart/connection.rb", "lib/roart/connection_adapter.rb", "lib/roart/connection_adapters/mechanize_adapter.rb", "lib/roart/core/hash.rb", "lib/roart/errors.rb", "lib/roart/history.rb", "lib/roart/roart.rb", "lib/roart/ticket.rb", "lib/roart/ticket_page.rb", "lib/roart/validations.rb", "roart.gemspec", "spec/roart/callbacks_spec.rb", "spec/roart/connection_adapter_spec.rb", "spec/roart/connection_spec.rb", "spec/roart/core/hash_spec.rb", "spec/roart/history_spec.rb", "spec/roart/roart_spec.rb", "spec/roart/ticket_page_spec.rb", "spec/roart/ticket_spec.rb", "spec/roart/validation_spec.rb", "spec/roart_spec.rb", "spec/spec_helper.rb", "spec/test_data/full_history.txt", "spec/test_data/search_ticket.txt", "spec/test_data/single_history.txt", "spec/test_data/ticket.txt"]
|
14
14
|
s.homepage = %q{http://github.com/pjdavis/roart}
|
15
15
|
s.rdoc_options = ["--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
@@ -2,31 +2,39 @@ require File.join(File.dirname(__FILE__), %w[ .. .. spec_helper])
|
|
2
2
|
|
3
3
|
describe 'hash extentions' do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it 'should handel custom fields' do
|
12
|
-
payload = {:cf_stuff => 'field'}
|
13
|
-
payload.to_content_format.should == "CF-Stuff: field"
|
14
|
-
end
|
5
|
+
describe "#to_content_format" do
|
6
|
+
it 'should format the content correctly' do
|
7
|
+
payload = {:subject => "A New Ticket", :queue => 'My Queue'}
|
8
|
+
payload.to_content_format.include?("Subject: A New Ticket").should be_true
|
9
|
+
payload.to_content_format.include?("Queue: My Queue").should be_true
|
10
|
+
end
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
it 'should handel custom fields' do
|
13
|
+
payload = {:cf_stuff => 'field'}
|
14
|
+
payload.to_content_format.should == "CF-Stuff: field"
|
15
|
+
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
it 'should NOT change custom key when it starts with CF-' do
|
18
|
+
payload = { 'CF-My CustomField wiTout magic' => 'hello' }
|
19
|
+
payload.to_content_format.should == "CF-My CustomField wiTout magic: hello"
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should use our content formatter for strings' do
|
23
|
+
payload = {:subject => 'A new ticket', :queue => 'My queue', :text => "A text"}
|
24
|
+
Roart::ContentFormatter.should_receive(:format_string).at_least(:once)
|
25
|
+
payload.to_content_format
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not include attachments into content" do
|
29
|
+
payload = {:subject => 'A new ticket', :queue => 'My queue', :text => "A text", :attachments => '/dev/null'}
|
30
|
+
payload.to_content_format.should_not include("Attachment")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should not include attachments into content" do
|
34
|
+
payload = {:subject => 'A new ticket', :queue => 'My queue', :text => "A text", :attachment => '/dev/null,/dev/zero'}
|
35
|
+
payload.to_content_format.should include("Attachment")
|
36
|
+
end
|
26
37
|
|
27
|
-
it "should return sorted data with the same key multiple times when value is array" do
|
28
|
-
payload = { 'CF-My Day' => %w(Tue Wed Fri), 'CF-My Time' => %w(morning evening) }
|
29
|
-
payload.to_content_format.should == "CF-My Day: Fri\nCF-My Day: Tue\nCF-My Day: Wed\nCF-My Time: evening\nCF-My Time: morning"
|
30
38
|
end
|
31
39
|
|
32
40
|
end
|
data/spec/roart/ticket_spec.rb
CHANGED
@@ -549,5 +549,43 @@ describe "Ticket" do
|
|
549
549
|
end
|
550
550
|
|
551
551
|
end
|
552
|
-
|
552
|
+
|
553
|
+
describe ".comment" do
|
554
|
+
before do
|
555
|
+
@ticket_file = File.expand_path("ticket.txt", File.dirname(__FILE__) + "../../test_data")
|
556
|
+
@lorem_file = File.expand_path("lorem.txt", File.dirname(__FILE__) + "../../test_data")
|
557
|
+
@connection = mock('connection', :server => "localhost", :get => IO.read(@ticket_file))
|
558
|
+
end
|
559
|
+
|
560
|
+
it "should add comment into POST request" do
|
561
|
+
@connection.should_receive(:post).with do |uri, payload|
|
562
|
+
payload.should have_key(:content)
|
563
|
+
payload[:content].should include("Text: test comment")
|
564
|
+
end.and_return("RT/4.0.5 200 Ok\n\n# Message recorded\n\n")
|
565
|
+
|
566
|
+
Roart::Ticket.stub(:connection).and_return(@connection)
|
567
|
+
|
568
|
+
@ticket = Roart::Ticket.find(11111)
|
569
|
+
|
570
|
+
@ticket.comment("test comment")
|
571
|
+
end
|
572
|
+
|
573
|
+
it "should add attachment into POST request" do
|
574
|
+
@connection.should_receive(:post).with do |uri, payload|
|
575
|
+
payload.should have_key(:content)
|
576
|
+
payload[:content].should include("Attachment: lorem.txt")
|
577
|
+
|
578
|
+
payload.should have_key("attachment_1")
|
579
|
+
payload["attachment_1"].should be_a(File)
|
580
|
+
end.and_return("RT/4.0.5 200 Ok\n\n# Message recorded\n\n")
|
581
|
+
|
582
|
+
Roart::Ticket.stub(:connection).and_return(@connection)
|
583
|
+
|
584
|
+
@ticket = Roart::Ticket.find(11111)
|
585
|
+
|
586
|
+
@ticket.comment("test comment", :attachments => @lorem_file)
|
587
|
+
end
|
588
|
+
|
589
|
+
end
|
590
|
+
|
553
591
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ludo-roart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 14
|
10
|
+
version: 0.1.14
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- PJ Davis
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-15 00:00:00
|
19
|
-
default_executable:
|
18
|
+
date: 2010-09-15 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: mechanize
|
@@ -89,7 +88,6 @@ files:
|
|
89
88
|
- lib/roart/connection_adapter.rb
|
90
89
|
- lib/roart/connection_adapters/mechanize_adapter.rb
|
91
90
|
- lib/roart/core/hash.rb
|
92
|
-
- lib/roart/core/content_formatter.rb
|
93
91
|
- lib/roart/errors.rb
|
94
92
|
- lib/roart/history.rb
|
95
93
|
- lib/roart/roart.rb
|
@@ -112,7 +110,6 @@ files:
|
|
112
110
|
- spec/test_data/search_ticket.txt
|
113
111
|
- spec/test_data/single_history.txt
|
114
112
|
- spec/test_data/ticket.txt
|
115
|
-
has_rdoc: true
|
116
113
|
homepage: http://github.com/pjdavis/roart
|
117
114
|
licenses: []
|
118
115
|
|
@@ -143,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
140
|
requirements: []
|
144
141
|
|
145
142
|
rubyforge_project: roart
|
146
|
-
rubygems_version: 1.
|
143
|
+
rubygems_version: 1.8.15
|
147
144
|
signing_key:
|
148
145
|
specification_version: 3
|
149
146
|
summary: Interface for working with Request Tracker (RT) tickets inspired by ActiveRecord
|
@@ -1,12 +0,0 @@
|
|
1
|
-
module Roart
|
2
|
-
class ContentFormatter
|
3
|
-
# The following is only based on quick trial&error on my part. The RT Api (at least in 3.6) does not have good documentation.
|
4
|
-
# Strings in a RT request:
|
5
|
-
# - are not allowed to contain '\r'
|
6
|
-
# - must use equally padded new-lines to distinguish them from the beginning of a new field (we use 2-space padding)
|
7
|
-
def self.format_string(string)
|
8
|
-
string.gsub("\r", '').gsub("\n", "\n ")
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
end
|