taskmapper-zendesk 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.DS_Store ADDED
Binary file
data/.rbenv-gemsets ADDED
@@ -0,0 +1 @@
1
+ ticketmaster-zendesk
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@taskmapper-zendesk --create
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "taskmapper", "~> 0.8"
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "rspec", "~> 2.8"
11
+ gem "bundler", "~> 1.1"
12
+ gem "jeweler", "~> 1.6"
13
+ gem "simplecov", "~> 0.5", :platforms => :ruby_19
14
+ gem "rcov", "~> 1.0", :platforms => :ruby_18
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.2.3)
5
+ activesupport (= 3.2.3)
6
+ builder (~> 3.0.0)
7
+ activeresource (3.2.3)
8
+ activemodel (= 3.2.3)
9
+ activesupport (= 3.2.3)
10
+ activesupport (3.2.3)
11
+ i18n (~> 0.6)
12
+ multi_json (~> 1.0)
13
+ builder (3.0.0)
14
+ diff-lcs (1.1.3)
15
+ git (1.2.5)
16
+ hashie (1.2.0)
17
+ i18n (0.6.0)
18
+ jeweler (1.6.4)
19
+ bundler (~> 1.0)
20
+ git (>= 1.2.5)
21
+ rake
22
+ multi_json (1.0.4)
23
+ rake (0.9.2.2)
24
+ rcov (1.0.0)
25
+ rspec (2.8.0)
26
+ rspec-core (~> 2.8.0)
27
+ rspec-expectations (~> 2.8.0)
28
+ rspec-mocks (~> 2.8.0)
29
+ rspec-core (2.8.0)
30
+ rspec-expectations (2.8.0)
31
+ diff-lcs (~> 1.1.2)
32
+ rspec-mocks (2.8.0)
33
+ simplecov (0.5.4)
34
+ multi_json (~> 1.0.3)
35
+ simplecov-html (~> 0.5.3)
36
+ simplecov-html (0.5.3)
37
+ taskmapper (0.8.0)
38
+ activeresource (~> 3.0)
39
+ activesupport (~> 3.0)
40
+ hashie (~> 1.2)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.1)
47
+ jeweler (~> 1.6)
48
+ rcov (~> 1.0)
49
+ rspec (~> 2.8)
50
+ simplecov (~> 0.5)
51
+ taskmapper (~> 0.8)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2010 YOU
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ NONE
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # taskmapper-redmine
2
+
3
+ This is a provider for [taskmapper](http://ticketrb.com). It provides interoperability with [Zendesk](http://www.zendesk.com) and it's issue tracking system through the taskmapper gem.
4
+
5
+ Right now this provider only supports reading operations.
6
+
7
+ # Usage and Examples
8
+
9
+ First we have to instantiate a new taskmapper instance:
10
+
11
+ zendesk = taskmapper.new(:zendesk, {:account => 'hybridgroup', :username => "foo", :password => "bar"})
12
+
13
+ If you do not pass in account, username and password, you won't get any information.
14
+
15
+ ## Finding Projects
16
+
17
+ You can find your own projects by doing:
18
+
19
+ projects = zendesk.projects # Will return all your repositories
20
+ projects = zendesk.projects(['your_repo1']) # You must use your projects identifier
21
+ project = zendesk.project('your_repo') # Also use project identifier in here
22
+
23
+ Note: Zendesk dosen't support a projects which means this is a taskmapper place holder object, you will always get the same project name as follows: 'accountname-project'.
24
+
25
+
26
+ ## Finding Tickets
27
+
28
+ tickets = project.tickets # All open issues
29
+ tickets = project.tickets([1,2]) # An array of tickets with the specified id's
30
+ ticket = project.ticket(<issue_number>)
31
+
32
+ ## Finding Comments
33
+
34
+ comments = tickets.comments
35
+ comments = tickets.comments([1,2]) # An array of comments with the specified id's
36
+
37
+
38
+ ## Requirements
39
+
40
+ * rubygems (obviously)
41
+ * taskmapper gem (latest version preferred)
42
+ * jeweler gem (only if you want to repackage and develop)
43
+
44
+ The taskmapper gem should automatically be installed during the installation of this gem if it is not already installed.
45
+
46
+ ## Other Notes
47
+
48
+ Since this and the taskmapper gem is still primarily a work-in-progress, minor changes may be incompatible with previous versions. Please be careful about using and updating this gem in production.
49
+
50
+ If you see or find any issues, feel free to open up an issue report.
51
+
52
+
53
+ ## Note on Patches/Pull Requests
54
+
55
+ * Fork the project.
56
+ * Make your feature addition or bug fix.
57
+ * Add tests for it. This is important so we don't break it in a
58
+ future version unintentionally.
59
+ * Commit, do not mess with rakefile, version, or history.
60
+ (if you want to have your own version, that is fine but bump version in a commit by itself so we can ignore when I pull)
61
+ * Send us a pull request. Bonus points for topic branches.
62
+
63
+ ## Copyright
64
+
65
+ Copyright (c) 2010 The Hybrid Group. See LICENSE for details.
66
+
67
+
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "taskmapper-zendesk"
8
+ gem.summary = %Q{taskmapper Provider for Zendesk}
9
+ gem.description = %Q{Allows taskmapper to interact with Your System.}
10
+ gem.email = "rafael@hybridgroup.com"
11
+ gem.homepage = "http://github.com/hybridgroup/taskmapper-zendesk"
12
+ gem.authors = ["Rafael George"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rspec/core'
21
+ require 'rspec/core/rake_task'
22
+ RSpec::Core::RakeTask.new(:spec) do |spec|
23
+ spec.pattern = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+ task :default => :spec
32
+
33
+ require 'rake/rdoctask'
34
+ Rake::RDocTask.new do |rdoc|
35
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
36
+
37
+ rdoc.rdoc_dir = 'rdoc'
38
+ rdoc.title = "taskmapper-redmine#{version}"
39
+ rdoc.rdoc_files.include('README*')
40
+ rdoc.rdoc_files.include('lib/**/*.rb')
41
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.0
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,74 @@
1
+ module TaskMapper::Provider
2
+ module Zendesk
3
+ # The comment class for taskmapper-zendesk
4
+ #
5
+ # Do any mapping between taskmapper and your system's comment model here
6
+ # versions of the ticket.
7
+ #
8
+ class Comment < TaskMapper::Provider::Base::Comment
9
+ # declare needed overloaded methods here
10
+
11
+ USER_API = ZendeskAPI::User
12
+
13
+ def initialize(*object)
14
+ return super(object.first) if object.first.is_a? Hash
15
+ if object.first
16
+ object = object.first
17
+ ticket_id = object.shift
18
+ project_id = object.shift
19
+ comment_id = object.shift
20
+ object = object.shift
21
+ @system_data = {:client => object}
22
+ unless object.is_a? Hash
23
+ hash = {:author => object.author_id,
24
+ :body => object.value,
25
+ :id => comment_id,
26
+ :created_at => object.created_at,
27
+ :updated_at => object.created_at,
28
+ :ticket_id => ticket_id,
29
+ :project_id => project_id}
30
+ else
31
+ hash = object
32
+ end
33
+ super hash
34
+ end
35
+ end
36
+
37
+ def created_at
38
+ Time.parse(self[:created_at])
39
+ end
40
+
41
+ def updated_at
42
+ Time.parse(self[:updated_at])
43
+ end
44
+
45
+ def self.find(project_id, ticket_id, *options)
46
+ ticket_comments = self.find_all(project_id, ticket_id)
47
+ if options[0].first.is_a? Array
48
+ ticket_comments.select do |comment|
49
+ comment if options[0].first.any? { |comment_id| comment_id == comment.id }
50
+ end
51
+ elsif options[0].first.is_a? Hash
52
+ self.find_by_attributes(project_id, ticket_id, options[0].first)
53
+ else
54
+ ticket_comments
55
+ end
56
+ end
57
+
58
+ def self.find_all(project_id, ticket_id)
59
+ comment_id = 0
60
+ ZendeskAPI::Ticket.find(ticket_id).comments.collect do |comment|
61
+ comment_id += 1
62
+ comment.author_id = USER_API.find(comment.author_id).email
63
+ Comment.new [ticket_id, project_id, comment_id, comment]
64
+ end
65
+ end
66
+
67
+ def self.find_by_attributes(project_id, ticket_id, attributes = {})
68
+ search_by_attribute(self.find_all(project_id, ticket_id), attributes)
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,58 @@
1
+ module TaskMapper::Provider
2
+ module Zendesk
3
+ # Project class for taskmapper-zendesk
4
+ #
5
+ #
6
+ class Project < TaskMapper::Provider::Base::Project
7
+ attr_accessor :prefix_options
8
+ #API = ZendeskAPI::Organization
9
+ # declare needed overloaded methods here
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 = {:repository => object.account,
17
+ :user => object.username,
18
+ :name => object.name}
19
+ else
20
+ hash = object
21
+ end
22
+ super hash
23
+ end
24
+ end
25
+
26
+ # copy from this.copy(that) copies that into this
27
+ def copy(project)
28
+ project.tickets.each do |ticket|
29
+ copy_ticket = self.ticket!(:title => ticket.title, :description => ticket.description)
30
+ ticket.comments.each do |comment|
31
+ copy_ticket.comment!(:body => comment.body)
32
+ sleep 1
33
+ end
34
+ end
35
+ end
36
+
37
+ def tickets(*options)
38
+ Ticket.find(self.name, options)
39
+ end
40
+
41
+ def ticket(*options)
42
+ if options.first.is_a? Fixnum
43
+ ticket_id = options.first
44
+ Ticket.find_by_id(self.name, ticket_id)
45
+ elsif options.first.is_a? Hash
46
+ Ticket.find_by_attributes(self.name, options.first).first
47
+ else
48
+ TaskMapper::Provider::Zendesk::Ticket
49
+ end
50
+ end
51
+
52
+ def ticket!(*options)
53
+ Ticket.new ZendeskAPI::Ticket.create(options.first), self.name
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,97 @@
1
+
2
+ module TaskMapper::Provider
3
+ module Zendesk
4
+
5
+ class Ticket < TaskMapper::Provider::Base::Ticket
6
+ # declare needed overloaded methods here
7
+
8
+ SEARCH_API = ZendeskAPI::Search
9
+ API = ZendeskAPI::Ticket
10
+ USER_API = ZendeskAPI::User
11
+
12
+ def initialize(*object)
13
+ return super(object.first) if object.first.is_a? Hash
14
+ if object.first
15
+ args = object.first
16
+ object = args.shift
17
+ project_id = args.shift
18
+ @system_data = {:client => object}
19
+ unless object.is_a? Hash
20
+ hash = {:id => object.nice_id,
21
+ :status => object.status_id,
22
+ :title => object.subject,
23
+ :created_at => object.created_at,
24
+ :updated_at => object.updated_at,
25
+ :description => object.description,
26
+ :assignee => object.assignee_id,
27
+ :requestor => object.requester_id,
28
+ :priority => object.priority_id,
29
+ :project_id => project_id}
30
+ else
31
+ hash = object
32
+ end
33
+ super hash
34
+ end
35
+ end
36
+
37
+ def created_at
38
+ Time.parse(self[:created_at])
39
+ end
40
+
41
+ def updated_at
42
+ Time.parse(self[:updated_at])
43
+ end
44
+
45
+ def self.find(project_id, *options)
46
+ tickets = self.find_all(project_id)
47
+ if options[0].first.is_a? Array
48
+ Ticket.find_all(self.name).select { |ticket| ticket if options[0].first.any? { |ticket_id| ticket_id == ticket.id }}
49
+ elsif options[0].first.is_a? Hash
50
+ Ticket.find_by_attributes(self.name, options[0].first)
51
+ else
52
+ tickets
53
+ end
54
+ end
55
+
56
+ def self.find_all(*options)
57
+ project_id = options.first
58
+ SEARCH_API.find(:all, :params => {:query => "status:open"}).collect do |ticket|
59
+ ticket.requester_id = requestor(ticket)
60
+ ticket.assignee_id = assignee(ticket)
61
+ self.new([ticket, project_id])
62
+ end
63
+ end
64
+
65
+ def self.find_by_id(project_id, ticket_id)
66
+ self.new [API.find(ticket_id), project_id]
67
+ end
68
+
69
+ def self.find_by_attributes(project_id, attributes = {})
70
+ search_by_attribute(self.find_all(project_id), attributes)
71
+ end
72
+
73
+ def comments(*options)
74
+ Comment.find(project_id, id, options)
75
+ end
76
+
77
+ def comment(*options)
78
+ if options.first.is_a? Fixnum
79
+ Comment.find(project_id, id, [options.first]).first
80
+ elsif options.first.is_a? Hash
81
+ Comment.find_by_attributes(project_id, id, options.first).first
82
+ end
83
+ end
84
+
85
+ private
86
+ def self.requestor(ticket)
87
+ USER_API.find(ticket.requester_id).email
88
+ end
89
+
90
+ def self.assignee(ticket)
91
+ USER_API.find(ticket.assignee_id).email
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+ end