rt-client 0.6.4 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +2 -0
  3. data/rt/client.rb +50 -42
  4. metadata +43 -42
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec6bec56c3684933cf883aa29967fbd037c2f5b5
4
+ data.tar.gz: 62d27a2c55a33d8647601fb22ae951c407ee6f04
5
+ SHA512:
6
+ metadata.gz: 6db4f242a6d547c87248daaa8b80f1b170461a1432aa4c34016eaa90f207f261f68e4f8a771aa2c93387d3bf4079f949a51049abc6475b18f6d0317cd1347e9a
7
+ data.tar.gz: b1e599f20d38cc691af50637c1b1bfa4560b8a4368775a283473f719b6c474fcae7dbfa20261404fb9866ec97fcd1a03dad1fb69d6e50f7c08860ca7039cd0c8
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ --title RT Client
2
+ *.rb
data/rt/client.rb CHANGED
@@ -3,36 +3,42 @@
3
3
  require "rubygems"
4
4
  require "rest_client"
5
5
 
6
+ ## Author:: Tom Lahti
7
+ ## Copyright:: Copyright (c) 2013 Tom Lahti
8
+ ## License:: Apache 2.0
9
+
10
+ #{<img src="https://badge.fury.io/rb/rt-client.png" alt="Gem Version" />}[http://badge.fury.io/rb/rt-client]
6
11
  ##A ruby library API to Request Tracker's REST interface. Requires the
7
- ##rubygems rest-client, mail and mime-types to be installed. You can
12
+ ##rubygem rest-client be installed. You can
8
13
  ##create a file name .rtclientrc in the same directory as client.rb with a
9
14
  ##default server/user/pass to connect to RT as, so that you don't have to
10
15
  ##specify it/update it in lots of different scripts.
11
16
  ##
12
- ## Thanks to Brian McArdle for patch dealing with spaces in Custom Fields.
13
- ## To reference custom fields in RT that have spaces with rt-client, use an
14
- ## underscore in the rt-client code, e.g. "CF.{Has_Space}"
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}}"
15
20
  ##
16
- ## Thanks to Robert Vinson for 1.9.x compatibility when I couldn't be buggered
17
- ## and a great job of refactoring the old mess into something with much fewer
18
- ## dependencies.
21
+ ##Thanks to Robert Vinson for 1.9.x compatibility when I couldn't be buggered
22
+ ##and a great job of refactoring the old mess into something with much fewer
23
+ ##dependencies.
19
24
  ##
20
25
  ##TODO: Streaming, chunking attachments in compose method
21
26
  #
22
27
  # See each method for sample usage. To use this, "gem install rt-client" and
23
28
  #
24
29
  # require "rt/client"
30
+
25
31
  class RT_Client
26
32
 
27
- UA = "Mozilla/5.0 ruby RT Client Interface 0.6.4"
33
+ UA = "Mozilla/5.0 ruby RT Client Interface 0.6.8"
28
34
  attr_reader :status, :site, :version, :cookies, :server, :user, :cookie
29
35
 
30
36
  # Create a new RT_Client object. Load up our stored cookie and check it.
31
37
  # Log into RT again if needed and store the new cookie. You can specify
32
38
  # login and cookie storage directories in 3 different ways:
33
- # 1. Explicity during object creation
34
- # 2. From a .rtclientrc file in the working directory of your ruby program
35
- # 3. From a .rtclientrc file in the same directory as the library itself
39
+ # 1. Explicity during object creation
40
+ # 2. From a .rtclientrc file in the working directory of your ruby program
41
+ # 3. From a .rtclientrc file in the same directory as the library itself
36
42
  #
37
43
  # These are listed in order of priority; if you have explicit parameters,
38
44
  # they are always used, even if you have .rtclientrc files. If there
@@ -57,7 +63,7 @@ class RT_Client
57
63
  # cookies=<directory>
58
64
  def initialize(*params)
59
65
  @boundary = "----xYzZY#{rand(1000000).to_s}xYzZY"
60
- @version = "0.4.0"
66
+ @version = "0.6.8"
61
67
  @status = "Not connected"
62
68
  @server = "http://localhost/"
