Class: Sem4rCli::CommandRepDef
- Inherits:
-
OptParseCommand::Command
- Object
- OptParseCommand::Command
- Sem4rCli::CommandRepDef
- Defined in:
- lib/sem4r_cli/commands/cmd_repdef.rb
Overview
Report Definition (v201008 api)
Class Method Summary collapse
Instance Method Summary collapse
- #command_opt_parser(options) ⇒ Object
-
#initialize(sem4r_cli) ⇒ CommandRepDef
constructor
A new instance of CommandRepDef.
- #parse_and_run(argv) ⇒ Object
Constructor Details
#initialize(sem4r_cli) ⇒ CommandRepDef
Returns a new instance of CommandRepDef.
46 47 48 |
# File 'lib/sem4r_cli/commands/cmd_repdef.rb', line 46 def initialize(sem4r_cli) @sem4r_cli = sem4r_cli end |
Class Method Details
.command ⇒ Object
34 35 36 |
# File 'lib/sem4r_cli/commands/cmd_repdef.rb', line 34 def self.command "repdef" end |
.description ⇒ Object
42 43 44 |
# File 'lib/sem4r_cli/commands/cmd_repdef.rb', line 42 def self.description "manage report definition (subcommands: #{subcommands.join(", ")})" end |
.subcommands ⇒ Object
38 39 40 |
# File 'lib/sem4r_cli/commands/cmd_repdef.rb', line 38 def self.subcommands %w{fields list create} end |
Instance Method Details
#command_opt_parser(options) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/sem4r_cli/commands/cmd_repdef.rb', line 50 def command_opt_parser() opt_parser = OptionParser.new opt_parser. = "Usage #{self.class.command} [command_options ] [#{self.class.subcommands.join("|")}]" opt_parser.separator "" opt_parser.separator "#{self.class.description}" opt_parser.on("-h", "--help", "show this message") do puts opt_parser .exit = true end end |
#parse_and_run(argv) ⇒ Object
61 62 63 64 65 66 67 68 69 70 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 |
# File 'lib/sem4r_cli/commands/cmd_repdef.rb', line 61 def parse_and_run(argv) = OpenStruct.new rest = command_opt_parser().parse(argv) if .exit return false end if rest.empty? puts "missing command" return false end account = @sem4r_cli.account ret = true subcommand = rest[0] subcommand_args = rest[1..-1] case subcommand when "fields" report_type = ReportDefinition::AD_PERFORMANCE_REPORT puts "Fields for #{report_type}" Sem4rCli::report(account.report_fields(report_type), :field_name, :field_type) when "list" Sem4rCli::report(account.report_definitions, :id, :name) when "delete" report_definition_id = rest[1] account.report_definition_delete(report_definition_id) when "create" ret = create(account) else puts "unknow subcommand '#{subcommand}'; must be one of #{subcommands.join(", ")}" return false end account.adwords.p_counters ret end |