ticketmaster 0.1.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,11 @@
11
11
  # We are also planning on standardizing non-standard/provider-specific object models
12
12
  module TicketMaster::Provider
13
13
  module Base
14
+ PROJECT_API = nil # The Class for the project api interaction
15
+ TICKET_API = nil # The Class for the ticket api interaction
16
+
17
+ include TicketMaster::Provider::Helper
18
+
14
19
  # All providers must define this method.
15
20
  # It doesn't *have* to do anything, it just has to be there. But since it's here, you don't
16
21
  # have to worry about it as long as you "include TicketMaster::Provider::Base"
@@ -28,8 +33,15 @@ module TicketMaster::Provider
28
33
  #
29
34
  # Should try to implement a find :first (or find with singular result) if given parameters
30
35
  def project(*options)
31
- return TicketMaster::Project.find(*options) if options.length > 0
32
- TicketMaster::Project
36
+ easy_finder(@provider::Project, :first, options)
37
+ end
38
+
39
+ # All providers should try to define this method.
40
+ #
41
+ # It returns all projects in an array
42
+ # Should try to implement a find :all if given parameters
43
+ def projects(*options)
44
+ easy_finder(@provider::Project, :all, options)
33
45
  end
34
46
 
35
47
  # Providers should try to define this method
@@ -43,16 +55,7 @@ module TicketMaster::Provider
43
55
  #
44
56
  # Should try to implement a find :first (or find with singular result) if given parameters
45
57
  def ticket(*options)
46
- return TicketMaster::Ticket.find(*options) if options.length > 0
47
- TicketMaster::Ticket
48
- end
49
-
50
- # All providers should try to define this method.
51
- #
52
- # It returns all projects in an array
53
- # Should try to implement a find :all if given parameters
54
- def projects(*options)
55
- []
58
+ easy_finder(@provider::Ticket, :first, options)
56
59
  end
57
60
 
58
61
  # All providers should try to define this method
@@ -60,7 +63,7 @@ module TicketMaster::Provider
60
63
  # It returns all tickets in an array.
61
64
  # Should try to implement a find :all if given parameters
62
65
  def tickets(*options)
63
- []
66
+ easy_finder(@provider::Ticket, :all, options)
64
67
  end
65
68
  end
66
69
  end
@@ -8,111 +8,139 @@ module TicketMaster::Provider
8
8
  # methods act based on a blank slate (which means the info to find a specific ticket has
9
9
  # to be passed in the parameters in the ticket)
10
10
  #
11
- # Methods that a provider must define:
12
- #
13
- # * self.find
14
- # * close
15
- # * save
16
- # * destroy
17
- #
18
11
  # Methods that the provider should define if feasible:
19
12
  #
20
13
  # * reload!
21
14
  # * initialize
15
+ # * close
16
+ # * save
17
+ # * destroy
22
18
  #
23
19
  # Methods that would probably be okay if the provider left it alone:
24
20
  #
25
21
  # * self.create
26
22
  # * update
27
23
  # * update!
24
+ # * self.find
28
25
  #
29
26
  # A provider should define as many attributes as feasibly possible. The list below are
30
27
  # some guidelines as to what attributes are necessary, if your provider's api does not
31
- # implement them, point it to an attribute that is close to it. (for example, a summary
32
- # can point to title. and assignee might point to assigned_to. Remember to alias it in your class!)
28
+ # implement them, point it to an attribute that is close to it. (for example, a title
29
+ # can point to summary. and assignee might point to assigned_to. Remember to alias it in your class!)
33
30
  #
34
31
  # * id
35
32
  # * status
36
33
  # * priority
37
- # * summary
34
+ # * title
38
35
  # * resolution
39
36
  # * created_at
40
37
  # * updated_at
41
38
  # * description
42
39
  # * assignee
40
+ # * requestor
41
+ # * project_id
43
42
  class Ticket < Hashie::Mash
44
- @ignore_inspect = %w| system system_data |
45
- @system = nil # The symbol for the provider.
46
- @system_data = nil # The system info for the provider
43
+ include TicketMaster::Provider::Common
44
+ include TicketMaster::Provider::Helper
45
+ extend TicketMaster::Provider::Helper
47
46
  attr_accessor :system, :system_data
48
- # Find a ticket
49
- #
50
- # The implementation should be able to accept these cases if feasible:
47
+ API = nil # Replace with your ticket API's Class
48
+
49
+ # Find ticket
50
+ # You can also retrieve an array of all tickets by not specifying any query.
51
51
  #
