Class: Flurry::Request

Inherits:
Object
  • Object
show all
Includes:
Helper, HTTParty
Defined in:
lib/flurry/request.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, group_by) ⇒ Request

Returns a new instance of Request.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
# File 'lib/flurry/request.rb', line 12

def initialize(table, group_by)
  raise ArgumentError, 'table must be non nil' if table.nil?

  @table = table
  @grain = group_by || :day
end

Instance Attribute Details

#format(format) ⇒ Object



63
64
65
# File 'lib/flurry/request.rb', line 63

def format(format)
  dup.tap { |it| it.format = format }
end

#time_zone(time_zone) ⇒ Object



59
60
61
# File 'lib/flurry/request.rb', line 59

def time_zone(time_zone)
  dup.tap { |it| it.time_zone = time_zone }
end

Instance Method Details

#between(start, finish = nil, format: '%Y-%m-%d') ⇒ Object

Raises:



33
34
35
36
37
38
39
40
41
# File 'lib/flurry/request.rb', line 33

def between(start, finish = nil, format: '%Y-%m-%d')
  raise Flurry::Error, 'at least start time has to be provided' unless start

  finish ||= datetime?(start) ? tomorrow(start) : start
  finish = finish.strftime(format) if datetime? finish
  start = start.strftime(format) if datetime? start

  dup.tap { |it| it.range = [start, finish] }
end

#fetch(timeout = Flurry.configuration.timeout) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/flurry/request.rb', line 67

def fetch(timeout = Flurry.configuration.timeout)
  options = {}
  options[:timeout] = timeout
  options[:format] = @format || Flurry.configuration.format

  Response.new self.class.get(full_path, options)
end

#having(**havings) ⇒ Object

Raises:



53
54
55
56
57
# File 'lib/flurry/request.rb', line 53

def having(**havings)
  raise Flurry::Error, 'metrics must be provided before having' unless @metrics

  dup.tap { |it| it.havings = merge(it.havings, clean_havings(havings || {})) }
end

#select(*metrics) ⇒ Object

Raises:



23
24
25
26
27
28
29
30
31
# File 'lib/flurry/request.rb', line 23

def select(*metrics)
  metrics = metrics.flatten.reject(&:nil?) || []
  raise Flurry::Error, 'at least one metric has to be provided' if metrics.empty?

  dup.tap do |it|
    it.metrics ||= []
    it.metrics |= metrics.map { |m| camelize(m.to_s) }
  end
end

#showing(**dimensions) ⇒ Object



19
20
21
# File 'lib/flurry/request.rb', line 19

def showing(**dimensions)
  dup.tap { |it| it.dimensions = merge(it.dimensions, clean_dimensions(dimensions || {})) }
end

#sort(sorts, top = 0) ⇒ Object

Raises:



43
44
45
46
47
48
49
50
51
# File 'lib/flurry/request.rb', line 43

def sort(sorts, top = 0)
  raise Flurry::Error, 'metrics must be provided before sort' unless @metrics

  sorts = { sorts => nil } unless sorts.is_a?(Hash)
  dup.tap do |it|
    it.sorts = merge(it.sorts, clean_sorts(sorts || {}))
    it.top = top
  end
end