Class: Sem4rCli::CommandRepDef

Inherits:
OptParseCommand::Command
  • Object
show all
Defined in:
lib/sem4r_cli/commands/cmd_repdef.rb

Overview

Report Definition (v201008 api)

Class Method Summary collapse

Instance Method Summary collapse

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

.commandObject



34
35
36
# File 'lib/sem4r_cli/commands/cmd_repdef.rb', line 34

def self.command
  "repdef"
end

.descriptionObject



42
43
44
# File 'lib/sem4r_cli/commands/cmd_repdef.rb', line 42

def self.description
  "manage report definition (subcommands: #{subcommands.join(", ")})"
end

.subcommandsObject



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(options)
  opt_parser        = OptionParser.new
  opt_parser.banner = "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
    options.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)
  options = OpenStruct.new
  rest    = command_opt_parser(options).parse(argv)
  if options.exit
    return false
  end

  if rest.empty?
    puts "missing command"
    return false
  end

           = @sem4r_cli.
  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(.report_fields(report_type), :field_name, :field_type)

    when "list"
      Sem4rCli::report(.report_definitions, :id, :name)

    when "delete"
      report_definition_id = rest[1]
      .report_definition_delete(report_definition_id)

    when "create"
      ret = create()
    else
      puts "unknow subcommand '#{subcommand}'; must be one of #{subcommands.join(", ")}"
      return false
  end
  .adwords.p_counters
  ret
end