pjdavis-roart 0.1.1 → 0.1.2
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/History.txt +3 -0
- data/README.rdoc +5 -0
- data/Rakefile +1 -1
- data/lib/roart/connection.rb +4 -0
- data/lib/roart/core/hash.rb +7 -0
- data/lib/roart/ticket.rb +39 -19
- data/lib/roart.rb +1 -1
- data/roart.gemspec +3 -3
- data/spec/roart/core/hash_spec.rb +11 -0
- data/spec/roart/history_spec.rb +1 -0
- data/spec/roart/ticket_spec.rb +30 -0
- metadata +4 -2
data/History.txt
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
==0.1.2 / 2009-08-18
|
2
|
+
Added Create ticket functionality. Ticket.new will create a ticket in the RT system and return that ticket.
|
3
|
+
|
1
4
|
== 0.1.1 / 2009-08-17
|
2
5
|
Added History functionality. #histories now loads an array of history objects into memory and you can access them like you would a regular array. A few connivence methods (last, count) have also been added.
|
3
6
|
|
data/README.rdoc
CHANGED
@@ -45,6 +45,11 @@ If you are using Best Practical's Request Tracker (RT) and you need to interact
|
|
45
45
|
ticket.creator #-> rimmer@reddwarf.com
|
46
46
|
ticket.subject #-> Where is the Bomb?
|
47
47
|
|
48
|
+
* Get history for a ticket
|
49
|
+
|
50
|
+
my_ticket.histories #-> Returns an array of history objects
|
51
|
+
|
52
|
+
|
48
53
|
|
49
54
|
== REQUIREMENTS:
|
50
55
|
|
data/Rakefile
CHANGED
data/lib/roart/connection.rb
CHANGED
data/lib/roart/ticket.rb
CHANGED
@@ -3,18 +3,25 @@ module Roart
|
|
3
3
|
module Tickets
|
4
4
|
|
5
5
|
DefaultAttributes = %w(queue owner creator subject status priority initial_priority final_priority requestors cc admin_cc created starts started due resolved told last_updated time_estimated time_worked time_left full logs)
|
6
|
-
RequiredAttributes = %w(queue
|
6
|
+
RequiredAttributes = %w(queue subject)
|
7
7
|
|
8
8
|
end
|
9
9
|
|
10
10
|
class Ticket
|
11
11
|
|
12
12
|
include Roart::MethodFunctions
|
13
|
-
|
13
|
+
|
14
|
+
# Creates a new ticket. Attributes queue and subject are required. Expects a hash with the attributes of the ticket.
|
15
|
+
#
|
16
|
+
# ticket = MyTicket.new(:queue => "Some Queue", :subject => "The System is Down.")
|
17
|
+
# ticket.id #-> This will be the ID of the ticket in the RT System.
|
18
|
+
#
|
14
19
|
def initialize(attributes)
|
15
20
|
Roart::check_keys!(attributes, Roart::Tickets::RequiredAttributes)
|
16
21
|
if attributes.is_a?(Hash)
|
17
22
|
@attributes = Roart::Tickets::DefaultAttributes.to_hash.merge(attributes)
|
23
|
+
@attributes.update(:id => 'ticket/new')
|
24
|
+
@attributes[:id] = create
|
18
25
|
else
|
19
26
|
raise ArgumentError, "Expects a hash."
|
20
27
|
end
|
@@ -40,6 +47,21 @@ module Roart
|
|
40
47
|
@histories ||= Roart::History.default(:ticket => self)
|
41
48
|
end
|
42
49
|
|
50
|
+
protected
|
51
|
+
|
52
|
+
def create
|
53
|
+
uri = "#{self.class.connection.server}/REST/1.0/ticket/new"
|
54
|
+
payload = @attributes.to_content_format
|
55
|
+
resp = self.class.connection.post(uri, :content => payload)
|
56
|
+
resp = resp.split("\n")
|
57
|
+
raise "Ticket Create Failed" unless resp.first.include?("200")
|
58
|
+
if tid = resp[2].match(/^# Ticket (\d+) created./)
|
59
|
+
return tid[1].to_i
|
60
|
+
else
|
61
|
+
raise "Ticket Create Failed"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
43
65
|
class << self #class methods
|
44
66
|
|
45
67
|
# Gives or Sets the connection object for the RT Server.
|
@@ -55,11 +77,9 @@ module Roart
|
|
55
77
|
else
|
56
78
|
@connection
|
57
79
|
end
|
58
|
-
@connection
|
59
80
|
end
|
60
81
|
|
61
|
-
# Searches for a ticket or group of tickets with an active
|
62
|
-
# record like interface.
|
82
|
+
# Searches for a ticket or group of tickets with an active record like interface.
|
63
83
|
#
|
64
84
|
# Find has 3 different ways to search for tickets
|
65
85
|
#
|
@@ -104,7 +124,7 @@ module Roart
|
|
104
124
|
|
105
125
|
protected
|
106
126
|
|
107
|
-
def instantiate(attrs)
|
127
|
+
def instantiate(attrs) #:nodoc:
|
108
128
|
object = nil
|
109
129
|
if attrs.is_a?(Array)
|
110
130
|
array = Array.new
|
@@ -123,21 +143,21 @@ module Roart
|
|
123
143
|
object
|
124
144
|
end
|
125
145
|
|
126
|
-
def find_initial(options={})
|
146
|
+
def find_initial(options={}) #:nodoc:
|
127
147
|
options.update(:limit => 1)
|
128
148
|
find_all(options).first
|
129
149
|
end
|
130
150
|
|
131
|
-
def find_all(options)
|
151
|
+
def find_all(options) #:nodoc:
|
132
152
|
uri = construct_search_uri(options)
|
133
153
|
tickets = get_tickets_from_search_uri(uri)
|
134
154
|
end
|
135
155
|
|
136
|
-
def find_by_ids(args, options)
|
156
|
+
def find_by_ids(args, options) #:nodoc:
|
137
157
|
get_ticket_by_id(args.first)
|
138
158
|
end
|
139
159
|
|
140
|
-
def page_array(uri)
|
160
|
+
def page_array(uri) #:nodoc:
|
141
161
|
page = self.connection.get(uri)
|
142
162
|
raise TicketSystemError, "Can't get ticket." unless page
|
143
163
|
page = page.split("\n")
|
@@ -150,14 +170,14 @@ module Roart
|
|
150
170
|
end
|
151
171
|
end
|
152
172
|
|
153
|
-
def get_tickets_from_search_uri(uri)
|
173
|
+
def get_tickets_from_search_uri(uri) #:nodoc:
|
154
174
|
page = page_array(uri)
|
155
175
|
page.extend(Roart::TicketPage)
|
156
176
|
page = page.to_search_array
|
157
177
|
self.instantiate(page)
|
158
178
|
end
|
159
179
|
|
160
|
-
def get_ticket_from_uri(uri)
|
180
|
+
def get_ticket_from_uri(uri) #:nodoc:
|
161
181
|
page = page_array(uri)
|
162
182
|
page.extend(Roart::TicketPage)
|
163
183
|
page = page.to_hash
|
@@ -165,13 +185,13 @@ module Roart
|
|
165
185
|
self.instantiate(page)
|
166
186
|
end
|
167
187
|
|
168
|
-
def get_ticket_by_id(id)
|
188
|
+
def get_ticket_by_id(id) #:nodoc:
|
169
189
|
uri = "#{self.connection.server}/REST/1.0/ticket/"
|
170
190
|
uri << id.to_s
|
171
191
|
get_ticket_from_uri(uri)
|
172
192
|
end
|
173
193
|
|
174
|
-
def construct_search_uri(options)
|
194
|
+
def construct_search_uri(options) #:nodoc:
|
175
195
|
uri = "#{self.connection.server}/REST/1.0/search/ticket?"
|
176
196
|
uri << 'orderby=-Created&' if options.delete(:order)
|
177
197
|
unless options.empty?
|
@@ -191,7 +211,7 @@ module Roart
|
|
191
211
|
uri
|
192
212
|
end
|
193
213
|
|
194
|
-
def add_queue!(uri, queue)
|
214
|
+
def add_queue!(uri, queue) #:nodoc:
|
195
215
|
return false unless queue
|
196
216
|
if queue.is_a?(Array)
|
197
217
|
queues = Array.new
|
@@ -204,7 +224,7 @@ module Roart
|
|
204
224
|
end
|
205
225
|
end
|
206
226
|
|
207
|
-
def add_custom_fields!(uri, options)
|
227
|
+
def add_custom_fields!(uri, options) #:nodoc:
|
208
228
|
return false unless options
|
209
229
|
options.each do |field, value|
|
210
230
|
if value.is_a?(Array)
|
@@ -219,7 +239,7 @@ module Roart
|
|
219
239
|
end
|
220
240
|
end
|
221
241
|
|
222
|
-
def add_status!(uri, options)
|
242
|
+
def add_status!(uri, options) #:nodoc:
|
223
243
|
return false unless options
|
224
244
|
parts = Array.new
|
225
245
|
if options.is_a?(Array)
|
@@ -234,7 +254,7 @@ module Roart
|
|
234
254
|
uri << parts
|
235
255
|
end
|
236
256
|
|
237
|
-
def add_searches!(uri, options)
|
257
|
+
def add_searches!(uri, options) #:nodoc:
|
238
258
|
search_fields = %w( subject content content_type file_name)
|
239
259
|
options.each do |key, value|
|
240
260
|
if search_fields.include?(key.to_s)
|
@@ -252,7 +272,7 @@ module Roart
|
|
252
272
|
end
|
253
273
|
end
|
254
274
|
|
255
|
-
def add_dates!(uri, options)
|
275
|
+
def add_dates!(uri, options) #:nodoc:
|
256
276
|
date_field = %w( created started resolved told last_updated starts due updated )
|
257
277
|
options.each do |key, value|
|
258
278
|
if date_field.include?(key.to_s)
|
data/lib/roart.rb
CHANGED
data/roart.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{roart}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.2"
|
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"]
|
9
|
-
s.date = %q{2009-08-
|
9
|
+
s.date = %q{2009-08-18}
|
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/single_history.txt"]
|
13
|
-
s.files = ["History.txt", "README.rdoc", "Rakefile", "lib/roart.rb", "lib/roart/connection.rb", "lib/roart/core/array.rb", "lib/roart/core/string.rb", "lib/roart/errors.rb", "lib/roart/history.rb", "lib/roart/roart.rb", "lib/roart/ticket.rb", "lib/roart/ticket_page.rb", "roart.gemspec", "spec/roart/connection_spec.rb", "spec/roart/core/array_spec.rb", "spec/roart/core/string_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_spec.rb", "spec/spec_helper.rb", "spec/test_data/full_history.txt", "spec/test_data/single_history.txt", "test/test_roart.rb"]
|
13
|
+
s.files = ["History.txt", "README.rdoc", "Rakefile", "lib/roart.rb", "lib/roart/connection.rb", "lib/roart/core/array.rb", "lib/roart/core/hash.rb", "lib/roart/core/string.rb", "lib/roart/errors.rb", "lib/roart/history.rb", "lib/roart/roart.rb", "lib/roart/ticket.rb", "lib/roart/ticket_page.rb", "roart.gemspec", "spec/roart/connection_spec.rb", "spec/roart/core/array_spec.rb", "spec/roart/core/hash_spec.rb", "spec/roart/core/string_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_spec.rb", "spec/spec_helper.rb", "spec/test_data/full_history.txt", "spec/test_data/single_history.txt", "test/test_roart.rb"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/pjdavis/roart}
|
16
16
|
s.rdoc_options = ["--main", "README.rdoc"]
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w[ .. .. spec_helper])
|
2
|
+
|
3
|
+
describe 'hash extentions' do
|
4
|
+
|
5
|
+
it 'should format the content correctly' do
|
6
|
+
payload = {:subject => "A New Ticket", :queue => 'My Queue'}
|
7
|
+
payload.to_content_format.include?("Subject: A New Ticket").should be_true
|
8
|
+
payload.to_content_format.include?("Queue: My Queue").should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
data/spec/roart/history_spec.rb
CHANGED
@@ -30,6 +30,7 @@ describe "History" do
|
|
30
30
|
|
31
31
|
before do
|
32
32
|
@page = File.open(File.join(File.dirname(__FILE__), %w[ .. test_data full_history.txt])).readlines.join
|
33
|
+
@ticket = mock('ticket')
|
33
34
|
Roart::History.should_receive(:get_page).and_return(@page)
|
34
35
|
@histories = Roart::History.default(:ticket => @ticket)
|
35
36
|
end
|
data/spec/roart/ticket_spec.rb
CHANGED
@@ -296,12 +296,42 @@ describe "Ticket" do
|
|
296
296
|
|
297
297
|
end
|
298
298
|
|
299
|
+
describe 'manipulating tickets' do
|
300
|
+
|
301
|
+
def to_content_format(data)
|
302
|
+
fields = data.map { |key,value| "#{key.to_s.camelize}: #{value}" unless value.nil? }
|
303
|
+
fields.compact.join("\n")
|
304
|
+
end
|
305
|
+
|
306
|
+
before do
|
307
|
+
post_data = @payload = {:subject => 'A New Ticket', :queue => 'My Queue'}
|
308
|
+
post_data.update(:id => 'ticket/new')
|
309
|
+
post_data = to_content_format(post_data)
|
310
|
+
mock_connection = mock('connection')
|
311
|
+
mock_connection.should_receive(:post).with('uri/REST/1.0/ticket/new', {:content => post_data}).and_return("RT/3.6.6 200 Ok\n\n# Ticket 267783 created.")
|
312
|
+
mock_connection.should_receive(:server).and_return('uri')
|
313
|
+
Roart::Ticket.should_receive(:connection).twice.and_return(mock_connection)
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'should be able to create a ticket' do
|
317
|
+
ticket = Roart::Ticket.new(@payload)
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'should return a newly created ticket' do
|
321
|
+
ticket = Roart::Ticket.new(@payload)
|
322
|
+
ticket.class.should == Roart::Ticket
|
323
|
+
ticket.id.should == 267783
|
324
|
+
end
|
325
|
+
|
326
|
+
end
|
327
|
+
|
299
328
|
describe 'histories' do
|
300
329
|
|
301
330
|
before(:each) do
|
302
331
|
search_array = ['1:subject']
|
303
332
|
search_array.extend(Roart::TicketPage)
|
304
333
|
full_ticket = Roart::Ticket.send(:instantiate, {:id => 1, :subject => 'subject', :full => true})
|
334
|
+
@mock_connection = mock('connection')
|
305
335
|
@mock_connection.should_receive(:get).with('uri').and_return('200')
|
306
336
|
@ticket = Roart::Ticket.send(:instantiate, search_array.to_search_array).first
|
307
337
|
@ticket.class.should_receive(:connection).and_return(@mock_connection)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pjdavis-roart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- PJ Davis
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-18 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -50,6 +50,7 @@ files:
|
|
50
50
|
- lib/roart.rb
|
51
51
|
- lib/roart/connection.rb
|
52
52
|
- lib/roart/core/array.rb
|
53
|
+
- lib/roart/core/hash.rb
|
53
54
|
- lib/roart/core/string.rb
|
54
55
|
- lib/roart/errors.rb
|
55
56
|
- lib/roart/history.rb
|
@@ -59,6 +60,7 @@ files:
|
|
59
60
|
- roart.gemspec
|
60
61
|
- spec/roart/connection_spec.rb
|
61
62
|
- spec/roart/core/array_spec.rb
|
63
|
+
- spec/roart/core/hash_spec.rb
|
62
64
|
- spec/roart/core/string_spec.rb
|
63
65
|
- spec/roart/history_spec.rb
|
64
66
|
- spec/roart/roart_spec.rb
|