Class: GACli::Subcommand::Ga

Inherits:
Base
  • Object
show all
Defined in:
lib/ga_shikomi/subcommand/ga.rb

Instance Attribute Summary

Attributes inherited from Base

#api, #options

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from GACli::Subcommand::Base

Instance Method Details

#get(config) ⇒ Object

require –profile-id –begin-date –end-date –metrics



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
# File 'lib/ga_shikomi/subcommand/ga.rb', line 10

def get(config)
  opts = {
    'ids'        => options['profile_id'],
    'start-date' => options['start_date'],
    'end-date'   => options['end_date'],
    'metrics'    => options['metrics']
  }
  %w(ids
     metrics
     dimensions
     filters
     max-results
     output
     samplingLevel
     segment
     sort
     start-index
     fields).each {|e|
    opts[e] = config[e] if config[e]
  } if config

  result = api.execute(api.analytics.data.ga.get, opts)

  case result['rows'].size
  when 1
    [result['totalsForAllResults']]
  else
    fields = %w(columnHeaders totalsForAllResults rows)
    fields.map {|e| {e => result[e]}}.reduce(:merge)
  end
end