ticketmaster-redmine 0.2.8 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
 
6
- gem "ticketmaster", "0.6.10"
6
+ gem "ticketmaster", "~> 0.7.0"
7
7
  # Add dependencies to develop your gem here.
8
8
  # Include everything needed to run rake, tests, features, etc.
9
9
  group :development do
@@ -1,13 +1,13 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.2.2)
5
- activesupport (= 3.2.2)
4
+ activemodel (3.2.3)
5
+ activesupport (= 3.2.3)
6
6
  builder (~> 3.0.0)
7
- activeresource (3.2.2)
8
- activemodel (= 3.2.2)
9
- activesupport (= 3.2.2)
10
- activesupport (3.2.2)
7
+ activeresource (3.2.3)
8
+ activemodel (= 3.2.3)
9
+ activesupport (= 3.2.3)
10
+ activesupport (3.2.3)
11
11
  i18n (~> 0.6)
12
12
  multi_json (~> 1.0)
13
13
  builder (3.0.0)
@@ -34,7 +34,7 @@ GEM
34
34
  multi_json (~> 1.0.3)
35
35
  simplecov-html (~> 0.5.3)
36
36
  simplecov-html (0.5.3)
37
- ticketmaster (0.6.10)
37
+ ticketmaster (0.7.0)
38
38
  activeresource (~> 3.0)
39
39
  activesupport (~> 3.0)
40
40
  hashie (~> 1.2)
@@ -47,4 +47,4 @@ DEPENDENCIES
47
47
  rcov (~> 1.0)
48
48
  rspec (~> 2.8)
49
49
  simplecov (~> 0.5)
50
- ticketmaster (= 0.6.10)
50
+ ticketmaster (~> 0.7.0)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.3.0
@@ -0,0 +1,22 @@
1
+ #Reopening class to add ticket master espesific behavior without mixing it with RadmineAPI
2
+ class RedmineAPI::Issue
3
+ def to_ticket_hash
4
+ return :id => id.to_i,
5
+ :title => subject,
6
+ :created_at => created_on,
7
+ :updated_at => updated_on,
8
+ :project_id => project.id.to_i,
9
+ :status => status.name,
10
+ :priority => priority.name,
11
+ :priority_id => priority.id.to_i,
12
+ :requestor => author.name,
13
+ :assignee => author.name
14
+ end
15
+
16
+ def update_with(ticket)
17
+ self.subject = ticket.title
18
+ self.project_id = ticket.project_id
19
+ self.description = ticket.description
20
+ self
21
+ end
22
+ end
@@ -43,19 +43,6 @@ module TicketMaster::Provider
43
43
  def identifier
44
44
  self[:identifier]
45
45
  end
46
-
47
- def tickets(*options)
48
- Ticket.find(self.id, options)
49
- end
50
-
51
- def ticket(*options)
52
- unless options.empty?
53
- Ticket.find(self.id, options)
54
- else
55
- TicketMaster::Provider::Redmine::Ticket
56
- end
57
- end
58
-
59
46
  end
60
47
  end
61
48
  end
@@ -4,20 +4,21 @@ module TicketMaster::Provider
4
4
  include TicketMaster::Provider::Base
5
5
  PROJECT_API = RedmineAPI::Project
6
6
  TICKET_API = RedmineAPI::Issue
7
-
7
+
8
8
  # This is for cases when you want to instantiate using TicketMaster::Provider::Yoursystem.new(auth)
9
9
  def self.new(auth = {})
10
10
  TicketMaster.new(:redmine, auth)
11
11
  end
12
-
12
+
13
13
  # declare needed overloaded methods here
14
14
  def authorize(auth = {})
15
15
  @authentication ||= TicketMaster::Authenticator.new(auth)
16
16
  auth = @authentication
17
- if (auth.server.blank? and auth.username.blank? and auth.password.blank?)
18
- raise "Please you should provide server, username and password"
17
+ if auth.server.blank? and auth.token.blank?
18
+ raise "Please you should provide server and token"
19
19
  end
20
- RedmineAPI.authenticate(auth.server, auth.username, auth.password)
20
+
21
+ RedmineAPI.authenticate(auth.server, auth.token)
21
22
  end
22
23
 
