ticketmaster-trac 0.0.1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,6 +22,10 @@ Right now Trac doesn't support project handling, that's why you will use a proje
22
22
 
23
23
  ticket = project.ticket!({:summary => "New ticket", :description=> "Body for the very new ticket"}, attributes) # summary and description are mandatory fields the attributes hash will contain all the optional info that you need for your ticket, have to use the fields provided by Trac api.
24
24
 
25
+ == Finding comments
26
+
27
+ comments = project.tickets.first.comments # All the tickets facility for searchs are available for comments as well
28
+
25
29
 
26
30
  ## Requirements
27
31
 
data/Rakefile CHANGED
@@ -16,6 +16,7 @@ begin
16
16
  gem.add_dependency "activeresource", ">= 2.3.2"
17
17
  gem.add_dependency "addressable", ">= 2.1.2"
18
18
  gem.add_dependency "trac4r"
19
+ gem.add_dependency "nokogiri"
19
20
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
21
  end
21
22
  Jeweler::GemcutterTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.1
@@ -8,6 +8,23 @@ module TicketMaster::Provider
8
8
  class Comment < TicketMaster::Provider::Base::Comment
9
9
  # declare needed overloaded methods here
10
10
 
11
+ def initialize(*object)
12
+ if object.first
13
+ object = object.first
14
+ unless object.is_a? Hash
15
+ @system_data = {:client => object}
16
+ hash = {:id => object.id,
17
+ :author => object.author,
18
+ :body => object.body,
19
+ :ticket_id => object.ticket_id,
20
+ :created_at => object.created_at,
21
+ :updated_at => object.updated_at}
22
+ else
23
+ hash = object
24
+ end
25
+ super(hash)
26
+ end
27
+ end
11
28
  end
12
29
  end
13
30
  end
@@ -49,14 +49,33 @@ module TicketMaster::Provider
49
49
  end
50
50
  end
51
51
 
52
- def comments
53
- warn "Trac doesn't support comments"
54
- []
52
+ def comments(*options)
53
+ comments = CommentUtil.new(self.id).comments.collect { |comment| TicketMaster::Provider::Trac::Comment.new comment }
54
+ if options.first.is_a? Array
55
+ comments.select do |comment|
56
+ comment if options.first.any? { |id| id == comment.id }
57
+ end
58
+ elsif options.first.is_a? Hash
59
+ hash = options.first
60
+ comments.select do |key, value|
61
+ hash[key] == value
62
+ end
63
+ else
64
+ comments
65
+ end
55
66
  end
56
67
 
57
- def comment
58
- warn "Trac doesn't support comments"
59
- nil
68
+ def comment(*options)
69
+ comments = CommentUtil.new(self.id).comments.collect { |comment| TicketMaster::Provider::Trac::Comment.new comment }
70
+ if options.empty?
71
+ TicketMaster::Provider::Trac::Comment.new
72
+ elsif options.first.is_a? Fixnum
73
+ comments.select { |comment| comment[:id] == options.first }.first
74
+ elsif options.first.is_a? Hash
75
+ comments.select do |key, value|
76
+ options.first[key] == value
77
+ end.first
78
+ end
60
79
  end
61
80
 
62
81
  def comment!
data/lib/provider/trac.rb CHANGED
@@ -12,7 +12,7 @@ module TicketMaster::Provider
12
12
  @authentication ||= TicketMaster::Authenticator.new(auth)
13
13
  auth = @authentication
14
14
  @trac = ::Trac.new(auth.url, auth.username, auth.password)
15
- TracAPI.new @trac, auth.url, auth.username
15
+ TracAPI.new @trac, auth.url, auth.username, auth.password
16
16
  end
17
17
 
18
18
  # declare needed overloaded methods here
@@ -1,4 +1,6 @@
1
1
  require 'trac4r'
2
+ require 'nokogiri'
3
+ require 'open-uri'
2
4
 
3
5
  require 'lib/trac/trac'
4
6
 
data/lib/trac/trac.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  # code to communicate with your backend goes here...
2
2
 
3
3
  class TracAPI
4
- def initialize(trac, username, url)
4
+ def initialize(trac, url, username, password)
5
5
  @@api = trac
6
6
  @@username = username
7
7
  @@url = url
8
+ @@password = password
8
9
  end
9
10
 
10
11
  def self.api
@@ -18,6 +19,41 @@ class TracAPI
18
19
  def self.username
19
20
  @@username
20
21
  end
22
+
23
+ def self.password
24
+ @@password
25
+ end
26
+ end
27
+
28
+ class CommentUtil
29
+
30
+ def initialize(ticket_id)
31
+ @doc = Nokogiri::HTML(open("#{TracAPI.url}/ticket/#{ticket_id}", :http_basic_authentication=>[TracAPI.username, TracAPI.password]))
32
+ end
33
+
34
+ def comments
35
+ comment_id = 0
36
+ @doc.css('h3.change a.timeline').collect do |value|
37
+ body = @doc.css('div.comment p')
38
+ comment_id += 1
39
+ build_comment_hash(value, comment_id, body[comment_id-1].text)
40
+ end
41
+ end
42
+
43
+ private
44
+ def build_comment_hash(value, comment_id, body)
45
+ comment = {}
46
+ comment[:created_at] = date_from_attributes(value)
47
+ comment[:updated_at] = date_from_attributes(value)
48
+ comment[:ticket_id] = @ticket_id
49
+ comment[:body] = body
50
+ comment[:id] = comment_id
51
+ comment
52
+ end
53
+
54
+ def date_from_attributes(value)
55
+ value.attributes["title"].value.split(/\s/)[0]
56
+ end
21
57
  end
22
58
 
23
59
 