52
- # * find(:all) - Returns an array of all tickets
53
- # * find(##) - Returns a project based on that id or some other primary (unique) attribute
54
- # * find(:first, :summary => 'Ticket title') - Returns a ticket based on the ticket's attributes
55
- # * find(:summary => 'Test Ticket') - Returns all tickets based on the given attributes
56
- def self.find(*options)
57
- raise TicketMaster::Exception.new("This method must be reimplemented in the provider")
52
+ # * find(<project_id>) or find(<project_id>, :all) - Returns an array of all tickets
53
+ # * find(<project_id>, ##) - Returns a ticket based on that id or some other primary (unique) attribute
54
+ # * find(<project_id>, [#, #, #]) - Returns many tickets with these ids
55
+ # * find(<project_id>, :first, :title => 'ticket name') - Returns the first ticket based on the ticket's attribute(s)
56
+ # * find(<project_id>, :last, :title => 'Some ticket') - Returns the last ticket based on the ticket's attribute(s)
57
+ # * find(<project_id>, :all, :title => 'Test ticket') - Returns all tickets based on the given attribute(s)
58
+ def self.find(project_id, *options)
59
+ first, attributes = options
60
+ if first.nil? or (first == :all and attributes.nil?)
61
+ self.find_by_attributes(project_id)
62
+ elsif first.is_a? Fixnum
63
+ self.find_by_id(project_id, first)
64
+ elsif first.is_a? Array
65
+ first.collect { |id| self.find_by_id(project_id, id) }
66
+ elsif first == :first
67
+ tickets = attributes.nil? ? self.find_by_attributes(project_id) : self.find_by_attributes(project_id, attributes)
68
+ tickets.first
69
+ elsif first == :last
70
+ tickets = attributes.nil? ? self.find_by_attributes(project_id) : self.find_by_attributes(project_id, attributes)
71
+ tickets.last
72
+ elsif first == :all
73
+ self.find_by_attributes(project_id, attributes)
74
+ end
58
75
  end
59
76
 
60
- # Create a ticket.
61
- # Basically, a .new and .save in the same call. The default method assumes it is passed a
62
- # single hash with attribute information
63
- def self.create(*options)
64
- ticket = self.new(options.first)
65
- ticket.save
77
+ # The first of whatever ticket
78
+ def self.first(project_id, *options)
79
+ self.find(project_id, :first, *options)
66
80
  end
67
81
 
68
- # Instantiate a new ticket (but don't save yet!)
69
- # The default method assumes a single hash with all the parameters is passed to Ticket.new
70
- def initialize(*options)
71
- super(options.first)
72
- # do some other stuff
82
+ # The last of whatever ticket
83
+ def self.last(project_id, *options)
84
+ self.find(project_id, :last, *options)
73
85
  end
74
-
75
- # Close this ticket
76
- #
77
- # On success it should return true, otherwise false
78
- def close(*options)
79
- raise TicketMaster::Exception.new("This method must be reimplemented in the provider")
86
+
87
+ # Accepts an integer id and returns the single ticket instance
88
+ # Must be defined by the provider
89
+ def self.find_by_id(project_id, ticket_id)
90
+ if self::API.is_a? Class
91
+ self.new self::API.find(ticket_id, :params => {:project_id => project_id})
92
+ else
93
+ raise TicketMaster::Exception.new("This method must be reimplemented in the provider")
94
+ end
80
95
  end
81
96
 
82
- # Save this ticket
83
- # Expected return value of true (successful) or false (failure)
84
- def save(*options)
85
- raise TicketMaster::Exception.new("This method must be reimplemented in the provider")
97
+ # Accepts an attributes hash and returns all tickets matching those attributes in an array
98
+ # Should return all tickets if the attributes hash is empty
99
+ # Must be defined by the provider
100
+ def self.find_by_attributes(project_id, attributes = {})
101
+ if self::API.is_a? Class
102
+ self.search(project_id, attributes).collect { |thing| self.new thing }
103
+ else
104
+ raise TicketMaster::Exception.new("This method must be reimplemented in the provider")
105
+ end
86
106
  end
87
107
 
88
- # Reload this ticket
89
- def reload!(*options)
90
- raise TicketMaster::Exception.new("This method must be reimplemented in the provider")
108
+ # This is a helper method to find
109
+ def self.search(project_id, options = {}, limit = 1000)
110
+ if self::API.is_a? Class
111
+ tickets = self::API.find(:all, :params => {:project_id => project_id})
112
+ search_by_attribute(tickets, options, limit)
113
+ else
114
+ raise TicketMaster::Exception.new("This method must be reimplemented in the provider")
115
+ end
116
+ end
117
+
118
+ # Asks the provider's api for the comment associated with the project,
119
+ # returns an array of Comment objects.
120
+ def comments(*options)
121
+ options.insert 0, project_id
122
+ options.insert 1, id
123
+ easy_finder(self.class.parent::Comment, :all, options, 2)
91
124
  end
92
125
 
