roust 1.2.0 → 1.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a329790a5839a6b93c0d313c917c4c000f9e2a7
4
- data.tar.gz: 8bcafe4ef3bb915df0eebec3b839932726862a1b
3
+ metadata.gz: cef798971363e9cf2f7413d94e90b84573281480
4
+ data.tar.gz: f6310fab56e67982258e61b0c038aac6b44a266d
5
5
  SHA512:
6
- metadata.gz: 6782ef99b98042e6a70a1d4e3e25b7ea221fbbbf4132343ef877eb8af8cf3a188b710283388132f76b3d16048a9e81055e0f9af7dbd9f6eb4f158e224809a54f
7
- data.tar.gz: d6d9576b2fefd81e07782030a3fa9cccfb4e2db8a999915d720b136f898ec50f937f5d7a1b5891d045f6b02db4bca2a185a75541435e187b2c5cecdd990653ca
6
+ metadata.gz: 14173684c35624ecc5ff42142de0c26b9a233c42f96c9f8a5fa43134f23b2a77ccca45d498541b41a6538d2eebd3f05eeb4935cab549d9fcc1bb29feb5ec354d
7
+ data.tar.gz: 6e64614597cc7f8c3df383e75bfdba00f05b425b768b79bc9a922adcf8f6893de2c34b49aeab65c78cb7dfa535557c7c413b54bf248f53c367cd1dfb48ee838a
data/Gemfile CHANGED
@@ -9,4 +9,5 @@ group :development do
9
9
  gem 'colorize'
10
10
  gem 'rake'
11
11
  gem 'webmock'
12
+ gem 'pry'
12
13
  end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- roust (1.2.0)
4
+ roust (1.3.0)
5
5
  activesupport (>= 4.1.0)
6
6
  httparty (>= 0.13.1)
7
7
  mail (>= 2.5.4)
@@ -16,6 +16,7 @@ GEM
16
16
  thread_safe (~> 0.1)
17
17
  tzinfo (~> 1.1)
18
18
  addressable (2.3.5)
19
+ coderay (1.0.9)
19
20
  colorize (0.5.8)
20
21
  crack (0.4.1)
21
22
  safe_yaml (~> 0.9.0)
@@ -28,10 +29,15 @@ GEM
28
29
  mail (2.5.4)
29
30
  mime-types (~> 1.16)
30
31
  treetop (~> 1.4.8)
32
+ method_source (0.8.2)
31
33
  mime-types (1.25.1)
32
34
  minitest (5.3.3)
33
35
  multi_xml (0.5.5)
34
36
  polyglot (0.3.4)
37
+ pry (0.9.12.2)
38
+ coderay (~> 1.0.5)
39
+ method_source (~> 0.8)
40
+ slop (~> 3.4)
35
41
  rake (10.1.0)
36
42
  rspec (2.9.0)
37
43
  rspec-core (~> 2.9.0)
@@ -42,6 +48,7 @@ GEM
42
48
  diff-lcs (~> 1.1.3)
43
49
  rspec-mocks (2.9.0)
44
50
  safe_yaml (0.9.7)
51
+ slop (3.4.6)
45
52
  thread_safe (0.3.3)
46
53
  treetop (1.4.15)
47
54
  polyglot
@@ -57,6 +64,7 @@ PLATFORMS
57
64
 
58
65
  DEPENDENCIES
59
66
  colorize
67
+ pry
60
68
  rake
61
69
  roust!
62
70
  rspec
data/README.md CHANGED
@@ -55,6 +55,10 @@ rt.history("1", :format => "long") # => [{"id"=>"1", "ticket"=>"1", "timetaken"=
55
55
 
56
56
  # Fetch user details
57
57
  rt.user("dan@us.example") # => {"id"=>"user/160000", "name"=>"dan", "password"=>"********", "emailaddress"=>"dan@us.example", "realname"=>"Dan Smith", "nickname"=>"dan", … }
58
+
59
+ # Fetch queue details
60
+ rt.queue(1) # => {"id"=>"queue/1", "name"=>"sales", "description"=>"Sales", "correspondaddress"=>"sales@us.example", "commentaddress"=>"rt-comment@us.example", … }
61
+ rt.queue('sales') # => {"id"=>"queue/1", "name"=>"sales", "description"=>"Sales", "correspondaddress"=>"sales@us.example", "commentaddress"=>"rt-comment@us.example", … }
58
62
  ```
59
63
 
60
64
 
data/lib/roust/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Roust
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
data/lib/roust.rb CHANGED
@@ -46,7 +46,7 @@ class Roust
46
46
  def show(id)
47
47
  response = self.class.get("/ticket/#{id}/show")
48
48
 
49
- body, status = handle_response(response)
49
+ body, status = explode_response(response)
50
50
 
51
51
  if match = body.match(/^# (Ticket (\d+) does not exist\.)/)
52
52
  return { 'error' => match[1] }
@@ -136,7 +136,7 @@ class Roust
136
136
  },
137
137
  )
138
138
 
139
- body, status = handle_response(response)
139
+ body, status = explode_response(response)
140
140
 
141
141
  case body
142
142
  when /^# Could not create ticket/
@@ -155,28 +155,7 @@ class Roust
155
155
  end
156
156
 
157
157
  def update(id, attrs)
158
- default_attrs = {
159
- 'id' => "ticket/#{id}"
160
- }
161
- attrs = default_attrs.merge(attrs).stringify_keys!
162
-
163
- content = attrs.map { |k,v|
164
- # Don't lowercase strings if they're already camel cased.
165
- k = case
166
- when k.is_a?(Symbol)
167
- k.to_s
168
- when k == 'id'
169
- k
170
- when k =~ /^[a-z]/
171
- k.capitalize
172
- else
173
- k
174
- end
175
-
176
- v = v.join(', ') if v.respond_to?(:join)
177
-
178
- "#{k}: #{v}"
179
- }.join("\n")
158
+ content = compose_content('ticket', id, attrs)
180
159
 
181
160
  response = self.class.post(
182
161
  "/ticket/#{id}/edit",
@@ -185,7 +164,7 @@ class Roust
185
164
  },
186
165
  )
187
166
 
188
- body, status = handle_response(response)
167
+ body, status = explode_response(response)
189
168
 
190
169
  case body
191
170
  when /^# You are not allowed to modify ticket \d+/
@@ -236,7 +215,7 @@ class Roust
236
215
 
237
216
  response = self.class.get("/ticket/#{id}/history", :query => params)
238
217
 
239
- body, status = handle_response(response)
218
+ body, status = explode_response(response)
240
219
 
241
220
  case format
242
221
  when 'short'
@@ -246,14 +225,14 @@ class Roust
246
225
  end
247
226
  end
248
227
 
249
- # id can be numeric (e.g. 28) or textual (e.g. john)
250
- def user(id)
251
- response = self.class.get("/user/#{id}")
228
+ # id can be numeric (e.g. 28) or textual (e.g. sales)
229
+ def queue(id)
230
+ response = self.class.get("/queue/#{id}")
252
231
 
253
- body, status = handle_response(response)
232
+ body, status = explode_response(response)
254
233
  case body
255
- when /No user named/
256
- nil
234
+ when /No queue named/
235
+ nil
257
236
  else
258
237
  body.gsub!(/\n\s*\n/,"\n") # remove blank lines for Mail
259
238
  message = Mail.new(body)
@@ -265,14 +244,14 @@ class Roust
265
244
  end
266
245
  end
267
246
 
268
- # id can be numeric (e.g. 28) or textual (e.g. sales)
269
- def queue(id)
270
- response = self.class.get("/queue/#{id}")
247
+ # id can be numeric (e.g. 28) or textual (e.g. john)
248
+ def user_show(id)
249
+ response = self.class.get("/user/#{id}")
271
250
 
272
- body, status = handle_response(response)
251
+ body, status = explode_response(response)
273
252
  case body
274
- when /No queue named/
275
- nil
253
+ when /No user named/
254
+ nil
276
255
  else
277
256
  body.gsub!(/\n\s*\n/,"\n") # remove blank lines for Mail
278
257
  message = Mail.new(body)
@@ -284,8 +263,62 @@ class Roust
284
263
  end
285
264
  end
286
265
 
266
+ alias :user :user_show
267
+
268
+ def user_update(id, attrs)
269
+ content = compose_content('user', id, attrs)
270
+
271
+ response = self.class.post(
272
+ "/user/#{id}/edit",
273
+ :body => {
274
+ :content => content
275
+ },
276
+ )
277
+
278
+ body, status = explode_response(response)
279
+
280
+ case body
281
+ when /^# You are not allowed to modify user \d+/
282
+ { 'error' => body.strip }
283
+ when /^# Syntax error/
284
+ { 'error' => body.strip }
285
+ when /^# User (.+) updated/
286
+ id = body[/^# User (.+) updated/, 1]
287
+ user_show(id)
288
+ else
289
+ # We should never hit this, but if we do, just pass it through and
290
+ # surprise the user (!!!).
291
+ body
292
+ end
293
+ end
294
+
287
295
  private
288
- def handle_response(response)
296
+ def compose_content(type, id, attrs)
297
+ default_attrs = {
298
+ 'id' => [ type, id ].join('/')
299
+ }
300
+ attrs = default_attrs.merge(attrs).stringify_keys!
301
+
302
+ content = attrs.map { |k,v|
303
+ # Don't lowercase strings if they're already camel cased.
304
+ k = case
305
+ when k.is_a?(Symbol)
306
+ k.to_s
307
+ when k == 'id'
308
+ k
309
+ when k =~ /^[a-z]/
310
+ k.capitalize
311
+ else
312
+ k
313
+ end
314
+
315
+ v = v.join(', ') if v.respond_to?(:join)
316
+
317
+ "#{k}: #{v}"
318
+ }.join("\n")
319
+ end
320
+
321
+ def explode_response(response)
289
322
  body = response.body
290
323
  status = body[/RT\/\d+\.\d+\.\d+\s(\d{3}\s.*)\n/, 1]
291
324
 
@@ -0,0 +1,21 @@
1
+ RT/3.4.6 200 Ok
2
+
3
+ id: user/160000
4
+ Name: dan
5
+ Password: ********
6
+ EmailAddress: dan@us.example
7
+ RealName: Daniel Smith
8
+ NickName: dan
9
+ Gecos: dan
10
+ Zip: quote
11
+ MobilePhone: 0400123456
12
+ PagerPhone: DESC
13
+
14
+ Signature: Dan Smith
15
+ Engineer
16
+ Example Org
17
+ tel: 1300 000 123
18
+ mob: 0400 123 456
19
+ fax: 02 9000 1234
20
+
21
+ Lang: en
@@ -0,0 +1,3 @@
1
+ RT/3.4.6 200 Ok
2
+
3
+ # User dan@us.example updated.
data/spec/roust_spec.rb CHANGED
@@ -47,6 +47,12 @@ describe "Roust" do
47
47
  :body => mocks_path.join('user-nil.txt').read,
48
48
  :headers => {})
49
49
 
50
+ stub_request(:post, "http://rt.example.org/REST/1.0/user/dan@us.example/edit").
51
+ with(:body => "content=id%3A%20user%2Fdan%40us.example%0ARealName%3A%20Daniel%20Smith").
52
+ to_return(:status => 200,
53
+ :body => mocks_path.join('user-dan@us.example-edit.txt').read,
54
+ :headers => {})
55
+
50
56
  stub_request(:get, "http://rt.example.org/REST/1.0/queue/13").
51
57
  to_return(:status => 200,
52
58
  :body => mocks_path.join('queue-13.txt').read,
@@ -56,6 +62,7 @@ describe "Roust" do
56
62
  to_return(:status => 200,
57
63
  :body => mocks_path.join('queue-nil.txt').read,
58
64
  :headers => {})
65
+
59
66
  end
60
67
 
61
68
  describe 'authentication' do
@@ -130,13 +137,13 @@ describe "Roust" do
130
137
  end
131
138
 
132
139
  describe 'user' do
133
- it "can lookup user details" do
140
+ it 'can lookup user details' do
134
141
  rt = Roust.new(@credentials)
135
142
  rt.authenticated?.should be_true
136
143
 
137
144
  attrs = %w(name realname gecos nickname emailaddress id lang password)
138
145
 
139
- user = rt.user("dan@us.example")
146
+ user = rt.user_show('dan@us.example')
140
147
  attrs.each do |attr|
141
148
  user[attr].should_not be_nil, "#{attr} key doesn't exist"
142
149
  end
@@ -146,9 +153,27 @@ describe "Roust" do
146
153
  rt = Roust.new(@credentials)
147
154
  rt.authenticated?.should be_true
148
155
 
149
- queue = rt.user('nil')
156
+ queue = rt.user_show('nil')
150
157
  queue.should be_nil
151
158
  end
159
+
160
+ it 'can modify an existing user' do
161
+ mocks_path = Pathname.new(__FILE__).parent.join('mocks')
162
+ stub_request(:get, "http://rt.example.org/REST/1.0/user/dan@us.example").
163
+ to_return(:status => 200,
164
+ :body => mocks_path.join('user-dan@us.example-after-edit.txt').read,
165
+ :headers => {})
166
+
167
+ rt = Roust.new(@credentials)
168
+ rt.authenticated?.should be_true
169
+
170
+ attrs = %w(name realname gecos nickname emailaddress id lang password)
171
+
172
+ attrs = { 'RealName' => 'Daniel Smith' }
173
+ user = rt.user_update('dan@us.example', attrs)
174
+
175
+ user['realname'].should == 'Daniel Smith'
176
+ end
152
177
  end
153
178
 
154
179
  describe 'queue' do
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.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lindsay Holmwood
@@ -77,6 +77,8 @@ files:
77
77
  - spec/mocks/ticket-1-history-short.txt
78
78
  - spec/mocks/ticket-1-show.txt
79
79
  - spec/mocks/ticket-search-1-or-2.txt
80
+ - spec/mocks/user-dan@us.example-after-edit.txt
81
+ - spec/mocks/user-dan@us.example-edit.txt
80
82
  - spec/mocks/user-dan@us.example.txt
81
83
  - spec/mocks/user-nil.txt
82
84
  - spec/roust_spec.rb
@@ -112,6 +114,8 @@ test_files:
112
114
  - spec/mocks/ticket-1-history-short.txt
113
115
  - spec/mocks/ticket-1-show.txt
114
116
  - spec/mocks/ticket-search-1-or-2.txt
117
+ - spec/mocks/user-dan@us.example-after-edit.txt
118
+ - spec/mocks/user-dan@us.example-edit.txt
115
119
  - spec/mocks/user-dan@us.example.txt
116
120
  - spec/mocks/user-nil.txt
117
121
  - spec/roust_spec.rb