63
69
  @user = "rt_user"
@@ -102,7 +108,7 @@ class RT_Client
102
108
  end
103
109
 
104
110
 
105
- site = RestClient::Resource.new(@resource, :headers => headers, :timeout => 120)
111
+ site = RestClient::Resource.new(@resource, :headers => headers, :timeout => 240)
106
112
  data = site.post "" # a null post just to check that we are logged in
107
113
 
108
114
  if @cookie.length == 0 or data =~ /401/ # we're not logged in
@@ -180,33 +186,33 @@ class RT_Client
180
186
  reply = response_to_h(resp)
181
187
  end
182
188
 
183
- # Creates a new ticket. Requires a hash that contains RT form fields as
184
- # the keys. Capitalization is important; use :Queue, not :queue. You
185
- # will need at least :Queue to create a ticket. For a full list of fields
186
- # you can use, try "/opt/rt3/bin/rt edit ticket/1". Returns the newly
187
- # created ticket number, or a complete REST response.
188
- #
189
- # id = rt.create( :Queue => "Customer Service",
190
- # :Cc => "somebody\@email.com",
191
- # :Subject => "I've fallen and I can't get up",
192
- # :Text => "I think my hip is broken.\nPlease help.",
193
- # :"CF.{CustomField}" => "Urgent",
194
- def create(field_hash)
195
- field_hash[:id] = "ticket/new"
196
- payload = compose(field_hash)
197
- puts "Payload for new ticket:"
198
- puts payload
199
- resp = @site['ticket/new/edit'].post payload
200
- new_id = resp.match(/Ticket\s*(\d+)/)
201
- if new_id.class == MatchData
202
- new_ticket = new_id[1]
203
- else
204
- new_ticket = resp
205
- end
206
- new_ticket # return the ticket number, or the full REST response
207
- end
189
+ # Creates a new ticket. Requires a hash that contains RT form fields as
190
+ # the keys. Capitalization is important; use :Queue, not :queue. You
191
+ # will need at least :Queue to create a ticket. For a full list of fields
192
+ # you can use, try "/opt/rt3/bin/rt edit ticket/1". Returns the newly
193
+ # created ticket number, or a complete REST response.
194
+ #
195
+ # id = rt.create( :Queue => "Customer Service",
196
+ # :Cc => "somebody\@email.com",
197
+ # :Subject => "I've fallen and I can't get up",
198
+ # :Text => "I think my hip is broken.\nPlease help.",
199
+ # :"CF.{CustomField}" => "Urgent",
200
+ def create(field_hash)
201
+ field_hash[:id] = "ticket/new"
202
+ payload = compose(field_hash)
203
+ # puts "Payload for new ticket:"
204
+ # puts payload
205
+ resp = @site['ticket/new/edit'].post payload
206
+ new_id = resp.match(/Ticket\s*(\d+)/)
207
+ if new_id.class == MatchData
208
+ new_ticket = new_id[1]
209
+ else
210
+ new_ticket = resp
211
+ end
212
+ new_ticket # return the ticket number, or the full REST response
213
+ end
208
214
 
209
- # create a new user. Requires a hash of RT fields => values. Returns
215
+ # create a new user. Requires a hash of RT fields => values. Returns
210
216
  # the newly created user ID, or the full REST response if there is an error.
211
217
  # For a full list of possible parameters that you can specify, look at
212
218
  # "/opt/rt/bin/rt edit user/1"
@@ -295,7 +301,7 @@ class RT_Client
295
301
  # Find RT user details from an email address
296
302
  #
297
303
  # rt.usersearch(:EmailAddress => 'some@email.com')
298
- # => {"name"=>"rtlogin", "realname"=>"John Smith", "address1"=>"123 Main", etc }
304
+ # -> {"name"=>"rtlogin", "realname"=>"John Smith", "address1"=>"123 Main", etc }
299
305
  def usersearch(field_hash)
300
306
  if field_hash.has_key? :EmailAddress
301
307
  email = field_hash[:EmailAddress]
@@ -467,6 +473,7 @@ class RT_Client
467
473
  h = resp.split("\n").select{ |l| l =~ /^\d+:/ }
468
474
  else
