mixpannenkoek 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 6086d33df79e9b37754ec4834a758f08f84097ab
4
- data.tar.gz: 5b14c50436929af2868ca126a10cab450175ef0e
3
+ metadata.gz: a7399793b312fda362a710cab02c13c0061f3181
4
+ data.tar.gz: 3d4990a74dc58c7d011c83d7d9f0794ceb0eba76
5
5
  SHA512:
6
- metadata.gz: 4cf1c431e9737f3235f9aba98c9fb976357e220bb40eded73654f5365bc6102776af5bb5297b62baa70a37ab19df9309d612d1f0f8660ceb1a30fe1e09d4b736
7
- data.tar.gz: f267b2d654372851d60d078da1da63c39cb4c0802e54331ae7afcf1045192af733f3a8cdab8cb3d5786d98dd80565c05e70e29cfdd416a0d38edbff034c908bc
6
+ metadata.gz: ebed70b8633f90ef5976f67defa8d8351e47e5ac9690fafd1ec192f0d55151c25f212aa0235d604892a3e419d7b090dcc39f3026d4f1d5a890fe20ecca329634
7
+ data.tar.gz: a93ba52c09f8f521558305c7432f5115bc253f43d9f25933eeb6422c0df350984a5ced58048153356829fa565bf937fb77c291e75ddea36733c7c6e5451095f1
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Derek Kraan
1
+ Copyright (c) 2014 Springest BV
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Mixpannenkoek
2
2
 
3
- TODO: Write a gem description
3
+ This gem implements a fluent query interface for mixpanel_client.
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,47 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ Begin by configuring a model.
22
+
23
+ ```ruby
24
+ class ConversionFunnel < Mixpannenkoek::Base
25
+ set_api_key 'MY_API_KEY'
26
+ set_api_secret 'MY_API_SECRET'
27
+ set_endpoint 'funnels'
28
+
29
+ default_scope { set(funnel_id: 123456) }
30
+ end
31
+ ```
32
+
33
+ Build up a query with `where`, `group`, and `set`.
34
+
35
+ ```ruby
36
+ ConversionFunnel.where(date: 31.days.ago..1.day.ago)
37
+
38
+ ConversionFunnel.where(date: 31.days.ago..1.day.ago).where(user_id: 123).set(interval: 50).group('traffic_source')
39
+ ```
40
+
41
+ Operate on the query results fluently
42
+
43
+ ```ruby
44
+ ConversionFunnel.where(date: 31.days.ago..1.day.ago).map { |date,data| data['steps'].last['count'] }
45
+ #=> [1, 4, 2]
46
+ ```
47
+
48
+ Organize your query models with default scopes. Default scopes are heritable, so they will be automatically be applied to subclasses.
49
+ ```ruby
50
+ class ConversionFunnel < Mixpannenkoek::Base
51
+ default_scope { set(interval: 50) }
52
+ default_scope { where(user_type: 'visitor') }
53
+ end
54
+
55
+ # default scopes are heritable
56
+ # (GroupedConversionFunnel will get the default scopes
57
+ # of ConversionFunnel, in addition to its own)
58
+ class GroupedConversionFunnel < ConversionFunnel
59
+ default_scope { group('traffic_source') }
60
+ end
61
+ ```
22
62
 
23
63
  ## Contributing
24
64
 
@@ -1,3 +1,5 @@
1
+ require 'mixpannenkoek/class_inheritable_attribute'
2
+
1
3
  module Mixpannenkoek
2
4
  class Base
3
5
  extend ::Mixpannenkoek::ClassInheritableAttribute
@@ -2,13 +2,6 @@ require 'rubygems'
2
2
  require 'mixpanel_client'
3
3
 
4
4
  module Mixpannenkoek
5
- class Benchmark
6
- def self.ms(&block)
7
- return block.call unless defined?(::Benchmark)
8
- ::Benchmark.ms(&block)
9
- end
10
- end
11
-
12
5
  class Query
13
6
  class MissingRange < Exception; end
14
7
  class MissingConfiguration < Exception; end
@@ -114,11 +107,16 @@ module Mixpannenkoek
114
107
 
115
108
  def response_data
116
109
  check_parameters
117
- time = Benchmark.ms do
110
+ log do
118
111
  @mixpanel_request ||= mixpanel_client.request(*request_parameters)
119
112
  end
120
- Rails.logger.info " Mixpanel (#{time.round(1)}ms) #{request_parameters.inspect}" if defined? Rails
121
113
  @mixpanel_request
122
114
  end
115
+
116
+ def log(&block)
117
+ return block.call unless defined?(::Benchmark)
118
+ time = ::Benchmark.ms(&block)
119
+ Rails.logger.info " Mixpanel (#{time.round(1)}ms) #{request_parameters.inspect}" if defined? Rails
120
+ end
123
121
  end
124
122
  end
@@ -1,3 +1,3 @@
1
1
  module Mixpannenkoek
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,29 +1,29 @@
1
- {"Signup flow": {"data": {"2010-05-24": {"analysis": {"completion": 0.064679359580052493,
2
- "starting_amount": 762,
3
- "steps": 3,
4
- "worst": 2},
5
- "steps": [{"count": 762,
6
- "goal": "pages",
7
- "overall_conv_ratio": 1.0,
8
- "step_conv_ratio": 1.0},
9
- {"count": 69,
10
- "goal": "View signup",
11
- "overall_conv_ratio": 0.09055118110236221,
12
- "step_conv_ratio": 0.09055118110236221},
13
- {"count": 10,
14
- "goal": "View docs",
15
- "overall_conv_ratio": 0.064679359580052493,
16
- "step_conv_ratio": 0.7142857142857143}]},
17
- "2010-05-31": {"analysis": {"completion": 0.12362030905077263,
18
- "starting_amount": 906,
19
- "steps": 2,
20
- "worst": 2},
21
- "steps": [{"count": 906,
22
- "goal": "homepage",
23
- "overall_conv_ratio": 1.0,
24
- "step_conv_ratio": 1.0},
25
- {"count": 112,
26
- "goal": "View signup",
27
- "overall_conv_ratio": 0.12362030905077263,
28
- "step_conv_ratio": 0.12362030905077263}]}},
29
- "meta": {"dates": ["2010-05-24", "2010-05-31"]}}}
1
+ {"data": {"2010-05-24": {"analysis": {"completion": 0.064679359580052493,
2
+ "starting_amount": 762,
3
+ "steps": 3,
4
+ "worst": 2},
5
+ "steps": [{"count": 762,
6
+ "goal": "pages",
7
+ "overall_conv_ratio": 1.0,
8
+ "step_conv_ratio": 1.0},
9
+ {"count": 69,
10
+ "goal": "View signup",
11
+ "overall_conv_ratio": 0.09055118110236221,
12
+ "step_conv_ratio": 0.09055118110236221},
13
+ {"count": 10,
14
+ "goal": "View docs",
15
+ "overall_conv_ratio": 0.064679359580052493,
16
+ "step_conv_ratio": 0.7142857142857143}]},
17
+ "2010-05-31": {"analysis": {"completion": 0.12362030905077263,
18
+ "starting_amount": 906,
19
+ "steps": 2,
20
+ "worst": 2},
21
+ "steps": [{"count": 906,
22
+ "goal": "homepage",
23
+ "overall_conv_ratio": 1.0,
24
+ "step_conv_ratio": 1.0},
25
+ {"count": 112,
26
+ "goal": "View signup",
27
+ "overall_conv_ratio": 0.12362030905077263,
28
+ "step_conv_ratio": 0.12362030905077263}]}},
29
+ "meta": {"dates": ["2010-05-24", "2010-05-31"]}}
@@ -96,24 +96,25 @@ describe Mixpannenkoek::Base do
96
96
  end
97
97
  end
98
98
 
99
- describe '#to_hash' do
100
- subject { Mixpannenkoek::TestQuery.where(date: date_range).to_hash }
99
+ describe '#results' do
100
+ subject { Mixpannenkoek::TestQuery.where(date: date_range).results }
101
101
 
102
102
  let(:response_data) { JSON.parse(File.open("#{File.dirname(__FILE__)}/../../fixtures/funnel_response_data.json").read) }
103
103
  before { Mixpanel::Client.any_instance.stub(:request).and_return(response_data) }
104
104
 
105
- it 'returns the response data' do
106
- expect(subject).to eq response_data
105
+ it 'returns a Mixpannenkoek::Results::Base object' do
106
+ expect(subject).to be_a Mixpannenkoek::Results::Base
107
107
  end
108
108
  end
109
109
 
110
110
  describe '#method_missing' do
111
- before { Mixpannenkoek::Query.any_instance.stub(:mixpanel_request).and_return({ "funnel" => { "data" => { "2014-01-01" => [{ 'count' => '1' }, { 'count' => '4' }] } } }) }
112
- it 'delegates all calls to #to_hash.send(*args)' do
113
- expect(Mixpannenkoek::TestQuery.where(date: date_range).keys).to eq ['funnel']
111
+ before { Mixpanel::Client.any_instance.stub(:request).and_return({ "data" => { "2014-01-01" => [{ 'count' => '1' }, { 'count' => '4' }] } }) }
112
+ it 'delegates all calls to #results.send(*args)' do
113
+ expect(Mixpannenkoek::TestQuery.where(date: date_range).keys).to eq ['2014-01-01']
114
114
  end
115
+
115
116
  it 'delegates blocks' do
116
- expect(Mixpannenkoek::TestQuery.where(date: date_range)['funnel']['data'].values[0].map { |hash| hash['count'] }).to eq ['1','4']
117
+ expect(Mixpannenkoek::TestQuery.where(date: date_range).values[0].map { |hash| hash['count'] }).to eq ['1','4']
117
118
  end
118
119
  end
119
120
 
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mixpannenkoek::Results::Base do
4
+ let(:response_data) { JSON.parse(File.open("#{File.dirname(__FILE__)}/../../../fixtures/funnel_response_data.json").read) }
5
+
6
+ describe '#to_hash' do
7
+ subject { described_class.new(response_data).to_hash }
8
+ it 'returns the response data' do
9
+ expect(subject).to eq response_data
10
+ end
11
+ end
12
+
13
+ describe '#response_data' do
14
+ subject { described_class.new(response_data).response_data }
15
+ it 'returns the response data' do
16
+ expect(subject).to eq response_data
17
+ end
18
+ end
19
+
20
+ describe '#method_missing' do
21
+ subject { described_class.new(response_data) }
22
+ it 'delegates to to_hash' do
23
+ expect(subject.keys).to eq ['data', 'meta']
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mixpannenkoek::Results::Funnels do
4
+ let(:response_data) { JSON.parse(File.open("#{File.dirname(__FILE__)}/../../../fixtures/funnel_response_data.json").read) }
5
+
6
+ describe '#to_hash' do
7
+ subject { described_class.new(response_data).to_hash }
8
+ it 'returns the response data' do
9
+ expect(subject).to eq response_data['data']
10
+ end
11
+ end
12
+
13
+ describe '#response_data' do
14
+ subject { described_class.new(response_data).response_data }
15
+ it 'returns the response data' do
16
+ expect(subject).to eq response_data
17
+ end
18
+ end
19
+
20
+ describe '#method_missing' do
21
+ subject { described_class.new(response_data) }
22
+ it 'delegates to to_hash' do
23
+ expect(subject.keys).to eq ['2010-05-24', '2010-05-31']
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Mixpannenkoek::Results do
4
+ describe '.new' do
5
+ subject { Mixpannenkoek::Results.new(endpoint, {}) }
6
+
7
+ context 'any endpoint' do
8
+ let(:endpoint) { 'endpoint' }
9
+ it { expect(subject).to be_a Mixpannenkoek::Results::Base }
10
+ end
11
+
12
+ context 'funnels endoint' do
13
+ let(:endpoint) { 'funnels' }
14
+ it { expect(subject).to be_a Mixpannenkoek::Results::Funnels }
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixpannenkoek
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Kraan
@@ -92,6 +92,9 @@ files:
92
92
  - spec/lib/mixpannenkoek/base_spec.rb
93
93
  - spec/lib/mixpannenkoek/class_inheritable_attributes_spec.rb
94
94
  - spec/lib/mixpannenkoek/query_spec.rb
95
+ - spec/lib/mixpannenkoek/results/base_spec.rb
96
+ - spec/lib/mixpannenkoek/results/funnels_spec.rb
97
+ - spec/lib/mixpannenkoek/results_spec.rb
95
98
  - spec/lib/mixpannenkoek_spec.rb
96
99
  - spec/spec_helper.rb
97
100
  homepage: https://github.com/Springest/mixpannenkoek
@@ -123,5 +126,8 @@ test_files:
123
126
  - spec/lib/mixpannenkoek/base_spec.rb
124
127
  - spec/lib/mixpannenkoek/class_inheritable_attributes_spec.rb
125
128
  - spec/lib/mixpannenkoek/query_spec.rb
129
+ - spec/lib/mixpannenkoek/results/base_spec.rb
130
+ - spec/lib/mixpannenkoek/results/funnels_spec.rb
131
+ - spec/lib/mixpannenkoek/results_spec.rb
126
132
  - spec/lib/mixpannenkoek_spec.rb
127
133
  - spec/spec_helper.rb