93
- # Delete this ticket
94
- #
95
- # If your provider doesn't have a delete or trash option for tickets:
96
- # raise TicketMaster::Exception.new("Tickets can not be destroyed on SomeProviderAPI")
97
- def destroy(*options)
98
- raise TicketMaster::Exception.new("This method must be reimplemented in the provider")
126
+ def comment(*options)
127
+ if options.length > 0
128
+ options.insert(0, project_id)
129
+ options.insert(1, id)
130
+ end
131
+ easy_finder(self.class.parent::Comment, :first, options, 2)
99
132
  end
100
133
 
101
- # Update a ticket and save
134
+ # Close this ticket
102
135
  #
103
- # The default assumes the options passed to it is a single hash with the attributes to update
104
- def update!(*options)
105
- update(options.first)
106
- save
136
+ # On success it should return true, otherwise false
137
+ def close(*options)
138
+ raise TicketMaster::Exception.new("This method must be reimplemented in the provider")
107
139
  end
108
140
 
109
- # Update a ticket's attributes, but no save
110
- # Used when you need to do mass attribute assignment
111
- def update(*options)
112
- options.first.each do |k, v|
113
- self.send(k + '=', v)
114
- end
115
- self
141
+ # Reload this ticket
142
+ def reload!(*options)
143
+ raise TicketMaster::Exception.new("This method must be reimplemented in the provider")
116
144
  end
117
145
 
