ludo-roart 0.1.17 → 0.1.18

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,7 +1,8 @@
1
1
  .DS_Store
2
+ .rvmrc
2
3
  announcement.txt
3
4
  coverage
4
5
  doc
5
6
  pkg
6
7
  *.gem
7
- **/.DS_Store
8
+ **/.DS_Store
data/Gemfile CHANGED
@@ -2,6 +2,8 @@ source :rubygems
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'rake', '0.9.2.2'
6
+
5
7
  gem 'rspec', '2.8.0'
6
8
 
7
9
  gem 'activesupport', '3.0.12'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ludo-roart (0.1.16)
4
+ ludo-roart (0.1.17)
5
5
  activesupport (>= 2.0.0)
6
6
  mechanize (>= 1.0.0)
7
7
 
@@ -26,6 +26,7 @@ GEM
26
26
  net-http-persistent (2.6)
27
27
  nokogiri (1.5.2)
28
28
  ntlm-http (0.1.1)
29
+ rake (0.9.2.2)
29
30
  rspec (2.8.0)
30
31
  rspec-core (~> 2.8.0)
31
32
  rspec-expectations (~> 2.8.0)
@@ -46,4 +47,5 @@ DEPENDENCIES
46
47
  activesupport (= 3.0.12)
47
48
  i18n
48
49
  ludo-roart!
50
+ rake (= 0.9.2.2)
49
51
  rspec (= 2.8.0)
@@ -4,13 +4,20 @@ module Roart
4
4
  def to_payload
5
5
  hash = Hash.new
6
6
  self.each_with_index do |attach, index|
7
- hash["attachment_#{index+1}"] = attach.file
7
+ hash["attachment_#{index+1}"] = attach
8
8
  end
9
9
  hash
10
10
  end
11
11
  end
12
12
 
13
- class Attachment < Struct.new(:name, :file)
13
+ class Attachment < File
14
+
15
+ attr_reader :name, :file
16
+
17
+ def initialize(name, file)
18
+ @name = name
19
+ @file = file
20
+ end
14
21
 
15
22
  def path
16
23
  name
@@ -20,6 +27,10 @@ module Roart
20
27
  file.read
21
28
  end
22
29
 
30
+ def mime_type
31
+ file.content_type if file.respond_to?(:content_type)
32
+ end
33
+
23
34
  def self.detect(*args)
