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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aab9d43586ace9b91f12ef33efe629a925b6965615760ae91302574330bba5e6
4
- data.tar.gz: aad2af4110cd6fa68efaad1cd5c9e8ca886d2248684d1bc1c404c755c3ac5363
3
+ metadata.gz: b5702aba374c6b60521137823bd21d7c086f18c2b1629a336456afd94f11ac56
4
+ data.tar.gz: 605807aeee9a6e06057d90a32bf306523d8d12d1275ead1df47bdc21b3ecec77
5
5
  SHA512:
6
- metadata.gz: e515c93beb93060111cb0b87355b08de981d688f258017a697a5c1591ed7950e5c6aa923431c25f41113807d7dcc43ead3d2ab2ada24155beed0518abfdd0af1
7
- data.tar.gz: 1d7858cb57f6a9e14a7d3484ee9eec409565777a881d270eb33c6debba90afdd487b0a7e39571ad6ae22d8bec0346590b11530a90a0cc46dbb8af101b2f2660f
6
+ metadata.gz: 5c802dfcfe04234df2007bfdda5ab2530656e7f9ad7a72c300ff9bf9f60349ed050dce115eb20da88cec2e9061568ac8c1a4b6124b37067c45b74a979691f6aa
7
+ data.tar.gz: cf6ee0bcdac4283856fa0a4fdaad0f6775519c557431902aeea74250d031d2493aa6e52cd1c1c6b288e88739846f4f3457bea71fbccc78a4a044c1f9c1b090ac
@@ -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
- camelize(metric.to_s) unless metric.nil?
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
@@ -1,3 +1,3 @@
1
1
  module Flurry
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
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.1.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-04 00:00:00.000000000 Z
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: 2.0.0
96
+ version: '0'
97
97
  required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - ">="