flurry 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b5702aba374c6b60521137823bd21d7c086f18c2b1629a336456afd94f11ac56
4
- data.tar.gz: 605807aeee9a6e06057d90a32bf306523d8d12d1275ead1df47bdc21b3ecec77
3
+ metadata.gz: 74f200311571ba866a1d51214386d824b1b9d3fcd982a149b0f838707886c478
4
+ data.tar.gz: 03fa9ee7ac0f313abefc2dfb93e7939048966cea25dc08c96d9bf78740f64d19
5
5
  SHA512:
6
- metadata.gz: 5c802dfcfe04234df2007bfdda5ab2530656e7f9ad7a72c300ff9bf9f60349ed050dce115eb20da88cec2e9061568ac8c1a4b6124b37067c45b74a979691f6aa
7
- data.tar.gz: cf6ee0bcdac4283856fa0a4fdaad0f6775519c557431902aeea74250d031d2493aa6e52cd1c1c6b288e88739846f4f3457bea71fbccc78a4a044c1f9c1b090ac
6
+ metadata.gz: 374239c8e7ca0ecedfe3de235ea77186348899b14a31ffae0c21db392e97b8a8e99488062bb51dce8cb0dacd9eb72004055f71f5c4893e7f4ba744ee701737d3
7
+ data.tar.gz: 177be332838006fbc41235c892aad920afcfc34f8927e51531a131057dbfb87d61359ea95979128e2beef45c636cfd5cc1f0519020c4346e6abb3f35ecf90538
@@ -47,13 +47,19 @@ module Flurry
47
47
  end
48
48
  end
49
49
 
50
+ def having(**havings)
51
+ raise Flurry::Error, 'metrics must be provided before having' unless @metrics
52
+
53
+ dup.tap { |it| it.havings = clean_havings(havings || {}) }
54
+ end
55
+
50
56
  def fetch
51
57
  self.class.get(full_path).response
52
58
  end
53
59
 
54
60
  protected
55
61
 
56
- attr_writer :table, :grain, :dimensions, :metrics, :range, :sorts, :top
62
+ attr_writer :table, :grain, :dimensions, :metrics, :range, :sorts, :top, :havings
57
63
 
58
64
  private
59
65
 
@@ -75,6 +81,15 @@ module Flurry
75
81
  end
76
82
  end
77
83
 
84
+ def clean_havings(sorts)
85
+ sorts.each_with_object({}) do |(key, val), h|
86
+ next if key.nil? || val.nil? || val.empty?
87
+
88
+ k = camelize(key.to_s)
89
+ h[k] = val if @metrics.include? k
90
+ end
91
+ end
92
+
78
93
  def base_partial_path
79
94
  "/#{camelize(@table.to_s)}/#{@grain}"
80
95
  end
@@ -110,6 +125,14 @@ module Flurry
110
125
  end
111
126
  end
112
127
 
128
+ def having_partial_path
129
+ return '' unless @havings && @havings.any?
130
+
131
+ '&having=' + @havings.map do |metric, hs|
132
+ hs.map { |k, v| "#{metric}-#{k}[#{v}]" }.join(',')
133
+ end.join(',')
134
+ end
135
+
113
136
  def full_path
114
137
  ''.tap do |path|
115
138
  path << base_partial_path
@@ -119,6 +142,7 @@ module Flurry
119
142
  path << '&timeZone=' + Flurry.configuration.time_zone if Flurry.configuration.time_zone
120
143
  path << metrics_partial_path
121
144
  path << sort_partial_path
145
+ path << having_partial_path
122
146
  path << time_range_partial_path
123
147
  end
124
148
  end
@@ -1,3 +1,3 @@
1
1
  module Flurry
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.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.2.0
4
+ version: 0.3.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 00:00:00.000000000 Z
11
+ date: 2019-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty