roust 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/roust/version.rb +1 -1
- data/lib/roust.rb +23 -3
- data/spec/mocks/queue-13.txt +11 -0
- data/spec/mocks/queue-nil.txt +5 -0
- data/spec/mocks/user-nil.txt +5 -0
- data/spec/roust_spec.rb +177 -0
- metadata +9 -3
- data/spec/ticket_spec.rb +0 -124
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a329790a5839a6b93c0d313c917c4c000f9e2a7
|
4
|
+
data.tar.gz: 8bcafe4ef3bb915df0eebec3b839932726862a1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6782ef99b98042e6a70a1d4e3e25b7ea221fbbbf4132343ef877eb8af8cf3a188b710283388132f76b3d16048a9e81055e0f9af7dbd9f6eb4f158e224809a54f
|
7
|
+
data.tar.gz: d6d9576b2fefd81e07782030a3fa9cccfb4e2db8a999915d720b136f898ec50f937f5d7a1b5891d045f6b02db4bca2a185a75541435e187b2c5cecdd990653ca
|
data/Gemfile.lock
CHANGED
data/lib/roust/version.rb
CHANGED
data/lib/roust.rb
CHANGED
@@ -246,13 +246,33 @@ class Roust
|
|
246
246
|
end
|
247
247
|
end
|
248
248
|
|
249
|
-
|
250
|
-
|
249
|
+
# id can be numeric (e.g. 28) or textual (e.g. john)
|
250
|
+
def user(id)
|
251
|
+
response = self.class.get("/user/#{id}")
|
251
252
|
|
252
253
|
body, status = handle_response(response)
|
253
254
|
case body
|
254
255
|
when /No user named/
|
255
|
-
|
256
|
+
nil
|
257
|
+
else
|
258
|
+
body.gsub!(/\n\s*\n/,"\n") # remove blank lines for Mail
|
259
|
+
message = Mail.new(body)
|
260
|
+
Hash[message.header.fields.map {|header|
|
261
|
+
key = header.name.to_s.downcase
|
262
|
+
value = header.value.to_s
|
263
|
+
[ key, value ]
|
264
|
+
}]
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
# id can be numeric (e.g. 28) or textual (e.g. sales)
|
269
|
+
def queue(id)
|
270
|
+
response = self.class.get("/queue/#{id}")
|
271
|
+
|
272
|
+
body, status = handle_response(response)
|
273
|
+
case body
|
274
|
+
when /No queue named/
|
275
|
+
nil
|
256
276
|
else
|
257
277
|
body.gsub!(/\n\s*\n/,"\n") # remove blank lines for Mail
|
258
278
|
message = Mail.new(body)
|
data/spec/roust_spec.rb
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'roust'
|
3
|
+
|
4
|
+
describe "Roust" do
|
5
|
+
before do
|
6
|
+
@credentials = {
|
7
|
+
:server => 'http://rt.example.org',
|
8
|
+
:username => 'admin',
|
9
|
+
:password => 'password'
|
10
|
+
}
|
11
|
+
mocks_path = Pathname.new(__FILE__).parent.join('mocks')
|
12
|
+
|
13
|
+
stub_request(:post, "http://rt.example.org/index.html").
|
14
|
+
with(:body => {
|
15
|
+
"user"=>"admin",
|
16
|
+
"pass"=>"password",
|
17
|
+
}).
|
18
|
+
to_return(:status => 200, :body => "", :headers => {})
|
19
|
+
|
20
|
+
stub_request(:get, "http://rt.example.org/REST/1.0/ticket/1/show").
|
21
|
+
to_return(:status => 200,
|
22
|
+
:body => mocks_path.join('ticket-1-show.txt').read,
|
23
|
+
:headers => {})
|
24
|
+
|
25
|
+
stub_request(:get, "http://rt.example.org/REST/1.0/search/ticket?format=s&orderby=%2Bid&query%5Bquery%5D=id%20=%201%20or%20id%20=%202").
|
26
|
+
to_return(:status => 200,
|
27
|
+
:body => mocks_path.join('ticket-search-1-or-2.txt').read,
|
28
|
+
:headers => {})
|
29
|
+
|
30
|
+
stub_request(:get, "http://rt.example.org/REST/1.0/ticket/1/history?format=s").
|
31
|
+
to_return(:status => 200,
|
32
|
+
:body => mocks_path.join('ticket-1-history-short.txt').read,
|
33
|
+
:headers => {})
|
34
|
+
|
35
|
+
stub_request(:get, "http://rt.example.org/REST/1.0/ticket/1/history?format=l").
|
36
|
+
to_return(:status => 200,
|
37
|
+
:body => mocks_path.join('ticket-1-history-long.txt').read,
|
38
|
+
:headers => {})
|
39
|
+
|
40
|
+
stub_request(:get, "http://rt.example.org/REST/1.0/user/dan@us.example").
|
41
|
+
to_return(:status => 200,
|
42
|
+
:body => mocks_path.join('user-dan@us.example.txt').read,
|
43
|
+
:headers => {})
|
44
|
+
|
45
|
+
stub_request(:get, "http://rt.example.org/REST/1.0/user/nil").
|
46
|
+
to_return(:status => 200,
|
47
|
+
:body => mocks_path.join('user-nil.txt').read,
|
48
|
+
:headers => {})
|
49
|
+
|
50
|
+
stub_request(:get, "http://rt.example.org/REST/1.0/queue/13").
|
51
|
+
to_return(:status => 200,
|
52
|
+
:body => mocks_path.join('queue-13.txt').read,
|
53
|
+
:headers => {})
|
54
|
+
|
55
|
+
stub_request(:get, "http://rt.example.org/REST/1.0/queue/nil").
|
56
|
+
to_return(:status => 200,
|
57
|
+
:body => mocks_path.join('queue-nil.txt').read,
|
58
|
+
:headers => {})
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'authentication' do
|
62
|
+
it "authenticates on instantiation" do
|
63
|
+
rt = Roust.new(@credentials)
|
64
|
+
rt.authenticated?.should be_true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe 'tickets' do
|
69
|
+
it "can list tickets matching a query" do
|
70
|
+
rt = Roust.new(@credentials)
|
71
|
+
rt.authenticated?.should be_true
|
72
|
+
|
73
|
+
results = rt.search(:query => "id = 1 or id = 2")
|
74
|
+
results.size.should == 2
|
75
|
+
results.each do |result|
|
76
|
+
result.size.should == 2
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
it "can fetch metadata on individual tickets" do
|
81
|
+
rt = Roust.new(@credentials)
|
82
|
+
rt.authenticated?.should be_true
|
83
|
+
|
84
|
+
ticket = rt.show("1")
|
85
|
+
ticket.should_not be_nil
|
86
|
+
|
87
|
+
attrs = %w(id Subject Queue) +
|
88
|
+
%w(Requestors Cc AdminCc Owner Creator) +
|
89
|
+
%w(Resolved Status) +
|
90
|
+
%w(Starts Started TimeLeft Due TimeWorked TimeEstimated) +
|
91
|
+
%w(LastUpdated Created Told) +
|
92
|
+
%w(Priority FinalPriority InitialPriority)
|
93
|
+
|
94
|
+
attrs.each do |attr|
|
95
|
+
ticket[attr].should_not be_nil, "#{attr} key doesn't exist"
|
96
|
+
end
|
97
|
+
|
98
|
+
%w(Requestors Cc AdminCc).each do |field|
|
99
|
+
ticket[field].size.should > 1
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it "can fetch transactions on individual tickets" do
|
104
|
+
rt = Roust.new(@credentials)
|
105
|
+
rt.authenticated?.should be_true
|
106
|
+
|
107
|
+
short = rt.history("1", :format => "short")
|
108
|
+
|
109
|
+
short.size.should > 1
|
110
|
+
short.each do |txn|
|
111
|
+
txn.size.should == 2
|
112
|
+
txn.first.should match(/^\d+$/)
|
113
|
+
txn.last.should match(/^\w.*\w$/)
|
114
|
+
end
|
115
|
+
|
116
|
+
#attrs = %w(ticket data oldvalue creator timetaken) +
|
117
|
+
# %w(id type field newvalue content description) +
|
118
|
+
# %w(attachments created)
|
119
|
+
attrs = %w(ticket data oldvalue timetaken) +
|
120
|
+
%w(id type field newvalue content description)
|
121
|
+
|
122
|
+
long = rt.history("1", :format => "long")
|
123
|
+
long.size.should > 0
|
124
|
+
long.each do |txn|
|
125
|
+
attrs.each do |attr|
|
126
|
+
txn[attr].should_not be_nil, "#{attr} key doesn't exist"
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
describe 'user' do
|
133
|
+
it "can lookup user details" do
|
134
|
+
rt = Roust.new(@credentials)
|
135
|
+
rt.authenticated?.should be_true
|
136
|
+
|
137
|
+
attrs = %w(name realname gecos nickname emailaddress id lang password)
|
138
|
+
|
139
|
+
user = rt.user("dan@us.example")
|
140
|
+
attrs.each do |attr|
|
141
|
+
user[attr].should_not be_nil, "#{attr} key doesn't exist"
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'returns nil for unknown users' do
|
146
|
+
rt = Roust.new(@credentials)
|
147
|
+
rt.authenticated?.should be_true
|
148
|
+
|
149
|
+
queue = rt.user('nil')
|
150
|
+
queue.should be_nil
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'queue' do
|
155
|
+
it "can lookup queue details" do
|
156
|
+
rt = Roust.new(@credentials)
|
157
|
+
rt.authenticated?.should be_true
|
158
|
+
|
159
|
+
attrs = %w(id name description correspondaddress commentaddress) +
|
160
|
+
%w(initialpriority finalpriority defaultduein)
|
161
|
+
|
162
|
+
queue = rt.queue('13')
|
163
|
+
attrs.each do |attr|
|
164
|
+
queue[attr].should_not be_nil, "#{attr} key doesn't exist"
|
165
|
+
end
|
166
|
+
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'returns nil for unknown queues' do
|
170
|
+
rt = Roust.new(@credentials)
|
171
|
+
rt.authenticated?.should be_true
|
172
|
+
|
173
|
+
queue = rt.queue('nil')
|
174
|
+
queue.should be_nil
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: roust
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lindsay Holmwood
|
@@ -71,13 +71,16 @@ files:
|
|
71
71
|
- lib/roust.rb
|
72
72
|
- lib/roust/version.rb
|
73
73
|
- roust.gemspec
|
74
|
+
- spec/mocks/queue-13.txt
|
75
|
+
- spec/mocks/queue-nil.txt
|
74
76
|
- spec/mocks/ticket-1-history-long.txt
|
75
77
|
- spec/mocks/ticket-1-history-short.txt
|
76
78
|
- spec/mocks/ticket-1-show.txt
|
77
79
|
- spec/mocks/ticket-search-1-or-2.txt
|
78
80
|
- spec/mocks/user-dan@us.example.txt
|
81
|
+
- spec/mocks/user-nil.txt
|
82
|
+
- spec/roust_spec.rb
|
79
83
|
- spec/spec_helper.rb
|
80
|
-
- spec/ticket_spec.rb
|
81
84
|
homepage: http://github.com/bulletproofnetworks/roust
|
82
85
|
licenses:
|
83
86
|
- Apache 2.0
|
@@ -103,10 +106,13 @@ signing_key:
|
|
103
106
|
specification_version: 4
|
104
107
|
summary: Ruby client for RT's REST API
|
105
108
|
test_files:
|
109
|
+
- spec/mocks/queue-13.txt
|
110
|
+
- spec/mocks/queue-nil.txt
|
106
111
|
- spec/mocks/ticket-1-history-long.txt
|
107
112
|
- spec/mocks/ticket-1-history-short.txt
|
108
113
|
- spec/mocks/ticket-1-show.txt
|
109
114
|
- spec/mocks/ticket-search-1-or-2.txt
|
110
115
|
- spec/mocks/user-dan@us.example.txt
|
116
|
+
- spec/mocks/user-nil.txt
|
117
|
+
- spec/roust_spec.rb
|
111
118
|
- spec/spec_helper.rb
|
112
|
-
- spec/ticket_spec.rb
|
data/spec/ticket_spec.rb
DELETED
@@ -1,124 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'roust'
|
3
|
-
|
4
|
-
describe "Roust" do
|
5
|
-
before do
|
6
|
-
@credentials = {
|
7
|
-
:server => 'http://rt.example.org',
|
8
|
-
:username => 'admin',
|
9
|
-
:password => 'password'
|
10
|
-
}
|
11
|
-
mocks_path = Pathname.new(__FILE__).parent.join('mocks')
|
12
|
-
|
13
|
-
stub_request(:post, "http://rt.example.org/index.html").
|
14
|
-
with(:body => {
|
15
|
-
"user"=>"admin",
|
16
|
-
"pass"=>"password",
|
17
|
-
}).
|
18
|
-
to_return(:status => 200, :body => "", :headers => {})
|
19
|
-
|
20
|
-
stub_request(:get, "http://rt.example.org/REST/1.0/ticket/1/show").
|
21
|
-
to_return(:status => 200,
|
22
|
-
:body => mocks_path.join('ticket-1-show.txt').read,
|
23
|
-
:headers => {})
|
24
|
-
|
25
|
-
stub_request(:get, "http://rt.example.org/REST/1.0/search/ticket?format=s&orderby=%2Bid&query%5Bquery%5D=id%20=%201%20or%20id%20=%202").
|
26
|
-
to_return(:status => 200,
|
27
|
-
:body => mocks_path.join('ticket-search-1-or-2.txt').read,
|
28
|
-
:headers => {})
|
29
|
-
|
30
|
-
stub_request(:get, "http://rt.example.org/REST/1.0/ticket/1/history?format=s").
|
31
|
-
to_return(:status => 200,
|
32
|
-
:body => mocks_path.join('ticket-1-history-short.txt').read,
|
33
|
-
:headers => {})
|
34
|
-
|
35
|
-
stub_request(:get, "http://rt.example.org/REST/1.0/ticket/1/history?format=l").
|
36
|
-
to_return(:status => 200,
|
37
|
-
:body => mocks_path.join('ticket-1-history-long.txt').read,
|
38
|
-
:headers => {})
|
39
|
-
|
40
|
-
stub_request(:get, "http://rt.example.org/REST/1.0/user/dan@us.example").
|
41
|
-
to_return(:status => 200,
|
42
|
-
:body => mocks_path.join('user-dan@us.example.txt').read,
|
43
|
-
:headers => {})
|
44
|
-
end
|
45
|
-
|
46
|
-
it "authenticates on instantiation" do
|
47
|
-
rt = Roust.new(@credentials)
|
48
|
-
rt.authenticated?.should be_true
|
49
|
-
end
|
50
|
-
|
51
|
-
it "can list tickets matching a query" do
|
52
|
-
rt = Roust.new(@credentials)
|
53
|
-
rt.authenticated?.should be_true
|
54
|
-
|
55
|
-
results = rt.search(:query => "id = 1 or id = 2")
|
56
|
-
results.size.should == 2
|
57
|
-
results.each do |result|
|
58
|
-
result.size.should == 2
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "can fetch metadata on individual tickets" do
|
63
|
-
rt = Roust.new(@credentials)
|
64
|
-
rt.authenticated?.should be_true
|
65
|
-
|
66
|
-
ticket = rt.show("1")
|
67
|
-
ticket.should_not be_nil
|
68
|
-
|
69
|
-
attrs = %w(id Subject Queue) +
|
70
|
-
%w(Requestors Cc AdminCc Owner Creator) +
|
71
|
-
%w(Resolved Status) +
|
72
|
-
%w(Starts Started TimeLeft Due TimeWorked TimeEstimated) +
|
73
|
-
%w(LastUpdated Created Told) +
|
74
|
-
%w(Priority FinalPriority InitialPriority)
|
75
|
-
|
76
|
-
attrs.each do |attr|
|
77
|
-
ticket[attr].should_not be_nil, "#{attr} key doesn't exist"
|
78
|
-
end
|
79
|
-
|
80
|
-
%w(Requestors Cc AdminCc).each do |field|
|
81
|
-
ticket[field].size.should > 1
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
it "can fetch transactions on individual tickets" do
|
86
|
-
rt = Roust.new(@credentials)
|
87
|
-
rt.authenticated?.should be_true
|
88
|
-
|
89
|
-
short = rt.history("1", :format => "short")
|
90
|
-
|
91
|
-
short.size.should > 1
|
92
|
-
short.each do |txn|
|
93
|
-
txn.size.should == 2
|
94
|
-
txn.first.should match(/^\d+$/)
|
95
|
-
txn.last.should match(/^\w.*\w$/)
|
96
|
-
end
|
97
|
-
|
98
|
-
#attrs = %w(ticket data oldvalue creator timetaken) +
|
99
|
-
# %w(id type field newvalue content description) +
|
100
|
-
# %w(attachments created)
|
101
|
-
attrs = %w(ticket data oldvalue timetaken) +
|
102
|
-
%w(id type field newvalue content description)
|
103
|
-
|
104
|
-
long = rt.history("1", :format => "long")
|
105
|
-
long.size.should > 0
|
106
|
-
long.each do |txn|
|
107
|
-
attrs.each do |attr|
|
108
|
-
txn[attr].should_not be_nil, "#{attr} key doesn't exist"
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
it "can find user details" do
|
114
|
-
rt = Roust.new(@credentials)
|
115
|
-
rt.authenticated?.should be_true
|
116
|
-
|
117
|
-
attrs = %w(name realname gecos nickname emailaddress id lang password)
|
118
|
-
|
119
|
-
user = rt.user("dan@us.example")
|
120
|
-
attrs.each do |attr|
|
121
|
-
user[attr].should_not be_nil, "#{attr} key doesn't exist"
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|