24
35
  AttachmentCollection.new Array(args.compact).flatten.map { |file|
25
36
  if file.is_a?(File)
@@ -10,7 +10,7 @@ module Roart
10
10
 
11
11
  def login(config)
12
12
  @conf.merge!(config)
13
- agent = Mechanize.new
13
+ agent = RoartMechanize.new
14
14
  page = agent.get(@conf[:server])
15
15
  form = page.form('login')
16
16
  form.user = @conf[:user]
@@ -11,18 +11,20 @@ class Hash
11
11
  elsif key.to_s.match(/^CF-.+/)
12
12
  key.to_s
13
13
  elsif key.to_s.match(/^[a|A]ttachments/)
14
- values = values.join(",") if values.kind_of?(Array)
15
- "Attachment"
14
+ nil
16
15
  else
17
16
  key.to_s.camelize
18
17
  end
19
18
 
19
+ next if key_name.nil?
20
+
20
21
  values = [values] unless values.is_a?(Array)
21
22
  values.each do |value|
22
23
  value = Roart::ContentFormatter.format_string(value.to_s)
23
24
  fields << "#{key_name}: #{value}"
24
25
  end
25
26
  end
27
+
26
28
  content = fields.compact.sort.join("\n")
27
29
  end
28
30
 
@@ -0,0 +1,43 @@
1
+ module Roart
2
+ class RoartMechanize < Mechanize
3
+ ##
4
+ # POST to the given +uri+ with the given +query+. The query is specified by
5
+ # either a string, or a list of key-value pairs represented by a hash or an
6
+ # array of arrays.
7
+ #
8
+ # Examples:
9
+ # agent.post 'http://example.com/', "foo" => "bar"
10
+ #
11
+ # agent.post 'http://example.com/', [%w[foo bar]]
12
+ #
13
+ # agent.post('http://example.com/', "<message>hello</message>",
14
+ # 'Content-Type' => 'application/xml')
15
+
16
+ def post(uri, query={}, headers={})
17
+ return request_with_entity(:post, uri, query, headers) if String === query
18
+
19
+ node = {}
20
+ # Create a fake form
21
+ class << node
22
+ def search(*args); []; end
23
+ end
24
+ node['method'] = 'POST'
25
+ node['enctype'] = 'application/x-www-form-urlencoded'
26
+
27
+ form = Form.new(node)
28
+
29
+ query.each { |k, v|
30
+ if v.is_a?(IO)
31
+ form.enctype = 'multipart/form-data'
32
+ ul = Form::FileUpload.new({'name' => k.to_s},::File.basename(v.path))
33
+ ul.file_data = v.read
34
+ ul.mime_type = v.mime_type if v.respond_to?(:mime_type)
35
+ form.file_uploads << ul
36
+ else
37
+ form.fields << Form::Field.new({'name' => k.to_s},v)
38
+ end
39
+ }
40
+ post_form(uri, form, headers)
41
+ end
42
+ end
43
+ end
@@ -86,10 +86,10 @@ module Roart
86
86
 
87
87
  comment.merge!(:attachment => attachments.map(&:name).join(",")) unless attachments.empty?
88
88
 
89
- resp = self.class.connection.post(uri, {:content => comment.to_content_format}.merge(attachments.to_payload))
89
+ raw_resp = self.class.connection.post(uri, {:content => comment.to_content_format}.merge(attachments.to_payload))
90
90
 
91
- resp = resp.split("\n")
92
- raise TicketSystemError, "Ticket Comment Failed" unless resp.first.include?("200")
91
+ resp = raw_resp.split("\n")
92
+ raise TicketSystemError, "Ticket Comment Failed \n\n RT Response:\n#{raw_resp}" unless resp.first.include?("200")
93
93
  !!resp[2].match(/^# Message recorded/)
94
94
  end
95
95
 
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
13
  gem.name = "ludo-roart"
14
14
  gem.require_paths = ["lib"]
15
- gem.version = "0.1.17"
15
+ gem.version = "0.1.18"
16
16
 
17
17
  gem.add_runtime_dependency "mechanize", ">= 1.0.0"
18
18
  gem.add_runtime_dependency "activesupport", ">= 2.0.0"
@@ -25,11 +25,17 @@ describe 'hash extentions' do
25
25
  payload.to_content_format
26
26
  end
27
27
 
28
- it "should include attachments into content" do
29
- payload = {:subject => 'A new ticket', :queue => 'My queue', :text => "A text", :attachments => '/dev/null,/dev/zero'}
28
+ it "should include attachment as singular into content" do
29
+ payload = {:subject => 'A new ticket', :queue => 'My queue', :text => "A text", :attachment => 'just field'}
30
30
  payload.to_content_format.should include("Attachment")
31
31
  end
32
32
 
33
+ it "should NOT include attachments into content" do
34
+ payload = {:subject => 'A new ticket', :queue => 'My queue', :text => "A text", :attachments => '/dev/null,/dev/zero'}
35
+ payload.to_content_format.should_not include("Attachment")
36
+ payload.to_content_format.should_not include("Attachments")
37
+ end
38
+
33
39
  end
34
40
 
35
41
  it "should return sorted data with the same key multiple times when value is array" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ludo-roart
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 17
10
- version: 0.1.17
9
+ - 18
10
+ version: 0.1.18
11
11
  platform: ruby
12
12
  authors:
13
13
  - PJ Davis
@@ -16,8 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-04-05 00:00:00 +03:00
20
- default_executable:
19
+ date: 2012-04-09 00:00:00 Z
21
20
  dependencies:
22
21
  - !ruby/object:Gem::Dependency
23
22
  name: mechanize
@@ -79,6 +78,7 @@ files:
79
78
  - lib/roart/errors.rb
80
79
  - lib/roart/history.rb
81
80
  - lib/roart/roart.rb
81
+ - lib/roart/roart_mechanize.rb
82
82
  - lib/roart/ticket.rb
83
83
  - lib/roart/ticket_page.rb
84
84
  - lib/roart/validations.rb
@@ -101,7 +101,6 @@ files:
101
101
  - spec/test_data/search_ticket.txt
102
102
  - spec/test_data/single_history.txt
103
103
  - spec/test_data/ticket.txt
104
- has_rdoc: true
105
104
  homepage: https://github.com/ludo/roart
106
105
  licenses: []
107
106
 
@@ -131,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
130
  requirements: []
132
131
 
133
132
  rubyforge_project:
134
- rubygems_version: 1.5.2
133
+ rubygems_version: 1.8.15
135
134
  signing_key:
136
135
  specification_version: 3
137
136
  summary: Interface for working with Request Tracker (RT) tickets inspired by ActiveRecord