Module: Garb::Model

Defined in:
lib/garb/model.rb

Constant Summary collapse

MONTH =
2592000
URL =
"https://www.google.com/analytics/feeds/data"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



6
7
8
# File 'lib/garb/model.rb', line 6

def self.extended(base)
  ProfileReports.add_report_method(base)
end

Instance Method Details

#dimensions(*fields) ⇒ Object



15
16
17
18
# File 'lib/garb/model.rb', line 15

def dimensions(*fields)
  @dimensions ||= ReportParameter.new(:dimensions)
  @dimensions << fields
end

#instance_klassObject



24
25
26
# File 'lib/garb/model.rb', line 24

def instance_klass
  @instance_klass || OpenStruct
end

#metrics(*fields) ⇒ Object



10
11
12
13
# File 'lib/garb/model.rb', line 10

def metrics(*fields)
  @metrics ||= ReportParameter.new(:metrics)
  @metrics << fields
end

#results(profile, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/garb/model.rb', line 28

def results(profile, options = {})
  default_params = build_default_params(profile)

  param_set = [
    default_params,
    metrics.to_params,
    dimensions.to_params,
    parse_filters(options).to_params,
    parse_segment(options),
    parse_sort(options).to_params,
    build_page_params(options)
  ]

  data = send_request_for_data(profile, build_params(param_set))
  ReportResponse.new(data, instance_klass).results
end

#set_instance_klass(klass) ⇒ Object



20
21
22
# File 'lib/garb/model.rb', line 20

def set_instance_klass(klass)
  @instance_klass = klass
end