Method: GAAPI::Main.call

Defined in:
lib/gaapi/main.rb

.callObject



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
# File 'lib/gaapi/main.rb', line 8

def call
  begin
    return false if (options = process_options).nil?

    puts "options: #{options.inspect}" if options[:debug]

    # return unless (result = Query.call(options))
    query = Query.new((options[:query_file] || $stdin).read,
      options[:view_id],
      options[:access_token],
      options[:start_date],
      options[:end_date])
    puts "query: #{query.inspect}" if options[:debug]
  rescue StandardError => e
    $stderr.puts e.message # rubocop:disable Style/StderrPuts
    return false
  end

  return true if options[:dry_run]

  result = query.execute
  puts "result: #{result.inspect}" if options[:debug]

  unless result.success?
    # Show the output unformatted, because we don't know what we're going
    # to get back.
    puts result.body
    return false
  end

  case options[:output_format]
  when :csv
    puts result.csv
  else
    puts result.pp
  end

  true
end