23
24
  def valid?
@@ -7,23 +7,11 @@ module TicketMaster::Provider
7
7
  class Ticket < TicketMaster::Provider::Base::Ticket
8
8
  # declare needed overloaded methods here
9
9
 
10
- def initialize(*object)
11
- if object.first
12
- object = object.first
13
- unless object.is_a? Hash
14
- hash = {:id => object.id.to_i,
15
- :title => object.subject,
16
- :created_at => object.created_on,
17
- :updated_at => object.updated_on,
18
- :project_id => object.project.id.to_i,
19
- :status => object.status.name,
20
- :priority => object.priority.name,
21
- :requestor => object.author.name,
22
- :assignee => object.author.name}
23
- else
24
- hash = object
25
- end
26
- super hash
10
+ def initialize(*args)
11
+ case args.first
12
+ when Hash then super args.first
13
+ when RedmineAPI::Issue then super args.first.to_ticket_hash
14
+ else raise ArgumentError.new
27
15
  end
28
16
  end
29
17
 
@@ -36,7 +24,7 @@ module TicketMaster::Provider
36
24
  end
37
25
 
38
26
  def project_id
39
- self[:project].id.to_i
27
+ self[:project_id]
40
28
  end
41
29
 
42
30
  def status
@@ -46,7 +34,7 @@ module TicketMaster::Provider
46
34
  def priority
47
35
  self[:priority].name
48
36
  end
49
-
37
+
50
38
  def requestor
51
39
  self[:author].name
52
40
  end
@@ -58,41 +46,33 @@ module TicketMaster::Provider
58
46
  def id
59
47
  self[:id].to_i
60
48
  end
49
+
50
+ def description
51
+ self[:description]
52
+ end
61
53
 
62
- def self.find(project_id, *options)
63
- if options.first.is_a? Hash
64
- options[0].merge!(:params => {:project_id => project_id})
65
- super(*options)
66
- elsif options.empty?
67
- issues = RedmineAPI::Issue.find(:all, :params => {:project_id => project_id}).collect { |issue| TicketMaster::Provider::Redmine::Ticket.new issue }
68
- elsif options[0].first.is_a? Fixnum
69
- self.find_by_id(project_id, options[0].first)
70
- else
71
- super(*options)
72
- end
73
- end
74
-
75
- def self.find_by_id(project_id, ticket_id)
54
+ def self.find_by_id(project_id, ticket_id)
76
55
  self.new API.find(:first, :id => ticket_id)
77
- end
56
+ end
78
57
 
79
- def self.find_by_attributes(project_id, attributes = {})
80
- issues = API.find(:all, build_attributes(project_id, attributes))
58
+ def self.find_by_attributes(project_id, attributes = {})
59
+ issues = API.find(:all, attributes_for_request(project_id, attributes))
81
60
  issues.collect { |issue| self.new issue }
82
- end
83
-
84
- def self.build_attributes(repo, options)
85
- hash = {:repo => repo}.merge!(options)
86
- end
87
-
61
+ end
88
62
 
89
- def self.create(*options)
90
- issue = API.new(options.first.merge!(:status => 'New', :priority => 'Normal'))
91
- ticket = self.new issue
92
- issue.save
93
- ticket
63
+ def self.attributes_for_request(project_id, options)
64
+ hash = {:params => {:project_id => project_id}}.merge!(options)
94
65
  end
95
66
 
67
+ def self.create(attributes)
68
+ ticket = self.new(attributes)
69
+ ticket if ticket.save
70
+ end
71
+
72
+ def save
73
+ to_issue.new? ? to_issue.save : update
74
+ end
75
+
96
76
  def comments
97
77
  warn "Redmine doesn't support comments"
98
78
  []
@@ -107,6 +87,21 @@ module TicketMaster::Provider
107
87
  warn "Redmine doesn't support comments"
108
88
  []
109
89
  end
90
+
91
+ private
92
+ def find_issue
93
+ issue = API.find id, :params => {:project_id => self.project_id}
94
+ raise TicketMaster::Exception.new "Ticket with #{id} was not found" unless issue
95
+ issue
96
+ end
97
+
98
+ def update
99
+ find_issue.update_with(self).save
100
+ end
101
+
102
+ def to_issue
103
+ API.new.update_with(self)
104
+ end
110
105
 
111
106
  end
112
107
  end
@@ -7,12 +7,10 @@ module RedmineAPI
7
7
  class Error < StandardError; end
8
8
 
9
9
  class << self
10
- def authenticate(server, username, password)
11
- @username = username
12
- @password = password
10
+ attr_reader :token
11
+ def authenticate(server, token)
12
+ @token = token
13
13
  @server = server
14
- self::Base.user = username
15
- self::Base.password = password
16
14
  self::Base.site = server
17
15
  end
18
16
 
@@ -26,14 +24,13 @@ module RedmineAPI
26
24
  def self.inherited(base)
27
25
  RedmineAPI.resources << base
28
26
  end
27
+
28
+ def self.headers
29
+ {"X-Redmine-API-Key" => RedmineAPI.token}
30
+ end
29
31
  end
30
32
 
31
33
  class Issue < Base
32
- attr_reader :project_id
33
-
34
- def name
35
- self.subject
36
- end
37
34
  end
38
35
 
39
36
  class Project < Base
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/redmine/redmine-api'
2
2
 
3
- %w{ redmine ticket project comment }.each do |f|
3
+ %w{ redmine ticket project comment api-extensions }.each do |f|
4
4
  require File.dirname(__FILE__) + '/provider/' + f + '.rb';
5
5
  end
6
6
 
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Ticketmaster::Provider::Redmine::Project" do
4
4
  before(:each) do
5
- headers = {'Authorization' => 'Basic Y29yZWQ6MTIzNDU2', 'Accept' => 'application/xml'}
5
+ headers = {'X-Redmine-API-Key' => 'abcdefghijk', 'Accept' => 'application/xml'}
6
6
  headers_post_put = {'Authorization' => 'Basic Y29yZWQ6MTIzNDU2', 'Content-Type' => 'application/xml'}
7
7
  @project_id = '1'
8
8
  ActiveResource::HttpMock.respond_to do |mock|
@@ -12,7 +12,7 @@ describe "Ticketmaster::Provider::Redmine::Project" do
12
12
  mock.post '/projects.xml', headers_post_put, '', 200
13
13
  end
14
14
 
15
- @ticketmaster = TicketMaster.new(:redmine, {:server => 'http://demo.redmine.org/', :username => 'cored', :password => '123456'})
15
+ @ticketmaster = TicketMaster.new :redmine, :server => 'http://demo.redmine.org/', :token => 'abcdefghijk'
16
16
  @klass = TicketMaster::Provider::Redmine::Project
17
17
  end
18
18
 
@@ -2,7 +2,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Ticketmaster::Provider::Redmine" do
4
4
 
5
- before(:each) do
5
+ before :each do
6
6
  headers = {'Authorization' => 'Basic Y29yZWQ6YWZkZA==', 'Accept' => 'application/xml'}
7
7
  ActiveResource::HttpMock.respond_to do |mock|
8
8
  mock.get '/projects.xml', headers, fixture_for('projects'), 200
@@ -10,14 +10,9 @@ describe "Ticketmaster::Provider::Redmine" do
10
10
  end
11
11
 
12
12
  it "should be able to instantiate a new instance" do
13
- @ticketmaster = TicketMaster.new(:redmine, {:server => 'http://redmine.server', :username => 'cored', :password => 'afdd'})
14
- @ticketmaster.should be_an_instance_of(TicketMaster)
15
- @ticketmaster.should be_a_kind_of(TicketMaster::Provider::Redmine)
16
- end
17
-
18
- it "should implmement the valid method" do
19
- @ticketmaster = TicketMaster.new(:redmine, {:server => 'http://redmine.server', :username => 'cored', :password => 'afdd'})
20
- @ticketmaster.valid?.should be_true
13
+ ticketmaster = TicketMaster.new(:redmine, :server => 'http://redmine.server', :token => 'kdkjkladkaldj')
14
+ ticketmaster.should be_an_instance_of(TicketMaster)
15
+ ticketmaster.should be_a_kind_of(TicketMaster::Provider::Redmine)
21
16
  end
22
17
 
23
18
  end
@@ -2,8 +2,8 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Ticketmaster::Provider::Redmine::Ticket" do
4
4
  before(:each) do
5
- headers = {'Authorization' => 'Basic Y29yZWQ6MTIzNDU2', 'Accept' => 'application/xml'}
6
- headers_post_put = {'Authorization' => 'Basic Y29yZWQ6MTIzNDU2', 'Content-Type' => 'application/xml'}
5
+ headers = {'X-Redmine-API-Key' => 'abcdefghijk', 'Accept' => 'application/xml'}
6
+ headers_post_put = {'X-Redmine-API-Key' => 'abcdefghijk', 'Content-Type' => 'application/xml'}
7
7
  @project_id = 1
8
8
  ActiveResource::HttpMock.respond_to do |mock|
9
9
  mock.get '/projects.xml', headers, fixture_for('projects'), 200
@@ -15,7 +15,7 @@ describe "Ticketmaster::Provider::Redmine::Ticket" do
15
15
  mock.post '/issues.xml', headers_post_put, '', 200
16
16
  end
17
17
 
18
- @ticketmaster = TicketMaster.new(:redmine, {:server => 'http://demo.redmine.org/', :username => 'cored', :password => '123456'})
18
+ @ticketmaster = TicketMaster.new :redmine, :server => 'http://demo.redmine.org/', :token => 'abcdefghijk'
19
19
  @project = @ticketmaster.project(@project_id)
20
20
  @klass = TicketMaster::Provider::Redmine::Ticket
21
21
  end
@@ -49,17 +49,16 @@ describe "Ticketmaster::Provider::Redmine::Ticket" do
49
49
  @ticket.title.should == 'test-issue'
50
50
  end
51
51
 
52
- it "should be able to update and save a ticket" do
53
- pending
52
+ it "should be able to update and save a ticket" do
54
53
  @ticket = @project.ticket(1)
55
54
  @ticket.description = 'hello'
56
55
  @ticket.save.should == true
57
56
  end
58
57
 
59
58
  it "should be able to create a ticket" do
60
- pending
61
- @ticket = @project.ticket!(:subject => 'Ticket #12', :description => 'Body')
59
+ @ticket = @project.ticket!(:title => 'Ticket #12', :description => 'Body')
62
60
  @ticket.should be_an_instance_of(@klass)
61
+ @ticket.project_id.should_not be_nil
63
62
  end
64
63
 
65
64
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "ticketmaster-redmine"
8
- s.version = "0.2.8"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Rafael George"]
12
- s.date = "2012-03-27"
12
+ s.date = "2012-04-19"
13
13
  s.description = "Allows ticketmaster to interact with Your System."
14
14
  s.email = "rafael@hybridgroup.com"
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "README.md",
27
27
  "Rakefile",
28
28
  "VERSION",
29
+ "lib/provider/api-extensions.rb",
29
30
  "lib/provider/comment.rb",
30
31
  "lib/provider/project.rb",
31
32
  "lib/provider/redmine.rb",
@@ -53,20 +54,20 @@ Gem::Specification.new do |s|
53
54
  s.specification_version = 3
54
55
 
55
56
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
- s.add_runtime_dependency(%q<ticketmaster>, ["= 0.6.10"])
57
+ s.add_runtime_dependency(%q<ticketmaster>, ["~> 0.7.0"])
57
58
  s.add_development_dependency(%q<rspec>, ["~> 2.8"])
58
59
  s.add_development_dependency(%q<jeweler>, ["~> 1.6"])
59
60
  s.add_development_dependency(%q<simplecov>, ["~> 0.5"])
60
61
  s.add_development_dependency(%q<rcov>, ["~> 1.0"])
61
62
  else
62
- s.add_dependency(%q<ticketmaster>, ["= 0.6.10"])
63
+ s.add_dependency(%q<ticketmaster>, ["~> 0.7.0"])
63
64
  s.add_dependency(%q<rspec>, ["~> 2.8"])
64
65
  s.add_dependency(%q<jeweler>, ["~> 1.6"])
65
66
  s.add_dependency(%q<simplecov>, ["~> 0.5"])
66
67
  s.add_dependency(%q<rcov>, ["~> 1.0"])
67
68
  end
68
69
  else
