flurry 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flurry/request.rb +33 -3
- data/lib/flurry/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5702aba374c6b60521137823bd21d7c086f18c2b1629a336456afd94f11ac56
|
4
|
+
data.tar.gz: 605807aeee9a6e06057d90a32bf306523d8d12d1275ead1df47bdc21b3ecec77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c802dfcfe04234df2007bfdda5ab2530656e7f9ad7a72c300ff9bf9f60349ed050dce115eb20da88cec2e9061568ac8c1a4b6124b37067c45b74a979691f6aa
|
7
|
+
data.tar.gz: cf6ee0bcdac4283856fa0a4fdaad0f6775519c557431902aeea74250d031d2493aa6e52cd1c1c6b288e88739846f4f3457bea71fbccc78a4a044c1f9c1b090ac
|
data/lib/flurry/request.rb
CHANGED
@@ -23,7 +23,7 @@ module Flurry
|
|
23
23
|
metrics = metrics.flatten.reject(&:nil?) || []
|
24
24
|
raise Flurry::Error, 'at least one metric has to be provided' if metrics.empty?
|
25
25
|
|
26
|
-
dup.tap { |it| it.metrics = metrics }
|
26
|
+
dup.tap { |it| it.metrics = metrics.map { |m| camelize(m.to_s) } }
|
27
27
|
end
|
28
28
|
|
29
29
|
def between(start, finish = nil, format: '%Y-%m-%d')
|
@@ -37,13 +37,23 @@ module Flurry
|
|
37
37
|
dup.tap { |it| it.range = [start, finish] }
|
38
38
|
end
|
39
39
|
|
40
|
+
def sort(sorts, top = 0)
|
41
|
+
raise Flurry::Error, 'metrics must be provided before sort' unless @metrics
|
42
|
+
|
43
|
+
sorts = { sorts => nil } unless sorts.is_a?(Hash)
|
44
|
+
dup.tap do |it|
|
45
|
+
it.sorts = clean_sorts(sorts || {})
|
46
|
+
it.top = top
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
40
50
|
def fetch
|
41
51
|
self.class.get(full_path).response
|
42
52
|
end
|
43
53
|
|
44
54
|
protected
|
45
55
|
|
46
|
-
attr_writer :table, :grain, :dimensions, :metrics, :range
|
56
|
+
attr_writer :table, :grain, :dimensions, :metrics, :range, :sorts, :top
|
47
57
|
|
48
58
|
private
|
49
59
|
|
@@ -56,6 +66,15 @@ module Flurry
|
|
56
66
|
end
|
57
67
|
end
|
58
68
|
|
69
|
+
def clean_sorts(sorts)
|
70
|
+
sorts.each_with_object({}) do |(key, val), h|
|
71
|
+
next if key.nil?
|
72
|
+
|
73
|
+
k = camelize(key.to_s)
|
74
|
+
h[k] = val || :desc if @metrics.include? k
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
59
78
|
def base_partial_path
|
60
79
|
"/#{camelize(@table.to_s)}/#{@grain}"
|
61
80
|
end
|
@@ -73,7 +92,7 @@ module Flurry
|
|
73
92
|
|
74
93
|
def metrics_partial_path
|
75
94
|
'&metrics=' + @metrics.map do |metric|
|
76
|
-
|
95
|
+
metric unless metric.nil?
|
77
96
|
end.join(',')
|
78
97
|
end
|
79
98
|
|
@@ -81,6 +100,16 @@ module Flurry
|
|
81
100
|
"&dateTime=#{@range.join('/')}"
|
82
101
|
end
|
83
102
|
|
103
|
+
def sort_partial_path
|
104
|
+
return '' unless @sorts && @sorts.any?
|
105
|
+
|
106
|
+
partial = ("&topN=#{@top}" if @top && @top.positive?) || ''
|
107
|
+
partial.tap do |path|
|
108
|
+
path << '&sort='
|
109
|
+
path << @sorts.map { |k, v| "#{k}|#{v}" }.join(',')
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
84
113
|
def full_path
|
85
114
|
''.tap do |path|
|
86
115
|
path << base_partial_path
|
@@ -89,6 +118,7 @@ module Flurry
|
|
89
118
|
path << 'token=' + Flurry.configuration.token
|
90
119
|
path << '&timeZone=' + Flurry.configuration.time_zone if Flurry.configuration.time_zone
|
91
120
|
path << metrics_partial_path
|
121
|
+
path << sort_partial_path
|
92
122
|
path << time_range_partial_path
|
93
123
|
end
|
94
124
|
end
|
data/lib/flurry/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flurry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roger Bagué
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -91,9 +91,9 @@ require_paths:
|
|
91
91
|
- lib
|
92
92
|
required_ruby_version: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: '0'
|
97
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
98
|
requirements:
|
99
99
|
- - ">="
|