Module: Hisui::Model

Defined in:
lib/hisui/model.rb

Instance Method Summary collapse

Instance Method Details

#dimensions(*field) ⇒ ListParameter

Adds dimensions to the class for retrieval from GA

Parameters:

  • fields (Symbol)

    the names of the fields to retrieve

Returns:

  • (ListParameter)

    the set of all dimensions



17
18
19
20
21
# File 'lib/hisui/model.rb', line 17

def dimensions(*field)
  @dimensions ||= Set.new([])
  field.try(:each) { |f| @dimensions << { name: Hisui.to_ga_string(f) } }
  @dimensions
end

#filters_expression(field = nil) ⇒ Object

Adds filters_expression to the class for retrieval from GA

operators are ‘==’, ‘~=’ and so on. cf: developers.google.com/analytics/devguides/reporting/core/v3/reference?hl=ja#filters

Parameters:

  • field (Hash) (defaults to: nil)

    options:

    • field_name

    • operator

    • value

Returns:

  • concatenated string



47
48
49
50
51
# File 'lib/hisui/model.rb', line 47

def filters_expression(field = nil)
  @filters_expression ||= ''
  @filters_expression = Hisui::FiltersExpression.new(field).to_param if field
  @filters_expression
end

#metrics(*field) ⇒ ListParameter

Adds metrics to the class for retrieval from GA

Parameters:

  • fields (Symbol)

    the names of the fields to retrieve

Returns:

  • (ListParameter)

    the set of all metrics



7
8
9
10
11
# File 'lib/hisui/model.rb', line 7

def metrics(*field)
  @metrics ||= Set.new([])
  field.try(:each) { |f| @metrics << { expression: Hisui.to_ga_string(f) } }
  @metrics
end

#order_bys(field = nil) ⇒ Object

Parameters:

  • field (Hash) (defaults to: nil)

    options:

    • field_name

    • order_type

    • sort_order



31
32
33
34
35
# File 'lib/hisui/model.rb', line 31

def order_bys(field = nil)
  @order_bys ||= Set.new([])
  @order_bys << field if field
  @order_bys
end

#results(profile:, **options) ⇒ Object



53
54
55
# File 'lib/hisui/model.rb', line 53

def results(profile:, **options)
  Hisui::Request.new(profile: profile, model: self, **options).fetch_data
end