118
146
  end
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'spec'
4
+ require 'spec/autorun'
5
+
6
+ Spec::Runner.configure do |config| end
7
+ # Tests for the cli
8
+ # I'm not quite sure what the most effective way to test this is...
9
+ describe "Ticketmaster CLI" do
10
+ before(:all) do
11
+ @ticket = File.dirname(__FILE__) + '/../bin/ticket'
12
+ @cli_dir = File.dirname(__FILE__) + '/../lib/ticketmaster/cli'
13
+ end
14
+
15
+ it "should output help if no command given" do
16
+ help = `#{@ticket}`
17
+ $?.should == 0
18
+ help.should include('Usage: ticket [options] COMMAND [command_options]')
19
+ end
20
+
21
+ it "should be able to show help pages" do
22
+ `#{@ticket} help`.should include(File.read(@cli_dir + '/commands/help/help'))
23
+ `#{@ticket} help config`.should include(File.read(@cli_dir + '/commands/help/config'))
24
+ `#{@ticket} help console`.should include(File.read(@cli_dir + '/commands/help/console'))
25
+ end
26
+
27
+ it "should be able to add and edit config info" do
28
+ pending
29
+ end
30
+
31
+ it "should be able to open up a console" do
32
+ pending
33
+ end
34
+
35
+ end
Binary file
@@ -0,0 +1,95 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ticketmaster}
8
+ s.version = "0.3.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Sirupsen", "deadprogrammer"]
12
+ s.date = %q{2010-07-03}
13
+ s.default_executable = %q{ticket}
14
+ s.description = %q{Ticketmaster provides a universal API to trouble ticket and project management systems.}
15
+ s.email = %q{simon@hybridgroup.com}
16
+ s.executables = ["ticket"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.md",
20
+ "TODO"
21
+ ]
22
+ s.files = [
23
+ ".document",
24
+ ".gitignore",
25
+ "LICENSE",
26
+ "NOTES",
27
+ "README.md",
28
+ "Rakefile",
29
+ "TODO",
30
+ "VERSION",
31
+ "bin/ticket",
32
+ "lib/ticketmaster.rb",
33
+ "lib/ticketmaster/authenticator.rb",
34
+ "lib/ticketmaster/cli/commands/config.rb",
35
+ "lib/ticketmaster/cli/commands/console.rb",
36
+ "lib/ticketmaster/cli/commands/help.rb",
37
+ "lib/ticketmaster/cli/commands/help/config",
38
+ "lib/ticketmaster/cli/commands/help/console",
39
+ "lib/ticketmaster/cli/commands/help/help",
40
+ "lib/ticketmaster/cli/commands/help/project",
41
+ "lib/ticketmaster/cli/commands/help/ticket",
42
+ "lib/ticketmaster/cli/commands/project.rb",
43
+ "lib/ticketmaster/cli/commands/ticket.rb",
44
+ "lib/ticketmaster/cli/common.rb",
45
+ "lib/ticketmaster/cli/init.rb",
46
+ "lib/ticketmaster/comment.rb",
47
+ "lib/ticketmaster/common.rb",
48
+ "lib/ticketmaster/dummy/dummy.rb",
49
+ "lib/ticketmaster/dummy/project.rb",
50
+ "lib/ticketmaster/dummy/ticket.rb",
51
+ "lib/ticketmaster/exception.rb",
52
+ "lib/ticketmaster/helper.rb",
53
+ "lib/ticketmaster/project.rb",
54
+ "lib/ticketmaster/provider.rb",
55
+ "lib/ticketmaster/ticket.rb",
56
+ "spec/spec.opts",
57
+ "spec/spec_helper.rb",
58
+ "spec/ticketmaster-cli_spec.rb",
59
+ "spec/ticketmaster_spec.rb",
60
+ "test/helper.rb",
61
+ "test/test_ticketmaster.rb",
62
+ "ticketmaster-0.3.0.gem",
63
+ "ticketmaster-0.3.1.gem",
64
+ "ticketmaster.gemspec"
65
+ ]
66
+ s.homepage = %q{http://ticketrb.com}
67
+ s.rdoc_options = ["--charset=UTF-8"]
68
+ s.require_paths = ["lib"]
69
+ s.rubygems_version = %q{1.3.7}
70
+ s.summary = %q{Ticketmaster provides a universal API to trouble ticket and project management systems.}
71
+ s.test_files = [
72
+ "spec/spec_helper.rb",
73
+ "spec/ticketmaster-cli_spec.rb",
74
+ "spec/ticketmaster_spec.rb",
75
+ "test/helper.rb",
76
+ "test/test_ticketmaster.rb"
77
+ ]
78
+
79
+ if s.respond_to? :specification_version then
80
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
81
+ s.specification_version = 3
82
+
83
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
84
+ s.add_runtime_dependency(%q<hashie>, [">= 0"])
85
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
86
+ else
87
+ s.add_dependency(%q<hashie>, [">= 0"])
88
+ s.add_dependency(%q<shoulda>, [">= 0"])
89
+ end
90
+ else
91
+ s.add_dependency(%q<hashie>, [">= 0"])
92
+ s.add_dependency(%q<shoulda>, [">= 0"])
93
+ end
94
+ end
95
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ticketmaster
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 3
8
9
  - 1
9
- - 0
10
- version: 0.1.0
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sirupsen
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-06-22 00:00:00 +02:00
19
+ date: 2010-07-03 00:00:00 -07:00
20
20
  default_executable: ticket
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -56,6 +56,7 @@ extensions: []
56
56
  extra_rdoc_files:
57
57
  - LICENSE
58
58
  - README.md
59
+ - TODO
59
60
  files:
60
61
  - .document
61
62
  - .gitignore
@@ -63,23 +64,42 @@ files:
63
64
  - NOTES
64
65
  - README.md
65
66
  - Rakefile
67
+ - TODO
66
68
  - VERSION
67
69
  - bin/ticket
68
- - lib/console.rb
69
70
  - lib/ticketmaster.rb
70
71
  - lib/ticketmaster/authenticator.rb
72
+ - lib/ticketmaster/cli/commands/config.rb
73
+ - lib/ticketmaster/cli/commands/console.rb
74
+ - lib/ticketmaster/cli/commands/help.rb
75
+ - lib/ticketmaster/cli/commands/help/config
76
+ - lib/ticketmaster/cli/commands/help/console
77
+ - lib/ticketmaster/cli/commands/help/help
78
+ - lib/ticketmaster/cli/commands/help/project
79
+ - lib/ticketmaster/cli/commands/help/ticket
80
+ - lib/ticketmaster/cli/commands/project.rb
81
+ - lib/ticketmaster/cli/commands/ticket.rb
82
+ - lib/ticketmaster/cli/common.rb
83
+ - lib/ticketmaster/cli/init.rb
84
+ - lib/ticketmaster/comment.rb
85
+ - lib/ticketmaster/common.rb
71
86
  - lib/ticketmaster/dummy/dummy.rb
72
87
  - lib/ticketmaster/dummy/project.rb
73
88
  - lib/ticketmaster/dummy/ticket.rb
74
89
  - lib/ticketmaster/exception.rb
90
+ - lib/ticketmaster/helper.rb
75
91
  - lib/ticketmaster/project.rb
76
92
  - lib/ticketmaster/provider.rb
77
93
  - lib/ticketmaster/ticket.rb
78
94
  - spec/spec.opts
79
95
  - spec/spec_helper.rb
96
+ - spec/ticketmaster-cli_spec.rb
80
97
  - spec/ticketmaster_spec.rb
81
98
  - test/helper.rb
82
99
  - test/test_ticketmaster.rb
100
+ - ticketmaster-0.3.0.gem
101
+ - ticketmaster-0.3.1.gem
102
+ - ticketmaster.gemspec
83
103
  has_rdoc: true
84
104
  homepage: http://ticketrb.com
85
105
  licenses: []
@@ -116,6 +136,7 @@ specification_version: 3
116
136
  summary: Ticketmaster provides a universal API to trouble ticket and project management systems.
117
137
  test_files:
118
138
  - spec/spec_helper.rb
139
+ - spec/ticketmaster-cli_spec.rb
119
140
  - spec/ticketmaster_spec.rb
120
- - test/test_ticketmaster.rb
121
141
  - test/helper.rb
142
+ - test/test_ticketmaster.rb