469
475
  h = resp.split("\n").select{ |l| l =~ /^\d+: [^Comments]/ }
476
+ h.select!{ |l| l !~ /Outgoing email about a comment/ }
470
477
  end
471
478
  list = h.map { |l| l.split(":") }
472
479
  else
@@ -538,6 +545,7 @@ class RT_Client
538
545
  id = params[:id] if params.has_key? :id
539
546
  history = params[:history] if params.has_key? :history
540
547
  end
548
+ reply = {}
541
549
  resp = @site["ticket/#{id}/history/id/#{history}"].get
542
550
  return reply if resp =~ /not related/ # history id must be related to the ticket id
543
551
  resp.gsub!(/RT\/\d+\.\d+\.\d+\s\d{3}\s.*\n\n/,"") # toss the HTTP response
@@ -740,7 +748,7 @@ class RT_Client
740
748
  end
741
749
 
742
750
  # helper to convert responses from RT REST to a hash
743
- def response_to_h(resp)
751
+ def response_to_h(resp) # :nodoc:
744
752
  resp.gsub!(/RT\/\d+\.\d+\.\d+\s\d{3}\s.*\n\n/,"") # toss the HTTP response
745
753
  #resp.gsub!(/\n\n/,"\n") # remove double spacing, TMail stops at a blank line
746
754
 
@@ -774,7 +782,7 @@ class RT_Client
774
782
  # :Attachment key, the value is assumed to be a comma-separated list of
775
783
  # filenames to attach. It returns a hash to be used with rest-client's
776
784
  # payload class
777
- def compose(fields) # :doc:
785
+ def compose(fields) # :nodoc:
778
786
  if fields.class != Hash
779
787
  raise "RT_Client.compose requires parameters as a hash."
780
788
  end
metadata CHANGED
@@ -1,67 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rt-client
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.6.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.8
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Tom Lahti
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2013-07-31 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2013-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
16
14
  name: rest-client
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
21
17
  - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0.9"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
24
20
  type: :runtime
25
- version_requirements: *id001
26
- description: " RT_Client is a ruby object that accesses the REST interface version 1.0\n of a Request Tracker instance. See http://www.bestpractical.com/ for\n Request Tracker.\n"
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ description: |2
28
+ RT_Client is a ruby object that accesses the REST interface version 1.0
29
+ of a Request Tracker instance. See http://www.bestpractical.com/ for
30
+ Request Tracker.
27
31
  email: tlahti@dmsolutions.com
28
32
  executables: []
29
-
30
33
  extensions: []
31
-
32
34
  extra_rdoc_files: []
33
-
34
- files:
35
+ files:
36
+ - ".yardopts"
35
37
  - rt/client.rb
36
38
  - rt/rtxmlsrv.rb
37
- homepage:
38
- licenses: []
39
-
39
+ homepage: http://rubygems.org/gems/rt-client
40
+ licenses:
41
+ - APACHE-2.0
42
+ metadata: {}
40
43
  post_install_message:
41
- rdoc_options:
42
- - --inline-source
43
- - --main
44
+ rdoc_options:
45
+ - "--inline-source"
46
+ - "--main"
44
47
  - RT_Client
45
- require_paths:
46
- - .
47
- required_ruby_version: !ruby/object:Gem::Requirement
48
- none: false
49
- requirements:
48
+ require_paths:
49
+ - "."
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
50
52
  - - ">="
51
- - !ruby/object:Gem::Version
53
+ - !ruby/object:Gem::Version
52
54
  version: 1.8.6
53
- required_rubygems_version: !ruby/object:Gem::Requirement
54
- none: false
55
- requirements:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
56
57
  - - ">="
57
- - !ruby/object:Gem::Version
58
- version: "0"
59
- requirements:
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements:
60
61
  - A working installation of RT with the REST 1.0 interface
61
62
  rubyforge_project:
62
- rubygems_version: 1.8.24
63
+ rubygems_version: 2.0.6
63
64
  signing_key:
64
- specification_version: 3
65
+ specification_version: 4
65
66
  summary: Ruby object for RT access via REST
66
67
  test_files: []
67
-
68
+ has_rdoc: true