ticketmaster-pivotal 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 HybridGroup
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
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ # ticketmaster-pivotal
2
+
3
+ Description goes here.
4
+
5
+ ## Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ ## Copyright
16
+
17
+ Copyright (c) 2010 HybridGroup. See LICENSE for details.
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "ticketmaster-pivotal"
8
+ gem.summary = %Q{This is a ticketmaster provider for interacting with Pivotal Tracker}
9
+ gem.description = %Q{This is a ticketmaster provider for interacting with Pivotal Tracker .}
10
+ gem.email = "hong.quach@abigfisch.com"
11
+ gem.homepage = "http://ticket.rb"
12
+ gem.authors = ["HybridGroup"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency "activesupport", ">= 2.3.2"
15
+ gem.add_dependency "activeresource", ">= 2.3.2"
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'spec/rake/spectask'
24
+ Spec::Rake::SpecTask.new(:spec) do |spec|
25
+ spec.libs << 'lib' << 'spec'
26
+ spec.spec_files = FileList['spec/**/*_spec.rb']
27
+ end
28
+
29
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
30
+ spec.libs << 'lib' << 'spec'
31
+ spec.pattern = 'spec/**/*_spec.rb'
32
+ spec.rcov = true
33
+ end
34
+
35
+ task :spec => :check_dependencies
36
+
37
+ task :default => :spec
38
+
39
+ require 'rake/rdoctask'
40
+ Rake::RDocTask.new do |rdoc|
41
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+
43
+ rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.title = "ticketmaster-pivotal #{version}"
45
+ rdoc.rdoc_files.include('README*')
46
+ rdoc.rdoc_files.include('lib/**/*.rb')
47
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,73 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_resource'
4
+
5
+ module PivotalAPI
6
+ class Error < StandardError; end
7
+ class << self
8
+ # Sets up basic authentication credentials for all the resources.
9
+ def authenticate(user, password)
10
+ Token.user = user
11
+ Token.password = password
12
+ self.token = Token.get(:active)['guid']
13
+ Token.user = nil
14
+ Token.password = nil
15
+ end
16
+
17
+ # Sets the API token for all the resources.
18
+ def token=(value)
19
+ resources.each do |klass|
20
+ klass.headers['X-TrackerToken'] = value
21
+ end
22
+ @token = value
23
+ end
24
+
25
+ def resources
26
+ @resources ||= []
27
+ end
28
+ end
29
+
30
+ class Base < ActiveResource::Base
31
+ self.site = 'http://www.pivotaltracker.com/services/v3/'
32
+ def self.inherited(base)
33
+ PivotalAPI.resources << base
34
+ super
35
+ end
36
+ end
37
+
38
+ class Project < Base
39
+ def stories(options = {})
40
+ Story.find(:all, :params => options.merge!(:project_id => self.id))
41
+ end
42
+ end
43
+
44
+ class Token < Base
45
+ end
46
+
47
+ class Activity < Base
48
+ self.site += 'projects/:project_id/'
49
+ end
50
+
51
+ class Membership < Base
52
+ self.site += 'projects/:project_id/'
53
+ end
54
+
55
+ class Iteration < Base
56
+ self.site += 'projects/:project_id/'
57
+ end
58
+
59
+ class Story < Base
60
+ self.site += 'projects/:project_id/'
61
+ end
62
+
63
+ class Note < Base
64
+ self.site += 'projects/:project_id/stories/:story_id/'
65
+ end
66
+
67
+ class Task < Base
68
+ self.site += 'projects/:project_id/stories/:story_id/'
69
+ end
70
+
71
+ class AllActivity < Base
72
+ end
73
+ end
@@ -0,0 +1,86 @@
1
+ module TicketMaster::Provider
2
+ # This is the Pivotal Tracker Provider for ticketmaster
3
+ module Pivotal
4
+ include TicketMaster::Provider::Base
5
+
6
+ # This is for cases when you want to instantiate using TicketMaster::Provider::Lighthouse.new(auth)
7
+ def self.new(auth = {})
8
+ TicketMaster.new(:pivotal, auth)
9
+ end
10
+
11
+ # The authorize and initializer for this provider
12
+ def authorize(auth = {})
13
+ @authentication ||= TicketMaster::Authenticator.new(auth)
14
+ auth = @authentication
15
+ if auth.token
16
+ PivotalAPI.token = auth.token
17
+ elsif auth.username && auth.password
18
+ PivotalAPI.authenticate(auth.username, auth.password)
19
+ end
20
+ end
21
+
22
+ # The projects
23
+ #
24
+ # We have to merge in the auth information because, due to the class-based authentication
25
+ # mechanism, if we don't reset the authorize information for every request, it would
26
+ # end up using whatever the previous instantiated object's account info is.
27
+ def projects(*options)
28
+ authorize
29
+ projects = if options.length > 0
30
+ Project.find(*options)
31
+ else
32
+ Project.find(:all)
33
+ end
34
+ set_master_data(projects)
35
+ end
36
+
37
+ # The project
38
+ def project(*options)
39
+ authorize
40
+ return set_master_data(Project.find(:first, *options)) if options.length > 0
41
+ Project
42
+ end
43
+
44
+ # The tickets
45
+ #
46
+ # Due to the nature of pivotal, we must have the project_id to pull tickets. You can
47
+ # pass in the id through this format:
48
+ #
49
+ # .tickets(22)
50
+ # .tickets(:project_id => 22)
51
+ #
52
+ # To conform to ticketmaster's standard of returning all tickets on a call to this method
53
+ # without any parameters, if no parameters are passed, it will return all tickets for whatever
54
+ # the first project is.
55
+ def tickets(*options)
56
+ authorize
57
+ arg = options.shift
58
+ tickets = if arg.nil?
59
+ Ticket.find
60
+ elsif arg.is_a?(Fixnum)
61
+ Ticket.find(:all, :params => {:project_id => arg})
62
+ elsif arg.is_a?(Hash)
63
+ Ticket.find(:all, :params => arg) if arg.is_a?(Hash)
64
+ else
65
+ []
66
+ end
67
+ set_master_data(tickets)
68
+ end
69
+
70
+ # the ticket
71
+ def ticket(*options)
72
+ authorize
73
+ return set_master_data(Ticket.find(*options)) if options.length > 0
74
+ Ticket
75
+ end
76
+
77
+ def set_master_data(data)
78
+ if data.is_a?(Array)
79
+ data.collect! { |p| p.system_data.merge!(:master => self); p }
80
+ else
81
+ data.system_data.merge!(:master => self)
82
+ end
83
+ data
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,108 @@
1
+ module TicketMaster::Provider
2
+ module Pivotal
3
+ # Project class for ticketmaster-pivotal
4
+ #
5
+ #
6
+ class Project < TicketMaster::Provider::Base::Project
7
+ # The finder method
8
+ #
9
+ # It accepts all the find functionalities defined by ticketmaster
10
+ #
11
+ # + find() and find(:all) - Returns all projects on the account
12
+ # + find(<project_id>) - Returns the project based on the id
13
+ # + find(:first, :name => <project_name>) - Returns the first project based on the attribute
14
+ # + find(:name => <project name>) - Returns all projects based on the attribute
15
+ attr_accessor :prefix_options
16
+ alias_method :stories, :tickets
17
+ alias_method :story, :ticket
18
+
19
+ def self.find(*options)
20
+ first = options.shift
21
+ if first.nil? or first == :all
22
+ PivotalAPI::Project.find(:all).collect do |p|
23
+ self.new p
24
+ end
25
+ elsif first.is_a?(Fixnum)
26
+ self.new PivotalAPI::Project.find(first)
27
+ elsif first == :first
28
+ self.new self.search(options.shift || {}, 1).first
29
+ elsif first.is_a?(Hash)
30
+ self.search(first).collect { |p| self.new p }
31
+ end
32
+ end
33
+
34
+ # This is a helper method to find
35
+ def self.search(options = {}, limit = 1000)
36
+ projects = PivotalAPI::Project.find(:all)
37
+ projects.find_all do |p|
38
+ options.keys.reduce(true) do |memo, key|
39
+ p.send(key) == options[key] and (limit-=1) >= 0
40
+ end
41
+ end
42
+ end
43
+
44
+ # Create a project
45
+ def self.create(*options)
46
+ project = PivotalAPI::Project.new(options.shift)
47
+ project.save
48
+ self.new project
49
+ end
50
+
51
+ # The initializer
52
+ #
53
+ # A side effect of Hashie causes prefix_options to become an instance of TicketMaster::Provider::Pivotal::Project
54
+ def initialize(*options)
55
+ @system = :pivotal
56
+ @system_data = {}
57
+ first = options.shift
58
+ if first.is_a?(PivotalAPI::Project)
59
+ @system_data[:client] = first
60
+ @prefix_options = first.prefix_options
61
+ super(first.attributes)
62
+ else
63
+ super(first)
64
+ end
65
+ end
66
+
67
+ # All tickets for this project
68
+ def tickets(*options)
69
+ if options.length == 0
70
+ Ticket.find(:project_id => self.id)
71
+ else
72
+ first = options.first
73
+ if first.is_a?(Fixnum)
74
+ [Ticket.find(first, {:project_id => self.id})]
75
+ else
76
+ Ticket.find({:project_id => self.id}.merge(:q => options.first))
77
+ end
78
+ end
79
+ end
80
+
81
+ # The ticket finder
82
+ # returns only one ticket
83
+ def ticket(*options)
84
+ first = options.shift
85
+ if first.nil?
86
+ return Ticket
87
+ elsif first.is_a?(Fixnum)
88
+ return Ticket.find(first, :project_id => self.id)
89
+ else
90
+ Ticket.find(:first, {:project_id => self.id}.merge(:q => first))
91
+ end
92
+ end
93
+
94
+ # Save this project
95
+ def save
96
+ warn 'Warning: Pivotal does not allow editing of project attributes. This method does nothing.'
97
+ true
98
+ end
99
+
100
+ # Delete this project
101
+ def destroy
102
+ result = self.system_data[:client].destroy
103
+ result.is_a?(Net::HTTPOK)
104
+ end
105
+
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,107 @@
1
+ module TicketMaster::Provider
2
+ module Pivotal
3
+ # Ticket class for ticketmaster-pivotal
4
+ class Ticket < TicketMaster::Provider::Base::Ticket
5
+ @@allowed_states = ['new', 'open', 'resolved', 'hold', 'invalid']
6
+ attr_accessor :prefix_options
7
+
8
+ # The finder
9
+ #
10
+ # It tries to implement all the ticketmaster calls, but since the project id is required as the
11
+ # parent key, it doesnt really make sense to call find(:all) or find(##)
12
+ #
13
+ # * find(:all) - Returns an array of all tickets
14
+ # * find(##, ##) - Returns a ticket based on that id or some other primary (unique) attribute
15
+ # * find(:first, :summary => 'Ticket title') - Returns a ticket based on the ticket's attributes
16
+ # * find(:summary => 'Test Ticket') - Returns all tickets based on the given attributes
17
+ def self.find(*options)
18
+ first = options.shift
19
+ if first.nil? or first == :all
20
+ tickets = []
21
+ PivotalAPI::Project.find(:all).each do |p|
22
+ tickets |= p.stories
23
+ end
24
+ tickets.collect { |t| self.new t }
25
+ elsif first.is_a?(Fixnum)
26
+ second = options.shift
27
+ if second.is_a?(Fixnum)
28
+ self.new PivotalAPI::Story.find(first, :params => { :project_id => second })
29
+ elsif second.is_a?(Hash)
30
+ self.new PivotalAPI::Story.find(first, :params => qize(second))
31
+ end
32
+ elsif first == :first
33
+ self.new self.search(options.shift, 1).first
34
+ elsif first.is_a?(Hash)
35
+ self.search(first).collect do |t| self.new t end
36
+ end
37
+ end
38
+
39
+ def self.qize(params)
40
+ return params unless params[:filter] and params[:filter].is_a?(Hash)
41
+ q = ''
42
+ params[:filter].keys.each do |key|
43
+ value = params[:q][key]
44
+ value = "\"#{value}\"" if value.to_s.include?(' ')
45
+ q += "#{key}:#{value} "
46
+ end
47
+ params[:filter] = q
48
+ params
49
+ end
50
+
51
+ # The find helper
52
+ def self.search(options, limit = 1000)
53
+ tickets = PivotalAPI::Story.find(:all, :params => ({:project_id => (options.delete(:project_id) || options.delete('project_id')).to_i}.merge(qize(:filter => options))))
54
+ tickets.find_all do |t|
55
+ options.keys.reduce(true) do |memo, key|
56
+ t.send(key) == options[key] and (limit-=1) > 0
57
+ end
58
+ end
59
+ end
60
+
61
+ # The initializer
62
+ def initialize(*options)
63
+ @system = :pivotal
64
+ @system_data = {}
65
+ first = options.shift
66
+ if first.is_a?(PivotalAPI::Story)
67
+ @system_data[:client] = first
68
+ @prefix_options = first.prefix_options
69
+ super(first.attributes)
70
+ else
71
+ super(first)
72
+ end
73
+ end
74
+
75
+ # The creator
76
+ def self.create(*options)
77
+ new_ticket = PivotalAPI::Story.new(:project_id => (options.first.delete(:project_id) || options.first.delete('project_id')).to_i)
78
+ ticket_attr.each do |k, v|
79
+ new_ticket.send(k + '=', v)
80
+ end
81
+ new_ticket.save
82
+ self.new new_ticket
83
+ end
84
+
85
+ # The saver
86
+ def save(*options)
87
+ pt_ticket = @system_data[:client]
88
+ self.keys.each do |key|
89
+ pt_ticket.send(key + '=', self.send(key)) if self.send(key) != pt_ticket.send(key)
90
+ end
91
+ pt_ticket.save
92
+ end
93
+
94
+ def destroy(*options)
95
+ @system_data[:client].destroy.is_a?(Net::HTTPOK)
96
+ end
97
+
98
+ # The closer
99
+ def close(resolution = 'resolved')
100
+ resolution = 'resolved' unless @@allowed_states.include?(resolution)
101
+ ticket = PivotalAPI::Ticket.find(self.id, :params => {:project_id => self.prefix_options[:project_id]})
102
+ ticket.state = resolution
103
+ ticket.save
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,6 @@
1
+ require File.dirname(__FILE__) + '/pivotal/pivotal-api'
2
+
3
+ %w{ pivotal ticket project }.each do |f|
4
+ require File.dirname(__FILE__) + '/provider/' + f + '.rb';
5
+ end
6
+
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'ticketmaster-pivotal'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "TicketmasterPivotal" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ticketmaster-pivotal
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - HybridGroup
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-26 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 2
48
+ - 3
49
+ - 2
50
+ version: 2.3.2
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: activeresource
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 7
62
+ segments:
63
+ - 2
64
+ - 3
65
+ - 2
66
+ version: 2.3.2
67
+ type: :runtime
68
+ version_requirements: *id003
69
+ description: This is a ticketmaster provider for interacting with Pivotal Tracker .
70
+ email: hong.quach@abigfisch.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - LICENSE
77
+ - README.markdown
78
+ files:
79
+ - .document
80
+ - .gitignore
81
+ - LICENSE
82
+ - README.markdown
83
+ - Rakefile
84
+ - VERSION
85
+ - lib/pivotal/pivotal-api.rb
86
+ - lib/provider/pivotal.rb
87
+ - lib/provider/project.rb
88
+ - lib/provider/ticket.rb
89
+ - lib/ticketmaster-pivotal.rb
90
+ - spec/spec.opts
91
+ - spec/spec_helper.rb
92
+ - spec/ticketmaster-pivotal_spec.rb
93
+ has_rdoc: true
94
+ homepage: http://ticket.rb
95
+ licenses: []
96
+
97
+ post_install_message:
98
+ rdoc_options:
99
+ - --charset=UTF-8
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.3.7
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: This is a ticketmaster provider for interacting with Pivotal Tracker
127
+ test_files:
128
+ - spec/spec_helper.rb
129
+ - spec/ticketmaster-pivotal_spec.rb