Top Level Namespace
Defined Under Namespace
Classes: TicketMaster
Instance Method Summary collapse
-
#add(options) ⇒ Object
Called on –add.
-
#attributes_hash(kvlist) ⇒ Object
A utility method used to separate name:value pairs.
-
#config(options) ⇒ Object
The command method call implementation This sets the option parser and passes the parsed options to the subcommands.
-
#console(options) ⇒ Object
the console command.
-
#copy_skeleton(options) ⇒ Object
Copy over the skeleton files.
-
#create(options) ⇒ Object
The create subcommand.
-
#create_directories(options) ⇒ Object
Create the directories so copy_skeleton can do its job.
-
#create_file(options, filename, data) ⇒ Object
Create files.
-
#destroy(options) ⇒ Object
The destroy subcommand.
-
#edit(options) ⇒ Object
Called on –edit.
-
#generate(options) ⇒ Object
The generate command.
-
#help(options) ⇒ Object
The help command.
-
#open_irb(options, argv) ⇒ Object
the actual method to do the irb opening.
-
#parse_config!(options) ⇒ Object
Parses the configuration information and puts it into options.
-
#project(options) ⇒ Object
This sets the option parser and passes the parsed options to the subcommands.
-
#read(options) ⇒ Object
The read subcommand.
-
#read_project(project) ⇒ Object
A utility method used to output project attributes.
-
#read_ticket(ticket) ⇒ Object
A utility method used to output project attributes.
-
#require_provider ⇒ Object
Called when a provider is not given.
-
#search(options) ⇒ Object
The search and list subcommands.
-
#set_default_provider(options) ⇒ Object
Called on –set-default-provider.
-
#ticket(options) ⇒ Object
This sets the option parser and passes the parsed options to the subcommands.
-
#update(options) ⇒ Object
The update subcommand.
Instance Method Details
#add(options) ⇒ Object
Called on –add. It adds a new entry to the config file and will refuse if it already exists
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ticketmaster/cli/commands/config.rb', line 40 def add() require_provider unless [:provider] provider = [:provider] config_file = File.([:config]) config = if File.exists?(config_file) YAML.load_file(config_file) else {} end if config[provider] puts "#{provider} has already been specfied in #{[:config]}. Refusing to add. Use --edit instead." exit 1 end config[provider] = {} config[provider]['authentication'] = [:authentication] || {} config[provider]['project'] = [:project] if [:project] File.open(config_file, 'w') do |out| YAML.dump(config, out) end puts "Wrote #{provider} to #{config_file}" exit end |
#attributes_hash(kvlist) ⇒ Object
A utility method used to separate name:value pairs
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ticketmaster/cli/common.rb', line 13 def attributes_hash(kvlist) require 'enumerator' if RUBY_VERSION < "1.8.7" if kvlist.is_a?(String) kvlist.split(',').inject({}) do |mem, kv| key, value = kv.split(':') mem[key] = value mem end elsif kvlist.is_a?(Array) mem = {} kvlist.each_slice(2) do |k, v| mem[k] = v end mem end end |
#config(options) ⇒ Object
The command method call implementation This sets the option parser and passes the parsed options to the subcommands
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ticketmaster/cli/commands/config.rb', line 3 def config() ARGV << '--help' if ARGV.length == 0 begin OptionParser.new do |opts| opts. = 'Usage: ticket -p PROVIDER [options] config [config_options]' opts.separator '' opts.separator 'Options:' opts.on('-a', '--add', 'Add a new entry to the configuration file based on ticketmaster options.') do [:subcommand] = 'add' end opts.on('-e', '--edit', 'Edit an existing entry to the configuration file based on ticketmaster options') do [:subcommand] = 'edit' end opts.on('-p', '--set-default-provider', 'Set the current provider as the default.', 'Requires provider to be specified, otherwise unsets the default') do [:subcommand] = 'set_default_provider' end opts.separator '' opts.separator 'Other options:' opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end.parse(ARGV) rescue OptionParser::MissingArgument => exception puts "ticket #{[:original_argv].join(' ')}\n\n" puts "Error: An option was called that requires an argument, but was not given one" puts exception. end send([:subcommand], ) end |
#console(options) ⇒ Object
the console command
2 3 4 |
# File 'lib/ticketmaster/cli/commands/console.rb', line 2 def console() send(:open_irb, , ARGV) end |
#copy_skeleton(options) ⇒ Object
Copy over the skeleton files
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ticketmaster/cli/commands/generate.rb', line 57 def copy_skeleton() skeleton_path = File.dirname(__FILE__) + '/generate/' provider = File.read(skeleton_path + 'provider.rb').gsub('yoursystem', [:provider].downcase) create_file(, [:provider_dir] + '.rb', provider) skeleton_path << 'provider/' provider = File.read(skeleton_path + 'provider.rb').gsub('Yoursystem', [:provider].capitalize).gsub('yoursystem', [:provider].downcase) create_file(, 'provider/' + [:provider].downcase + '.rb', provider) %w(project.rb ticket.rb comment.rb).each do |p| provider = File.read(skeleton_path + p).gsub('Yoursystem', [:provider].capitalize).gsub('yoursystem', [:provider].downcase) create_file(, 'provider/' + p, provider) end end |
#create(options) ⇒ Object
The create subcommand
77 78 79 80 81 82 |
# File 'lib/ticketmaster/cli/commands/ticket.rb', line 77 def create() tm = TicketMaster.new([:provider], [:authentication]) ticket = tm.ticket.create([:ticket_attributes].merge({:project_id => [:project]})) read_ticket ticket exit end |
#create_directories(options) ⇒ Object
Create the directories so copy_skeleton can do its job
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ticketmaster/cli/commands/generate.rb', line 71 def create_directories() if [:jeweler] = [:jeweler].inject('') do |mem, j| j="'#{j}'" if j.include?(' ') mem + j + ' ' end puts "Running jeweler #{} #{[:provider_dir]}" puts `jeweler #{} #{[:provider_dir]}` elsif [:mkdir] begin Dir.mkdir([:provider_dir]) puts "\tcreate\t#{[:provider_dir]}" rescue Exception => e puts "\t#{e.}" end begin Dir.mkdir([:lib]) puts "\tcreate\t#{[:lib]}" rescue Exception => e puts "\t#{e.}" end end begin Dir.mkdir([:lib] + '/provider') puts "\tcreate\t#{[:lib] + 'provider'}" rescue Exception => e puts "\t#{e.}" end end |
#create_file(options, filename, data) ⇒ Object
Create files
102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/ticketmaster/cli/commands/generate.rb', line 102 def create_file(, filename, data) file_path = [:lib] + '/' + filename if File.exist?(file_path) and File.size(file_path) > 0 puts "\texists with content...skipping\t#{filename}" return false; end puts "\tcreate\t#{filename}" f = File.open(file_path, 'a+') f.write data f.close end |
#destroy(options) ⇒ Object
The destroy subcommand.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/ticketmaster/cli/commands/ticket.rb', line 108 def destroy() tm = TicketMaster.new([:provider], [:authentication]) project = tm.project([:project]) ticket = project.ticket([:ticket]) puts "Are you sure you want to delete Ticket #{ticket.title} (#{ticket.id})? (yes/no) [no]" ARGV.clear confirm = readline.chomp.downcase if confirm != 'y' and confirm != 'yes' puts "Did not receive a 'yes' confirmation. Exiting..." exit elsif ticket.destroy puts "Successfully deleted Ticket #{ticket.title} (#{ticket.id})" else puts "Sorry, it seems there was an error when trying to delete the project" end exit end |
#edit(options) ⇒ Object
Called on –edit. It updates and edits an entry. If the entry is non-existent, it will add it.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ticketmaster/cli/commands/config.rb', line 64 def edit() require_provider unless [:provider] provider = [:provider] config_file = File.([:config]) config = if File.exist?(config_file) YAML.load_file(config_file) else {} end config[provider] ||= {} config[provider]['authentication'] = [:authentication] || {} config[provider]['project'] = [:project] if [:project] File.open(config_file, 'w') do |out| YAML.dump(config, out) end puts "Wrote #{provider} to #{config_file}" exit end |
#generate(options) ⇒ Object
The generate command
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ticketmaster/cli/commands/generate.rb', line 2 def generate() if ARGV.length == 0 ARGV << '--help' else provider_name = ARGV.shift if provider_name.start_with? '_' [:provider] = provider_name[1..-1] [:provider_dir] = [:provider] else [:provider] = provider_name [:provider_dir] = 'ticketmaster-' + [:provider] end end [:mkdir] = true begin OptionParser.new do |opts| opts. = 'Usage: tm generate PROVIDER_NAME [--lib-directory DIR] [--jeweler [jeweler_options]]' opts.separator '' opts.separator 'Options:' opts.on('-J', '--jeweler [JEWELER_OPTIONS]', 'Sets the working ticket') do |option| [:jeweler] = ARGV [:mkdir] = false end opts.on('-L', '--lib-directory DIR', 'Put the skeleton files inside this directory', ' * This assumes the directory already exists') do |dir| [:lib] = dir [:mkdir] = false end opts.separator '' opts.separator 'Other options:' opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end opts.separator '' opts.separator 'NOTE: ticketmaster- will be prepended to your provider name' opts.separator 'unless you set the first character as _ (it will be removed)' end.order! rescue OptionParser::MissingArgument => exception puts "tm #{[:original_argv].join(' ')}\n\n" puts "Error: An option was called that requires an argument, but was not given one" puts exception. rescue OptionParser::InvalidOption => exception [:jeweler] = exception.recover(ARGV) [:mkdir] = false end [:lib] ||= [:provider_dir] + '/lib/' create_directories() copy_skeleton() end |
#help(options) ⇒ Object
The help command.
2 3 4 5 6 7 8 9 |
# File 'lib/ticketmaster/cli/commands/help.rb', line 2 def help() cmd = ARGV.shift || 'help' page = File.dirname(__FILE__) + '/help/' + cmd if File.exist?(page) puts File.read(page) puts "\nFor parameter listing and details, try executing the command with --help.\n\ttm #{cmd} --help" end end |
#open_irb(options, argv) ⇒ Object
the actual method to do the irb opening
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ticketmaster/cli/commands/console.rb', line 7 def open_irb(, argv) tm_lib = File.dirname(__FILE__) + '/../../../ticketmaster.rb' irb_name = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb' requires = "-r rubygems -r #{tm_lib} " cmd = '' if File.exist?(config = File.([:config])) ENV['TICKETMASTER_CONFIG']=config end providers = ![:provider].nil? ? [[:provider]] : YAML.load_file(config).keys providers.delete 'default' require 'rubygems' require 'ticketmaster' providers.inject(requires) do |mem, p| begin require "ticketmaster-#{p}" requires << "-r ticketmaster-#{p} " rescue Exception => exception #puts exception begin require "#{p}" requires << "-r #{p} " rescue Exception => exception warn "Could not require the '#{p}' provider. Is it installed?" end end end cmd << "#{irb_name} #{requires} --simple-prompt #{ARGV.join(' ')}" exec cmd end |
#parse_config!(options) ⇒ Object
Parses the configuration information and puts it into options
2 3 4 5 6 7 8 9 10 |
# File 'lib/ticketmaster/cli/common.rb', line 2 def parse_config!() config = YAML.load_file File.([:config]) provider = ([:provider] ||= config['default'] || config.keys.first) if provider and provider.length > 0 [:project] ||= config[provider]['project'] [:authentication] ||= config[provider]['authentication'] end end |
#project(options) ⇒ Object
This sets the option parser and passes the parsed options to the subcommands
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ticketmaster/cli/commands/project.rb', line 4 def project() ARGV << '--help' if ARGV.length == 0 begin OptionParser.new do |opts| opts. = 'Usage: tm -p PROVIDER [options] project [project_options]' opts.separator '' opts.separator 'Options:' opts.on('-C', '--create ATTRIBUTES', 'Create a new project') do |attribute| [:project_attributes] = {attribute => ARGV.shift}.merge(attributes_hash(ARGV)) [:subcommand] = 'create' end opts.on('-R', '--read [PROJECT]', 'Read out project and its attributes') do |id| [:project] = id if id [:subcommand] = 'read' end opts.on('-U', '--update ATTRIBUTES', 'Update project information') do |attribute| [:project_attributes] = {attribute => ARGV.shift}.merge(attributes_hash(ARGV)) [:subcommand] = 'update' end opts.on('-D', '--destroy [PROJECT]', 'Destroy the project. Not reversible!') do |id| [:project] = id if id [:subcommand] = 'destroy' end opts.on('-I', '--info [PROJECT_ID]', 'Get project info. Same as --read. ') do |id| [:project] = id if id [:subcommand] = 'read' end opts.on('-S', '--search [ATTRIBUTES]', 'Search for a project based on attributes') do |attribute| [:project_attributes] = attribute ? {attribute => ARGV.shift}.merge(attributes_hash(ARGV)) : {} [:subcommand] = 'search' end opts.on('-L', '--list-all', 'List all projects. Same as --search without any parameters') do [:project_attributes] = {} [:subcommand] = 'search' end opts.on('-P', '--project [PROJECT_ID]', 'Set the project id') do |id| [:project] = id end opts.separator '' opts.separator 'Other options:' opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end.order! rescue OptionParser::MissingArgument => exception puts "tm #{[:original_argv].join(' ')}\n\n" puts "Error: An option was called that requires an argument, but was not given one" puts exception. end parse_config!() begin require 'ticketmaster' require "ticketmaster-#{[:provider]}" rescue require [:provider] end send([:subcommand], ) end |
#read(options) ⇒ Object
The read subcommand
85 86 87 88 89 90 91 |
# File 'lib/ticketmaster/cli/commands/ticket.rb', line 85 def read() tm = TicketMaster.new([:provider], [:authentication]) project = tm.project([:project]) ticket = project.ticket([:ticket]) read_ticket ticket exit end |
#read_project(project) ⇒ Object
A utility method used to output project attributes
136 137 138 139 140 |
# File 'lib/ticketmaster/cli/commands/project.rb', line 136 def read_project(project) project.system_data[:client].attributes.sort.each do |key, value| puts "#{key} : #{value}" end end |
#read_ticket(ticket) ⇒ Object
A utility method used to output project attributes
141 142 143 144 145 |
# File 'lib/ticketmaster/cli/commands/ticket.rb', line 141 def read_ticket(ticket) ticket.system_data[:client].attributes.sort.each do |key, value| puts "#{key} : #{value}" end end |
#require_provider ⇒ Object
Called when a provider is not given.
97 98 99 100 |
# File 'lib/ticketmaster/cli/commands/config.rb', line 97 def require_provider puts "Provider must be specified!" exit 1 end |
#search(options) ⇒ Object
The search and list subcommands
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/ticketmaster/cli/commands/ticket.rb', line 127 def search() tm = TicketMaster.new([:provider], [:authentication]) project = tm.project([:project]) tickets = project.tickets([:ticket_attributes]) puts "Found #{tickets.length} tickets" tickets.each_with_index do |ticket, index| puts "#{index+1}) Ticket #{ticket.title} (#{ticket.id})" #read_ticket ticket #puts end exit end |
#set_default_provider(options) ⇒ Object
Called on –set-default-provider. It sets the current provider as the default
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ticketmaster/cli/commands/config.rb', line 84 def set_default_provider() provider = [:provider] config = YAML.load_file(config_file = File.([:config])) puts "Warning! #{provider} is not defined in #{config_file}" unless provider.nil? or config[provider] config['default'] = provider File.open(config_file, 'w') do |out| YAML.dump(config, out) end puts "Default provider has been set to '#{provider}'" exit end |
#ticket(options) ⇒ Object
This sets the option parser and passes the parsed options to the subcommands
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ticketmaster/cli/commands/ticket.rb', line 4 def ticket() ARGV << '--help' if ARGV.length == 0 begin OptionParser.new do |opts| opts. = 'Usage: tm -p PROVIDER -P PROJECT [options] ticket [ticket_options]' opts.separator '' opts.separator 'Options:' opts.on('-T', '--ticket TICKET', 'Sets the working ticket') do |id| [:ticket] = id end opts.on('-C', '--create ATTRIBUTES', 'Create a new ticket') do |attribute| [:ticket_attributes] = {attribute => ARGV.shift}.merge(attributes_hash(ARGV)) [:subcommand] = 'create' end opts.on('-R', '--read [TICKET]', 'Read out ticket and its attributes. Requires --ticket to be set') do |id| [:ticket] = id if id [:subcommand] = 'read' end opts.on('-U', '--update ATTRIBUTES', 'Update ticket information. Requires --ticket to be set') do |attribute| [:ticket_attributes] = {attribute => ARGV.shift}.merge(attributes_hash(ARGV)) [:subcommand] = 'update' end opts.on('-D', '--destroy', 'Destroy/Delete the ticket. Not reversible! Requires --ticket to be set') do [:subcommand] = 'destroy' end opts.on('-I', '--info', 'Get ticket info. Same as --read. ') do [:subcommand] = 'read' end opts.on('-S', '--search [ATTRIBUTES]', 'Search for a ticket based on attributes') do |attribute| [:ticket_attributes] = attribute ? {attribute => ARGV.shift}.merge(attributes_hash(ARGV)) : {} [:subcommand] = 'search' end opts.on('-L', '--list-all', 'List all tickets. Same as --search without any parameters') do [:ticket_attributes] = {} [:subcommand] = 'search' end opts.on('-P', '--project [PROJECT_ID]', 'Set the project id') do |id| [:project] = id end opts.separator '' opts.separator 'Other options:' opts.on_tail('-h', '--help', 'Show this message') do puts opts exit end end.order! rescue OptionParser::MissingArgument => exception puts "tm #{[:original_argv].join(' ')}\n\n" puts "Error: An option was called that requires an argument, but was not given one" puts exception. end parse_config!() begin require 'ticketmaster' require "ticketmaster-#{[:provider]}" rescue require [:provider] end send([:subcommand], ) end |
#update(options) ⇒ Object
The update subcommand
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ticketmaster/cli/commands/ticket.rb', line 94 def update() tm = TicketMaster.new([:provider], [:authentication]) project = tm.project([:project]) ticket = project.ticket([:ticket]) if ticket.update!([:ticket_attributes]) puts "Successfully updated Ticket #{ticket.title} (#{ticket.id})" else puts "Sorry, it seems there was an error when trying to update the attributes" end read_ticket ticket exit end |