69
- s.add_dependency(%q<ticketmaster>, ["= 0.6.10"])
70
+ s.add_dependency(%q<ticketmaster>, ["~> 0.7.0"])
70
71
  s.add_dependency(%q<rspec>, ["~> 2.8"])
71
72
  s.add_dependency(%q<jeweler>, ["~> 1.6"])
72
73
  s.add_dependency(%q<simplecov>, ["~> 0.5"])
metadata CHANGED
@@ -1,8 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ticketmaster-redmine
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease:
5
- version: 0.2.8
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
6
11
  platform: ruby
7
12
  authors:
8
13
  - Rafael George
@@ -10,62 +15,83 @@ autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
17
 
13
- date: 2012-03-27 00:00:00 Z
18
+ date: 2012-04-19 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: ticketmaster
22
+ prerelease: false
23
+ type: :runtime
17
24
  requirement: &id001 !ruby/object:Gem::Requirement
18
25
  none: false
19
26
  requirements:
20
- - - "="
27
+ - - ~>
21
28
  - !ruby/object:Gem::Version
22
- version: 0.6.10
23
- type: :runtime
24
- prerelease: false
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ - 7
33
+ - 0
34
+ version: 0.7.0
25
35
  version_requirements: *id001
26
36
  - !ruby/object:Gem::Dependency
27
37
  name: rspec
38
+ prerelease: false
39
+ type: :development
28
40
  requirement: &id002 !ruby/object:Gem::Requirement
29
41
  none: false
30
42
  requirements:
31
43
  - - ~>
32
44
  - !ruby/object:Gem::Version
45
+ hash: 19
46
+ segments:
47
+ - 2
48
+ - 8
33
49
  version: "2.8"
34
- type: :development
35
- prerelease: false
36
50
  version_requirements: *id002
37
51
  - !ruby/object:Gem::Dependency
38
52
  name: jeweler
53
+ prerelease: false
54
+ type: :development
39
55
  requirement: &id003 !ruby/object:Gem::Requirement
40
56
  none: false
41
57
  requirements:
42
58
  - - ~>
43
59
  - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 1
63
+ - 6
44
64
  version: "1.6"
45
- type: :development
46
- prerelease: false
47
65
  version_requirements: *id003
48
66
  - !ruby/object:Gem::Dependency
49
67
  name: simplecov
68
+ prerelease: false
69
+ type: :development
50
70
  requirement: &id004 !ruby/object:Gem::Requirement
51
71
  none: false
52
72
  requirements:
53
73
  - - ~>
54
74
  - !ruby/object:Gem::Version
75
+ hash: 1
76
+ segments:
77
+ - 0
78
+ - 5
55
79
  version: "0.5"
56
- type: :development
57
- prerelease: false
58
80
  version_requirements: *id004
59
81
  - !ruby/object:Gem::Dependency
60
82
  name: rcov
83
+ prerelease: false
84
+ type: :development
61
85
  requirement: &id005 !ruby/object:Gem::Requirement
62
86
  none: false
63
87
  requirements:
64
88
  - - ~>
65
89
  - !ruby/object:Gem::Version
90
+ hash: 15
91
+ segments:
92
+ - 1
93
+ - 0
66
94
  version: "1.0"
67
- type: :development
68
- prerelease: false
69
95
  version_requirements: *id005
70
96
  description: Allows ticketmaster to interact with Your System.
71
97
  email: rafael@hybridgroup.com
@@ -86,6 +112,7 @@ files:
86
112
  - README.md
87
113
  - Rakefile
88
114
  - VERSION
115
+ - lib/provider/api-extensions.rb
89
116
  - lib/provider/comment.rb
90
117
  - lib/provider/project.rb
91
118
  - lib/provider/redmine.rb
@@ -116,12 +143,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
143
  requirements:
117
144
  - - ">="
118
145
  - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
119
149
  version: "0"
120
150
  required_rubygems_version: !ruby/object:Gem::Requirement
121
151
  none: false
122
152
  requirements:
123
153
  - - ">="
124
154
  - !ruby/object:Gem::Version
155
+ hash: 3
156
+ segments:
157
+ - 0
125
158
  version: "0"
126
159
  requirements: []
127
160