rt-client 0.3.7 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/rt/client.rb +35 -10
  2. metadata +4 -4
data/rt/client.rb CHANGED
@@ -14,6 +14,10 @@ require 'pp'
14
14
  ##default server/user/pass to connect to RT as, so that you don't have to
15
15
  ##specify it/update it in lots of different scripts.
16
16
  ##
17
+ ## Thanks to Brian McArdle for patch dealing with spaces in Custom Fields.
18
+ ## To reference custom fields in RT that have spaces with rt-client, use an
19
+ ## underscore in the rt-client code, e.g. "CF.{Has_Space}"
20
+ ##
17
21
  ##TODO: Streaming, chunking attachments in compose method
18
22
  #
19
23
  # See each method for sample usage. To use this, "gem install rt-client" and
@@ -22,7 +26,7 @@ require 'pp'
22
26
 
23
27
  class RT_Client
24
28
 
25
- UA = "Mozilla/5.0 ruby RT Client Interface 0.3.7"
29
+ UA = "Mozilla/5.0 ruby RT Client Interface 0.3.9"
26
30
  attr_reader :status, :site, :version, :cookies, :server, :user, :cookie
27
31
 
28
32
  # Create a new RT_Client object. Load up our stored cookie and check it.
@@ -55,7 +59,7 @@ class RT_Client
55
59
  # cookies=<directory>
56
60
  def initialize(*params)
57
61
  @boundary = "----xYzZY#{rand(1000000).to_s}xYzZY"
58
- @version = "0.3.7"
62
+ @version = "0.3.9"
59
63
  @status = "Not connected"
60
64
  @server = "http://localhost/"
61
65
  @user = "rt_user"
@@ -100,7 +104,7 @@ class RT_Client
100
104
  end
101
105
 
102
106
 
103
- site = RestClient::Resource.new(@resource, :headers => headers)
107
+ site = RestClient::Resource.new(@resource, :headers => headers, :timeout => 120)
104
108
  data = site.post "" # a null post just to check that we are logged in
105
109
 
106
110
  if @cookie.length == 0 or data =~ /401/ # we're not logged in
@@ -150,8 +154,11 @@ class RT_Client
150
154
  else
151
155
  resp = @site["#{type}/#{sid}/show"].get
152
156
  end
153
- resp.gsub!(/RT\/\d\.\d\.\d\s\d{3}\s.*\n\n/,"") # toss the HTTP response
157
+ resp.gsub!(/RT\/\d+\.\d+\.\d+\s\d{3}\s.*\n\n/,"") # toss the HTTP response
154
158
  resp.gsub!(/\n\n/,"\n") # remove double spacing, TMail stops at a blank line
159
+ while resp.match(/CF\.\{[\w_ ]*[ ]+[\w ]*\}/) #replace CF spaces with underscores
160
+ resp.gsub!(/CF\.\{([\w_ ]*)([ ]+)([\w ]*)\}/, 'CF.{\1_\3}')
161
+ end
155
162
  return {:error => resp, } if resp =~ /does not exist./
156
163
  th = TMail::Mail.parse(resp)
157
164
  resp += "\nrtclientend:" # to make the pattern match on the last key in the response
@@ -187,8 +194,11 @@ class RT_Client
187
194
  end
188
195
  reply = {}
189
196
  resp = @site["ticket/#{sid}/links/show"].get
190
- resp.gsub!(/RT\/\d\.\d\.\d\s\d{3}\s.*\n\n/,"") # toss the HTTP response
197
+ resp.gsub!(/RT\/\d+\.\d+\.\d+\s\d{3}\s.*\n\n/,"") # toss the HTTP response
191
198
  resp.gsub!(/\n\n/,"\n") # remove double spacing, TMail stops at a blank line
199
+ while resp.match(/CF\.\{[\w_ ]*[ ]+[\w ]*\}/) #replace CF spaces with underscores
200
+ resp.gsub!(/CF\.\{([\w_ ]*)([ ]+)([\w ]*)\}/, 'CF.{\1_\3}')
201
+ end
192
202
  return {:error => resp, } if resp =~ /does not exist./
193
203
  th = TMail::Mail.parse(resp)
194
204
  th.each_header do |k,v|
@@ -406,11 +416,14 @@ class RT_Client
406
416
  resp = @site["search/ticket/?query=#{URI.escape(query)}&orderby=#{order}&format=l"].get
407
417
  return replies if resp =~/No matching results./
408
418
  raise "Invalid query (#{query})" if resp =~ /Invalid query/
409
- resp.gsub!(/RT\/\d\.\d\.\d\s\d{3}\s.*\n\n/,"") # strip HTTP response
419
+ resp.gsub!(/RT\/\d+\.\d+\.\d+\s\d{3}\s.*\n\n/,"") # strip HTTP response
410
420
  tickets = resp.split("\n--\n") # -- occurs between each ticket
411
421
  tickets.each do |ticket|