@@ -1,5 +1,48 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Ticketmaster::Provider::Trac::Comment" do
4
- it "should have specs for comments"
4
+ before(:each) do
5
+ @ticketmaster = TicketMaster.new(:trac, {:username => 'george.rafael@gmail.com', :password => '123456', :url => 'http://pl3.projectlocker.com/cored/testrepo/trac'})
6
+ @project = @ticketmaster.projects.first
7
+ @ticket = @project.tickets.first
8
+ @klass = TicketMaster::Provider::Trac::Comment
9
+ end
10
+
11
+ it "should load all comments from a ticket" do
12
+ @ticket.comments.should be_an_instance_of(Array)
13
+ @ticket.comments.first.should be_an_instance_of(@klass)
14
+ end
15
+
16
+ it "should be able to load all comments based on id's" do
17
+ @comments = @ticket.comments([1,2])
18
+ @comments.should be_an_instance_of(Array)
19
+ @comments.first.id.should == 1
20
+ @comments.last.id.should == 2
21
+ @comments[1].should be_an_instance_of(@klass)
22
+ end
23
+
24
+ it "should be able to load comments throught attributes" do
25
+ @comments = @ticket.comments(:ticket_id => 1)
26
+ @comments.should be_an_instance_of(Array)
27
+ @comments.first.id.should == 1
28
+ @comments.last.id.should == 2
29
+ @comments[1].should be_an_instance_of(@klass)
30
+ end
31
+
32
+ it "should be able to load a comment based on id" do
33
+ @comment = @ticket.comment(2)
34
+ @comment.should be_an_instance_of(@klass)
35
+ @comment.id.should == 2
36
+ end
37
+
38
+ it "should return the comment class" do
39
+ @ticket.comment.should be_an_instance_of(@klass)
40
+ end
41
+
42
+ it "should be able to load a comment using attributes" do
43
+ @comment = @ticket.comment(:ticket_id => 1)
44
+ @comment.should be_an_instance_of(@klass)
45
+ @comment.id.should == 1
46
+ end
47
+
5
48
  end
@@ -0,0 +1,82 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ticketmaster-trac}
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Rafael George"]
12
+ s.date = %q{2011-01-06}
13
+ s.description = %q{Allows ticketmaster to interact with Your System.}
14
+ s.email = %q{george.rafael@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README.md",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "lib/provider/comment.rb",
25
+ "lib/provider/project.rb",
26
+ "lib/provider/ticket.rb",
27
+ "lib/provider/trac.rb",
28
+ "lib/ticketmaster-trac.rb",
29
+ "lib/trac/trac.rb",
30
+ "spec/comments_spec.rb",
31
+ "spec/fixtures/tickets.xml",
32
+ "spec/projects_spec.rb",
33
+ "spec/spec.opts",
34
+ "spec/spec_helper.rb",
35
+ "spec/ticketmaster-trac_spec.rb",
36
+ "spec/tickets_spec.rb",
37
+ "ticketmaster-trac.gemspec"
38
+ ]
39
+ s.homepage = %q{http://bandw.tumblr.com}
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{Ticketmaster Provider for Trac}
43
+ s.test_files = [
44
+ "spec/comments_spec.rb",
45
+ "spec/projects_spec.rb",
46
+ "spec/spec_helper.rb",
47
+ "spec/ticketmaster-trac_spec.rb",
48
+ "spec/tickets_spec.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
57
+ s.add_runtime_dependency(%q<ticketmaster>, [">= 0.1.0"])
58
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3.2"])
59
+ s.add_runtime_dependency(%q<activeresource>, [">= 2.3.2"])
60
+ s.add_runtime_dependency(%q<addressable>, [">= 2.1.2"])
61
+ s.add_runtime_dependency(%q<trac4r>, [">= 0"])
62
+ s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
63
+ else
64
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
65
+ s.add_dependency(%q<ticketmaster>, [">= 0.1.0"])
66
+ s.add_dependency(%q<activesupport>, [">= 2.3.2"])
67
+ s.add_dependency(%q<activeresource>, [">= 2.3.2"])
68
+ s.add_dependency(%q<addressable>, [">= 2.1.2"])
69
+ s.add_dependency(%q<trac4r>, [">= 0"])
70
+ s.add_dependency(%q<nokogiri>, [">= 0"])
71
+ end
72
+ else
73
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
74
+ s.add_dependency(%q<ticketmaster>, [">= 0.1.0"])
75
+ s.add_dependency(%q<activesupport>, [">= 2.3.2"])
76
+ s.add_dependency(%q<activeresource>, [">= 2.3.2"])
77
+ s.add_dependency(%q<addressable>, [">= 2.1.2"])
78
+ s.add_dependency(%q<trac4r>, [">= 0"])
79
+ s.add_dependency(%q<nokogiri>, [">= 0"])
80
+ end
81
+ end
82
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ticketmaster-trac
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rafael George
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-30 00:00:00 +00:00
18
+ date: 2011-01-06 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -112,6 +112,20 @@ dependencies:
112
112
  version: "0"
113
113
  type: :runtime
114
114
  version_requirements: *id006
115
+ - !ruby/object:Gem::Dependency
116
+ name: nokogiri
117
+ prerelease: false
118
+ requirement: &id007 !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ type: :runtime
128
+ version_requirements: *id007
115
129
  description: Allows ticketmaster to interact with Your System.
116
130
  email: george.rafael@gmail.com
117
131
  executables: []
@@ -139,6 +153,7 @@ files:
139
153
  - spec/spec_helper.rb
140
154
  - spec/ticketmaster-trac_spec.rb
141
155
  - spec/tickets_spec.rb
156
+ - ticketmaster-trac.gemspec
142
157
  has_rdoc: true
143
158
  homepage: http://bandw.tumblr.com
144
159
  licenses: []