ticketmaster 0.1.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/TODO ADDED
@@ -0,0 +1 @@
1
+ 1) A Cache system for the finders
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.3.1
data/bin/ticket CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- puts "ticket commands will go thru here..."
4
- puts "EXAMPLE:"
5
- puts "ticket list"
6
- puts "ticket close 127 \"This is done\""
7
- puts "ticket open \"what a problem we have here\""
3
+ # The 'ticketmaster' gem was installed using rubygems
4
+ # This file is the CLI application to use with 'ticketmaster'
5
+
6
+ require File.dirname(__FILE__) + '/../lib/ticketmaster/cli/init.rb'
7
+
data/lib/ticketmaster.rb CHANGED
@@ -7,8 +7,11 @@ class TicketMaster
7
7
  end
8
8
 
9
9
  %w{
10
+ common
11
+ helper
10
12
  project
11
13
  ticket
14
+ comment
12
15
  authenticator
13
16
  provider
14
17
  exception
@@ -18,7 +21,8 @@ end
18
21
  # This is the TicketMaster class
19
22
  #
20
23
  class TicketMaster
21
- attr_reader :provider
24
+ attr_reader :provider, :symbol
25
+ attr_accessor :default_project
22
26
 
23
27
  # This initializes the TicketMaster instance and prepares the provider
24
28
  # If called without any arguments, it conveniently tries searching for the information in
@@ -27,14 +31,16 @@ class TicketMaster
27
31
  #
28
32
  # What it DOES NOT do is auto-require the provider...so make sure you have the providers required.
29
33
  def initialize(system = nil, authentication = nil)
30
- if system.nil?
34
+ if system.nil? or authentication.nil?
31
35
  require 'yaml'
32
- data = YAML.load_file File.expand_path('~/.ticketmaster.yml')
33
- system = data['default'] || data.first.first
34
- authentication = data[system] if authentication.nil?
36
+ data = YAML.load_file File.expand_path(ENV['TICKETMASTER_CONFIG'] || '~/.ticketmaster.yml')
37
+ system = system.nil? ? data['default'] || data.first.first : system.to_s
38
+ authentication = data[system]['authentication'] if authentication.nil? and data[system]['authentication']
35
39
  end
36
40
  self.extend TicketMaster::Provider.const_get(system.to_s.capitalize)
37
41
  authorize authentication
42
+ @symbol = system.to_sym
43
+ @provider = TicketMaster::Provider.const_get(system.to_s.capitalize)
38
44
  end
39
45
 
40
46
  # Providers should over-write this method
@@ -0,0 +1,90 @@
1
+ # The command method call implementation
2
+ # This sets the option parser and passes the parsed options to the subcommands
3
+ def config(options)
4
+ ARGV << '--help' if ARGV.length == 0
5
+ begin
6
+ OptionParser.new do |opts|
7
+ opts.banner = 'Usage: ticket -p PROVIDER [options] config [config_options]'
8
+ opts.separator ''
9
+ opts.separator 'Options:'
10
+
11
+ opts.on('-a', '--add', 'Add a new entry to the configuration file based on ticketmaster options.') do
12
+ options[:subcommand] = 'add'
13
+ end
14
+
15
+ opts.on('-e', '--edit', 'Edit an existing entry to the configuration file based on ticketmaster options') do
16
+ options[:subcommand] = 'edit'
17
+ end
18
+
19
+ opts.on('-p', '--set-default-provider', 'Set the current provider as the default.', 'Requires provider to be specified, otherwise unsets the default') do
20
+ options[:subcommand] = 'set_default_provider'
21
+ end
22
+
23
+ opts.separator ''
24
+ opts.separator 'Other options:'
25
+
26
+ opts.on_tail('-h', '--help', 'Show this message') do
27
+ puts opts
28
+ exit
29
+ end
30
+ end.parse(ARGV)
31
+ rescue OptionParser::MissingArgument => exception
32
+ puts "ticket #{options[:original_argv].join(' ')}\n\n"
33
+ puts "Error: An option was called that requires an argument, but was not given one"
34
+ puts exception.message
35
+ end
36
+ send(options[:subcommand], options)
37
+ end
38
+
39
+ # Called on --add. It adds a new entry to the config file and will refuse if it already exists
40
+ def add(options)
41
+ require_provider unless options[:provider]
42
+ provider = options[:provider]
43
+ config = YAML.load_file(config_file = File.expand_path(options[:config]))
44
+ if config[provider]
45
+ puts "#{provider} has already been specfied in #{options[:config]}. Refusing to add. Use --edit instead."
46
+ exit 1
47
+ end
48
+ config[provider] = {}
49
+ config[provider]['authentication'] = options[:authentication] || {}
50
+ config[provider]['project'] = options[:project] if options[:project]
51
+ File.open(config_file, 'w') do |out|
52
+ YAML.dump(config, out)
53
+ end
54
+ puts "Wrote #{provider} to #{config_file}"
55
+ exit
56
+ end
57
+
58
+ # Called on --edit. It updates and edits an entry. If the entry is non-existent, it will add it.
59
+ def edit(options)
60
+ require_provider unless options[:provider]
61
+ provider = options[:provider]
62
+ config = YAML.load_file(config_file = File.expand_path(options[:config]))
63
+ config[provider] ||= {}
64
+ config[provider]['authentication'] = options[:authentication] || {}
65
+ config[provider]['project'] = options[:project] if options[:project]
66
+ File.open(config_file, 'w') do |out|
67
+ YAML.dump(config, out)
68
+ end
69
+ puts "Wrote #{provider} to #{config_file}"
70
+ exit
71
+ end
72
+
73
+ # Called on --set-default-provider. It sets the current provider as the default
74
+ def set_default_provider(options)
75
+ provider = options[:provider]
76
+ config = YAML.load_file(config_file = File.expand_path(options[:config]))
77
+ puts "Warning! #{provider} is not defined in #{config_file}" unless provider.nil? or config[provider]
78
+ config['default'] = provider
79
+ File.open(config_file, 'w') do |out|
80
+ YAML.dump(config, out)
81
+ end
82
+ puts "Default provider has been set to '#{provider}'"
83
+ exit
84
+ end
85
+
86
+ # Called when a provider is not given.
87
+ def require_provider
88
+ puts "Provider must be specified!"
89
+ exit 1
90
+ end
@@ -0,0 +1,31 @@
1
+ # the console command
2
+ def console(options)
3
+ send(:open_irb, options, ARGV)
4
+ end
5
+
6
+ # the actual method to do the irb opening
7
+ def open_irb(options, argv)
8
+ tm_lib = File.dirname(__FILE__) + '/../../../ticketmaster.rb'
9
+ irb_name = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
10
+ requires = "-r rubygems -r #{tm_lib} "
11
+ cmd = ''
12
+ if File.exist?(config = File.expand_path(options[:config]))
13
+ ENV['TICKETMASTER_CONFIG']=config
14
+ end
15
+ providers = !options[:provider].nil? ? [options[:provider]] : YAML.load_file(config).keys
16
+ providers.delete 'default'
17
+ require 'rubygems'
18
+ require 'ticketmaster'
19
+ providers.reduce(requires) do |mem, p|
20
+ begin
21
+ require "ticketmaster-#{p}"
22
+ requires << "-r ticketmaster-#{p} "
23
+ rescue LoadError => exception
24
+ puts exception
25
+ require "#{p}"
26
+ requires << "-r #{p} "
27
+ end
28
+ end
29
+ cmd << "#{irb_name} #{requires} --simple-prompt #{ARGV.join(' ')}"
30
+ exec cmd
31
+ end
@@ -0,0 +1,9 @@
1
+ # The help command.
2
+ def help(options)
3
+ cmd = ARGV.shift || 'help'
4
+ page = File.dirname(__FILE__) + '/help/' + cmd
5
+ if File.exist?(page)
6
+ puts File.read(page)
7
+ puts "\nFor parameter listing and details, try executing the command with --help.\n\tticketmaster #{cmd} --help"
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ This command is used to configure ticketmaster settings for use in your terminal.
2
+
3
+ By default, ticketmaster searches for the config information in a file named 'ticketmaster.yml' in the current directory. Next it searches for 'config/ticketmaster.yml' and if that fails, it uses the home directory's ~/.ticketmaster.yml (note the . in front on this one). There is also the TICKETMASTER_CONFIG environment variable that you can set to point to another configuration file anywhere if necessary.
4
+
5
+ This command helps facilitate the creation of a ticketmaster.yml.
6
+
7
+ Warning: Due to the way the authentication is parsed, if any keys or values contain a comma (,) or colin (:), it can not be parsed through the -A command. Usually this isn't a problem, and if it is, it can be resolved though putting the values in a config file.
8
+
9
+ Example:
10
+ ticket -c ~/.ticketmaster.yml -p dummy -A username:cheese,password:cakes -P 555 config --add
11
+ ticket -p dummy config --set-default-provider
12
+
13
+ The format for ticketmaster.yml is:
14
+ default: <default provider>
15
+ <provider name>:
16
+ authentication:
17
+ <authentication information>
18
+ project: <project>
19
+ [...]
20
+
21
+ For example, a ticketmaster.yml with the Dummy provider would look something like this:
22
+ default: dummy
23
+ dummy:
24
+ authentication:
25
+ username: name
26
+ password: doesnt-matter
27
+ project: 555
@@ -0,0 +1,13 @@
1
+ This command is used to open an irb session with the ticketmaster.
2
+
3
+ The configuration for this command should mostly be dependent on the ticketmaster.yml files.
4
+ See ticketmaster help config for more information on how to set it up.
5
+
6
+ Example:
7
+ ticket console
8
+ ticket -p dummy console
9
+ ticket -p dummy console -d --tracer
10
+
11
+ By default, it attempts to load all providers listed in the config unless a provider is explicitly given.
12
+
13
+ All options passed to console is passed to the irb session. See irb --help for those options and their details
@@ -0,0 +1,7 @@
1
+ usage: ticket help COMMAND
2
+
3
+ This is the help command. You can use this command to get more information on other commands.
4
+
5
+ Example:
6
+ ticket help config
7
+ ticket help console
@@ -0,0 +1,13 @@
1
+ This command is used to work with projects.
2
+
3
+ It can be used to do any of the CRUD actions with projects that are provided by the provider.
4
+
5
+ It will attempt to load data through the config files if they are available. See 'ticket help config' for more information.
6
+
7
+ Examples:
8
+ ticket -p lighthouse -A account:ticketmaster,token:abc project --create name "new project"
9
+ ticket project --read 946
10
+ ticket --project 946 project --read
11
+ ticket -p dummy -A "user:common coder,pass:w3rd out" project --destroy 712
12
+ ticket -p dummy -P 712 project --destroy
13
+ ticket -p dummy project --update name "new project name" description "this is the project description"
@@ -0,0 +1,14 @@
1
+ This command is used to work with tickets.
2
+
3
+ It can be used to do any of the CRUD actions with projects that are provided by the provider.
4
+
5
+ It will attempt to load data through the config files if they are available. See 'ticket help config' for more information.
6
+
7
+ If any of the keys or values contain a space, you will have to enclose that key or value in quotes. For example, if you set name to ProjectName it does not need to be quoted, but if you set name to Project Name it will have to be quoted to "Project Name" or 'Project Name'
8
+
9
+ Examples:
10
+ ticket -p lighthouse -A account:ticketmaster,token:abc ticket --create name "new ticket" description "this is a new ticket"
11
+ ticket --project 946 ticket --read --ticket 2
12
+ ticket -p dummy -A "user:common coder,pass: w3rd out" ticket --destroy --ticket 12
13
+ ticket -p dummy -P 712 ticket --destroy --ticket 4
14
+ ticket -p dummy project --ticket 6 --update attribute value name "free dummies"
@@ -0,0 +1,136 @@
1
+ require 'rubygems'
2
+ # The command method call for project
3
+ # This sets the option parser and passes the parsed options to the subcommands
4
+ def project(options)
5
+ ARGV << '--help' if ARGV.length == 0
6
+ begin
7
+ OptionParser.new do |opts|
8
+ opts.banner = 'Usage: ticket -p PROVIDER [options] project [project_options]'
9
+ opts.separator ''
10
+ opts.separator 'Options:'
11
+
12
+ opts.on('-C', '--create ATTRIBUTES', 'Create a new project') do |attribute|
13
+ options[:project_attributes] = {attribute => ARGV.shift}.merge(attributes_hash(ARGV))
14
+ options[:subcommand] = 'create'
15
+ end
16
+
17
+ opts.on('-R', '--read [PROJECT]', 'Read out project and its attributes') do |id|
18
+ options[:project] = id if id
19
+ options[:subcommand] = 'read'
20
+ end
21
+
22
+ opts.on('-U', '--update ATTRIBUTES', 'Update project information') do |attribute|
23
+ options[:project_attributes] = {attribute => ARGV.shift}.merge(attributes_hash(ARGV))
24
+ options[:subcommand] = 'update'
25
+ end
26
+
27
+ opts.on('-D', '--destroy [PROJECT]', 'Destroy the project. Not reversible!') do |id|
28
+ options[:project] = id if id
29
+ options[:subcommand] = 'destroy'
30
+ end
31
+
32
+ opts.on('-I', '--info [PROJECT_ID]', 'Get project info. Same as --read. ') do |id|
33
+ options[:project] = id if id
34
+ options[:subcommand] = 'read'
35
+ end
36
+
37
+ opts.on('-S', '--search [ATTRIBUTES]', 'Search for a project based on attributes') do |attribute|
38
+ options[:project_attributes] = attribute ? {attribute => ARGV.shift}.merge(attributes_hash(ARGV)) : {}
39
+ options[:subcommand] = 'search'
40
+ end
41
+
42
+ opts.on('-L', '--list-all', 'List all projects. Same as --search without any parameters') do
43
+ options[:project_attributes] = {}
44
+ options[:subcommand] = 'search'
45
+ end
46
+
47
+ opts.separator ''
48
+ opts.separator 'Other options:'
49
+
50
+ opts.on_tail('-h', '--help', 'Show this message') do
51
+ puts opts
52
+ exit
53
+ end
54
+ end.order!
55
+ rescue OptionParser::MissingArgument => exception
56
+ puts "ticket #{options[:original_argv].join(' ')}\n\n"
57
+ puts "Error: An option was called that requires an argument, but was not given one"
58
+ puts exception.message
59
+ end
60
+ parse_config!(options)
61
+ begin
62
+ require 'ticketmaster'
63
+ require "ticketmaster-#{options[:provider]}"
64
+ rescue
65
+ require options[:provider]
66
+ end
67
+ send(options[:subcommand], options)
68
+ end
69
+
70
+
71
+ # The create subcommand
72
+ def create(options)
73
+ tm = TicketMaster.new(options[:provider], options[:authentication])
74
+ project = tm.project.create(options[:project_attributes])
75
+ read_project project
76
+ exit
77
+ end
78
+
79
+ # The read subcommand
80
+ def read(options)
81
+ tm = TicketMaster.new(options[:provider], options[:authentication])
82
+ project = tm.project.find(options[:project].to_i)
83
+ read_project project
84
+ exit
85
+ end
86
+
87
+ # The update subcommand
88
+ def update(options)
89
+ tm = TicketMaster.new(options[:provider], options[:authentication])
90
+ project = tm.project.find(options[:project].to_i)
91
+ if project.update!(options[:project_attributes])
92
+ puts "Successfully updated Project #{project.name} (#{project.id})"
93
+ else
94
+ puts "Sorry, it seems there was an error when trying to update the attributes"
95
+ end
96
+ read_project project
97
+ exit
98
+ end
99
+
100
+ # The destroy subcommand.
101
+ def destroy(options)
102
+ tm = TicketMaster.new(options[:provider], options[:authentication])
103
+ project = tm.project.find(options[:project].to_i)
104
+ puts "Are you sure you want to delete Project #{project.name} (#{project.id})? (yes/no) [no]"
105
+ ARGV.clear
106
+ confirm = readline.chomp.downcase
107
+ if confirm != 'y' and confirm != 'yes'
108
+ puts "Did not receive a 'yes' confirmation. Exiting..."
109
+ exit
110
+ elsif project.destroy
111
+ puts "Successfully deleted Project #{project.name} (#{project.id})"
112
+ else
113
+ puts "Sorry, it seems there was an error when trying to delete the project"
114
+ end
115
+ exit
116
+ end
117
+
118
+ # The search and list subcommands
119
+ def search(options)
120
+ tm = TicketMaster.new(options[:provider], options[:authentication])
121
+ projects = tm.projects(options[:project_attributes])
122
+ puts "Found #{projects.length} projects"
123
+ projects.each_with_index do |project, index|
124
+ puts "#{index+1}) Project #{project.name} (#{project.id})"
125
+ read_project project
126
+ puts
127
+ end
128
+ exit
129
+ end
130
+
131
+ # A utility method used to output project attributes
132
+ def read_project(project)
133
+ project.system_data[:client].attributes.sort.each do |key, value|
134
+ puts "#{key} : #{value}"
135
+ end
136
+ end
@@ -0,0 +1,136 @@
1
+ require 'rubygems'
2
+ # The command method call for project
3
+ # This sets the option parser and passes the parsed options to the subcommands
4
+ def ticket(options)
5
+ ARGV << '--help' if ARGV.length == 0
6
+ begin
7
+ OptionParser.new do |opts|
8
+ opts.banner = 'Usage: ticket -p PROVIDER -P PROJECT [options] ticket [ticket_options]'
9
+ opts.separator ''
10
+ opts.separator 'Options:'
11
+
12
+ opts.on('-T', '--ticket TICKET', 'Sets the working ticket') do |id|
13
+ options[:ticket] = id
14
+ end
15
+ opts.on('-C', '--create ATTRIBUTES', 'Create a new ticket') do |attribute|
16
+ options[:ticket_attributes] = {attribute => ARGV.shift}.merge(attributes_hash(ARGV))
17
+ options[:subcommand] = 'create'
18
+ end
19
+
20
+ opts.on('-R', '--read', 'Read out ticket and its attributes. Requires --ticket to be set') do
21
+ options[:subcommand] = 'read'
22
+ end
23
+
24
+ opts.on('-U', '--update ATTRIBUTES', 'Update ticket information. Requires --ticket to be set') do |attribute|
25
+ options[:ticket_attributes] = {attribute => ARGV.shift}.merge(attributes_hash(ARGV))
26
+ options[:subcommand] = 'update'
27
+ end
28
+
29
+ opts.on('-D', '--destroy', 'Destroy/Delete the ticket. Not reversible! Requires --ticket to be set') do
30
+ options[:subcommand] = 'destroy'
31
+ end
32
+
33
+ opts.on('-I', '--info', 'Get ticket info. Same as --read. ') do
34
+ options[:subcommand] = 'read'
35
+ end
36
+
37
+ opts.on('-S', '--search [ATTRIBUTES]', 'Search for a ticket based on attributes') do |attribute|
38
+ options[:ticket_attributes] = attribute ? {attribute => ARGV.shift}.merge(attributes_hash(ARGV)) : {}
39
+ options[:subcommand] = 'search'
40
+ end
41
+
42
+ opts.on('-L', '--list-all', 'List all tickets. Same as --search without any parameters') do
43
+ options[:ticket_attributes] = {}
44
+ options[:subcommand] = 'search'
45
+ end
46
+
47
+ opts.separator ''
48
+ opts.separator 'Other options:'
49
+
50
+ opts.on_tail('-h', '--help', 'Show this message') do
51
+ puts opts
52
+ exit
53
+ end
54
+ end.order!
55
+ rescue OptionParser::MissingArgument => exception
56
+ puts "ticket #{options[:original_argv].join(' ')}\n\n"
57
+ puts "Error: An option was called that requires an argument, but was not given one"
58
+ puts exception.message
59
+ end
60
+ parse_config!(options)
61
+ begin
62
+ require 'ticketmaster'
63
+ require "ticketmaster-#{options[:provider]}"
64
+ rescue
65
+ require options[:provider]
66
+ end
67
+ send(options[:subcommand], options)
68
+ end
69
+
70
+
71
+ # The create subcommand
72
+ def create(options)
73
+ tm = TicketMaster.new(options[:provider], options[:authentication])
74
+ ticket = tm.ticket.create(options[:ticket_attributes].merge({:project_id => options[:project].to_i}))
75
+ read_ticket ticket
76
+ exit
77
+ end
78
+
79
+ # The read subcommand
80
+ def read(options)
81
+ tm = TicketMaster.new(options[:provider], options[:authentication])
82
+ ticket = tm.ticket.find(options[:ticket].to_i, options[:project].to_i)
83
+ read_ticket ticket
84
+ exit
85
+ end
86
+
87
+ # The update subcommand
88
+ def update(options)
89
+ tm = TicketMaster.new(options[:provider], options[:authentication])
90
+ ticket = tm.ticket.find(options[:ticket].to_i, options[:project].to_i)
91
+ if ticket.update!(options[:ticket_attributes])
92
+ puts "Successfully updated Ticket #{ticket.title} (#{ticket.id})"
93
+ else
94
+ puts "Sorry, it seems there was an error when trying to update the attributes"
95
+ end
96
+ read_ticket ticket
97
+ exit
98
+ end
99
+
100
+ # The destroy subcommand.
101
+ def destroy(options)
102
+ tm = TicketMaster.new(options[:provider], options[:authentication])
103
+ ticket = tm.ticket.find(options[:ticket].to_i, options[:project].to_i)
104
+ puts "Are you sure you want to delete Ticket #{ticket.title} (#{ticket.id})? (yes/no) [no]"
105
+ ARGV.clear
106
+ confirm = readline.chomp.downcase
107
+ if confirm != 'y' and confirm != 'yes'
108
+ puts "Did not receive a 'yes' confirmation. Exiting..."
109
+ exit
110
+ elsif ticket.destroy
111
+ puts "Successfully deleted Ticket #{ticket.title} (#{ticket.id})"
112
+ else
113
+ puts "Sorry, it seems there was an error when trying to delete the project"
114
+ end
115
+ exit
116
+ end
117
+
118
+ # The search and list subcommands
119
+ def search(options)
120
+ tm = TicketMaster.new(options[:provider], options[:authentication])
121
+ tickets = tm.ticket.find(options[:ticket_attributes])
122
+ puts "Found #{tickets.length} tickets"
123
+ tickets.each_with_index do |ticket, index|
124
+ puts "#{index+1}) Ticket #{ticket.title} (#{ticket.id})"
125
+ read_ticket ticket
126
+ puts
127
+ end
128
+ exit
129
+ end
130
+
131
+ # A utility method used to output project attributes
132
+ def read_ticket(ticket)
133
+ ticket.system_data[:client].attributes.sort.each do |key, value|
134
+ puts "#{key} : #{value}"
135
+ end
136
+ end