412
422
  ticket.gsub!(/^\n/,"") # strip leading blank lines
413
423
  ticket.gsub!(/\n\n/,"\n") # remove blank lines for TMail
424
+ while ticket.match(/CF\.\{[\w_ ]*[ ]+[\w ]*\}/) #replace CF spaces with underscores
425
+ ticket.gsub!(/CF\.\{([\w_ ]*)([ ]+)([\w ]*)\}/, 'CF.{\1_\3}')
426
+ end
414
427
  th = TMail::Mail.parse(ticket)
415
428
  reply = {}
416
429
  th.each_header do |k,v|
@@ -481,9 +494,12 @@ class RT_Client
481
494
  end
482
495
  list = h.map { |l| l.split(":") }
483
496
  else
484
- resp.gsub!(/RT\/\d\.\d\.\d\s\d{3}\s.*\n\n/,"") # toss the HTTP response
497
+ resp.gsub!(/RT\/\d+\.\d+\.\d+\s\d{3}\s.*\n\n/,"") # toss the HTTP response
485
498
  resp.gsub!(/^#.*?\n\n/,"") # toss the 'total" line
486
499
  resp.gsub!(/^\n/m,"") # toss blank lines
500
+ while resp.match(/CF\.\{[\w_ ]*[ ]+[\w ]*\}/) #replace CF spaces with underscores
501
+ resp.gsub!(/CF\.\{([\w_ ]*)([ ]+)([\w ]*)\}/, 'CF.{\1_\3}')
502
+ end
487
503
  items = resp.split("\n--\n")
488
504
  list = []
489
505
  items.each do |item|
@@ -548,9 +564,12 @@ class RT_Client
548
564
  reply = {}
549
565
  resp = @site["ticket/#{id}/history/id/#{history}"].get
550
566
  return reply if resp =~ /not related/ # history id must be related to the ticket id
551
- resp.gsub!(/RT\/\d\.\d\.\d\s\d{3}\s.*\n\n/,"") # toss the HTTP response
567
+ resp.gsub!(/RT\/\d+\.\d+\.\d+\s\d{3}\s.*\n\n/,"") # toss the HTTP response
552
568
  resp.gsub!(/^#.*?\n\n/,"") # toss the 'total" line
553
569
  resp.gsub!(/^\n/m,"") # toss blank lines
570
+ while resp.match(/CF\.\{[\w_ ]*[ ]+[\w ]*\}/) #replace CF spaces with underscores
571
+ resp.gsub!(/CF\.\{([\w_ ]*)([ ]+)([\w ]*)\}/, 'CF.{\1_\3}')
572
+ end
554
573
  th = TMail::Mail.parse(resp)
555
574
  attachments = []
556
575
  th.each_header do |k,v|
@@ -601,8 +620,11 @@ class RT_Client
601
620
  unnamed = false if unnamed.to_s == "0"
602
621
  id = $~[1] if id =~ /ticket\/(\d+)/
603
622
  resp = @site["ticket/#{id}/attachments"].get
604
- resp.gsub!(/RT\/\d\.\d\.\d\s\d{3}\s.*\n\n/,"") # toss the HTTP response
623
+ resp.gsub!(/RT\/\d+\.\d+\.\d+\s\d{3}\s.*\n\n/,"") # toss the HTTP response
605
624
  resp.gsub!(/^\n/m,"") # toss blank lines
625
+ while resp.match(/CF\.\{[\w_ ]*[ ]+[\w ]*\}/) #replace CF spaces with underscores
626
+ resp.gsub!(/CF\.\{([\w_ ]*)([ ]+)([\w ]*)\}/, 'CF.{\1_\3}')
627
+ end
606
628
  th = TMail::Mail.parse(resp)
607
629
  list = []
608
630
  pattern = /(\d+:\s.*?\)),/
@@ -658,7 +680,10 @@ class RT_Client
658
680
  end
659
681
  tid = $~[1] if tid =~ /ticket\/(\d+)/
660
682
  resp = @site["ticket/#{tid}/attachments/#{aid}"].get
661
- resp.gsub!(/RT\/\d\.\d\.\d\s\d{3}\s.*\n\n/,"") # toss HTTP response
683
+ resp.gsub!(/RT\/\d+\.\d+\.\d+\s\d{3}\s.*\n\n/,"") # toss HTTP response
684
+ while resp.match(/CF\.\{[\w_ ]*[ ]+[\w ]*\}/) #replace CF spaces with underscores
685
+ resp.gsub!(/CF\.\{([\w_ ]*)([ ]+)([\w ]*)\}/, 'CF.{\1_\3}')
686
+ end
662
687
  headers = TMail::Mail.parse(resp)
663
688
  reply = {}
664
689
  headers.each_header do |k,v|
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rt-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 7
10
- version: 0.3.7
9
+ - 9
10
+ version: 0.3.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tom Lahti
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-22 00:00:00 -08:00
18
+ date: 2011-08-22 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency