pushpop-keen 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+
4
+ rvm:
5
+ - 2.1.1
6
+
7
+ script:
8
+ - bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pushpop'
4
+ gem 'keen'
5
+
6
+ group :development, :test do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'mail'
10
+ gem 'twilio-ruby'
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.1.1)
5
+ i18n (~> 0.6, >= 0.6.9)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.1)
9
+ tzinfo (~> 1.1)
10
+ addressable (2.3.6)
11
+ builder (3.2.2)
12
+ clockwork (0.7.5)
13
+ activesupport
14
+ tzinfo
15
+ diff-lcs (1.2.5)
16
+ i18n (0.6.9)
17
+ json (1.8.1)
18
+ jwt (1.0.0)
19
+ keen (0.8.2)
20
+ addressable (~> 2.3.5)
21
+ multi_json (~> 1.3)
22
+ mail (2.6.1)
23
+ mime-types (>= 1.16, < 3)
24
+ mime-types (2.3)
25
+ minitest (5.3.4)
26
+ multi_json (1.10.1)
27
+ pushpop (0.1.0)
28
+ clockwork
29
+ keen
30
+ rake (10.3.2)
31
+ rspec (3.0.0)
32
+ rspec-core (~> 3.0.0)
33
+ rspec-expectations (~> 3.0.0)
34
+ rspec-mocks (~> 3.0.0)
35
+ rspec-core (3.0.1)
36
+ rspec-support (~> 3.0.0)
37
+ rspec-expectations (3.0.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.0.0)
40
+ rspec-mocks (3.0.1)
41
+ rspec-support (~> 3.0.0)
42
+ rspec-support (3.0.0)
43
+ thread_safe (0.3.4)
44
+ twilio-ruby (3.11.5)
45
+ builder (>= 2.1.2)
46
+ jwt (>= 0.1.2)
47
+ multi_json (>= 1.3.0)
48
+ tzinfo (1.2.1)
49
+ thread_safe (~> 0.1)
50
+
51
+ PLATFORMS
52
+ ruby
53
+
54
+ DEPENDENCIES
55
+ keen
56
+ mail
57
+ pushpop
58
+ rake
59
+ rspec
60
+ twilio-ruby
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Author Josh Dzielak
2
+ Copyright (c) 2014 Keen Labs
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ ## pushpop-keen
2
+
3
+ Keen IO plugin for [Pushpop](https://github.com/pushpop-project/pushpop).
4
+
5
+ ### Installation
6
+
7
+ Add `pushpop-keen` to your Gemfile:
8
+
9
+ ``` ruby
10
+ gem 'pushpop-keen'
11
+ ```
12
+
13
+ or install it as a gem:
14
+
15
+ ``` shell
16
+ $ gem install pushpop-keen
17
+ ```
18
+
19
+ ### Usage
20
+
21
+ The `keen` plugin gives you a DSL to specify Keen query parameters. Those query parameters are used to query data using the [keen-gem](https://github.com/keenlabs/keen-gem).
22
+
23
+ Here's an example that shows many of the options you can specify:
24
+
25
+ ``` ruby
26
+ job 'average response time for successful requests last month' do
27
+
28
+ keen do
29
+ event_collection 'checks'
30
+ analysis_type 'average'
31
+ target_property 'request.duration'
32
+ group_by 'check.name'
33
+ interval 'daily'
34
+ timeframe 'last_month',
35
+ filters [{ property_name: "response.successful",
36
+ operator: "eq",
37
+ property_value: true }]
38
+ end
39
+
40
+ end
41
+ ```
42
+
43
+ A `steps` method is also supported for [funnels](https://keen.io/docs/data-analysis/funnels/),
44
+ as well as `analyses` for doing a [multi-analysis](https://keen.io/docs/data-analysis/multi-analysis/).
45
+
46
+ The `keen` plugin requires that the following environment variables are set:
47
+
48
+ + `KEEN_PROJECT_ID`
49
+ + `KEEN_READ_KEY`
50
+
51
+
52
+ ### Contributing
53
+
54
+ Code and documentation issues and pull requests are welcome.
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ $stdout.sync = true
2
+
3
+ $: << File.join(File.dirname(__FILE__), './lib')
4
+
5
+ begin
6
+ require 'rspec/core/rake_task'
7
+ desc 'Run Rspec unit tests'
8
+ RSpec::Core::RakeTask.new(:spec) do |t|
9
+ t.pattern = 'spec/**/*_spec.rb'
10
+ end
11
+
12
+ task default: :spec
13
+ rescue LoadError
14
+ end
15
+
16
+
@@ -0,0 +1,80 @@
1
+ require 'pushpop'
2
+ require 'keen'
3
+
4
+ module Pushpop
5
+
6
+ class Keen < Step
7
+
8
+ PLUGIN_NAME = 'keen'
9
+
10
+ Pushpop::Job.register_plugin(Keen::PLUGIN_NAME, Keen)
11
+
12
+ attr_accessor :_event_collection
13
+ attr_accessor :_analysis_type
14
+ attr_accessor :_timeframe
15
+ attr_accessor :_target_property
16
+ attr_accessor :_group_by
17
+ attr_accessor :_interval
18
+ attr_accessor :_filters
19
+ attr_accessor :_steps
20
+ attr_accessor :_analyses
21
+
22
+ def run(last_response=nil, step_responses=nil)
23
+ self.configure(last_response, step_responses)
24
+ ::Keen.send(self._analysis_type, self._event_collection, self.to_analysis_options)
25
+ end
26
+
27
+ def configure(last_response=nil, step_responses=nil)
28
+ self.instance_exec(last_response, step_responses, &block)
29
+ end
30
+
31
+ def to_analysis_options
32
+ { timeframe: self._timeframe,
33
+ target_property: self._target_property,
34
+ group_by: self._group_by,
35
+ interval: self._interval,
36
+ filters: self._filters,
37
+ analyses: self._analyses,
38
+ steps: self._steps
39
+ }.delete_if { |_, v| v.nil? }
40
+ end
41
+
42
+ def event_collection(event_collection)
43
+ self._event_collection = event_collection
44
+ end
45
+
46
+ def analysis_type(analysis_type)
47
+ self._analysis_type = analysis_type
48
+ end
49
+
50
+ def timeframe(timeframe)
51
+ self._timeframe = timeframe
52
+ end
53
+
54
+ def target_property(target_property)
55
+ self._target_property = target_property
56
+ end
57
+
58
+ def group_by(group_by)
59
+ self._group_by = group_by
60
+ end
61
+
62
+ def interval(interval)
63
+ self._interval = interval
64
+ end
65
+
66
+ def filters(filters)
67
+ self._filters = filters
68
+ end
69
+
70
+ def steps(steps)
71
+ self._steps = steps
72
+ end
73
+
74
+ def analyses(analyses)
75
+ self._analyses = analyses
76
+ end
77
+
78
+ end
79
+
80
+ end
@@ -0,0 +1,5 @@
1
+ module Pushpop
2
+ class Keen
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'pushpop-keen/version'
4
+
5
+ Gem::Specification.new do |s|
6
+
7
+ s.name = "pushpop-keen"
8
+ s.version = Pushpop::Keen::VERSION
9
+ s.authors = ["Josh Dzielak"]
10
+ s.email = "josh@keen.io"
11
+ s.homepage = "https://github.com/pushpop-project/pushpop-keen"
12
+ s.summary = "Pushpop Keen IO plugin for querying and recording events"
13
+
14
+ s.add_dependency "pushpop"
15
+ s.add_dependency "keen"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
22
+
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe Pushpop::Keen do
4
+
5
+ describe '#configure' do
6
+
7
+ it 'should set various params' do
8
+
9
+ step = Pushpop::Keen.new do
10
+ event_collection 'pageviews'
11
+ analysis_type 'count'
12
+ timeframe 'last_3_days'
13
+ target_property 'trinkets'
14
+ group_by 'referer'
15
+ interval 'hourly'
16
+ filters [{ property_value: 'referer',
17
+ operator: 'ne',
18
+ property_value: 'yahoo.com' }]
19
+ steps [{ event_collection: 'pageviews',
20
+ actor_property: 'user.id' }]
21
+ analyses [{ analysis_type: 'count' }]
22
+ end
23
+
24
+ step.configure
25
+
26
+ step._event_collection.should == 'pageviews'
27
+ step._analysis_type.should == 'count'
28
+ step._timeframe.should == 'last_3_days'
29
+ step._group_by.should == 'referer'
30
+ step._interval.should == 'hourly'
31
+ step._steps.should == [{
32
+ event_collection: 'pageviews',
33
+ actor_property: 'user.id'
34
+ }]
35
+ step._analyses.should == [{ analysis_type: 'count' }]
36
+ end
37
+
38
+ end
39
+
40
+ describe '#run' do
41
+ it 'should run the query based on the analysis type' do
42
+ Keen.stub(:count).with('pageviews', {
43
+ timeframe: 'last_3_days'
44
+ }).and_return(365)
45
+
46
+ step = Pushpop::Keen.new('one') do
47
+ event_collection 'pageviews'
48
+ analysis_type 'count'
49
+ timeframe 'last_3_days'
50
+ end
51
+ response = step.run
52
+ response.should == 365
53
+ end
54
+ end
55
+
56
+ describe '#to_analysis_options' do
57
+ it 'should include various options' do
58
+ step = Pushpop::Keen.new('one') do end
59
+ step._timeframe = 'last_4_days'
60
+ step._group_by = 'referer'
61
+ step._target_property = 'trinkets'
62
+ step._interval = 'hourly'
63
+ step._filters = [{ property_value: 'referer',
64
+ operator: 'ne',
65
+ property_value: 'yahoo.com' }]
66
+ step._steps = [{ event_collection: 'pageviews',
67
+ actor_property: 'user.id' }]
68
+ step._analyses = [{ analysis_type: 'count' }]
69
+ step.to_analysis_options.should == {
70
+ timeframe: 'last_4_days',
71
+ target_property: 'trinkets',
72
+ group_by: 'referer',
73
+ interval: 'hourly',
74
+ filters: [{ property_value: 'referer',
75
+ operator: 'ne',
76
+ property_value: 'yahoo.com' }],
77
+ steps: [{ event_collection: 'pageviews',
78
+ actor_property: 'user.id' }],
79
+ analyses: [{ analysis_type: 'count' }]
80
+ }
81
+ end
82
+
83
+ it 'should not include nils' do
84
+ step = Pushpop::Keen.new('one') do end
85
+ step.to_analysis_options.should == {}
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,11 @@
1
+ $: << File.join(File.dirname(__FILE__), '../lib')
2
+
3
+ require 'pushpop'
4
+ require 'pushpop-keen'
5
+
6
+ RSpec.configure do |config|
7
+ config.before :each do
8
+ Pushpop.jobs.clear
9
+ end
10
+ end
11
+
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pushpop-keen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Josh Dzielak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-06-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pushpop
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: keen
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description:
47
+ email: josh@keen.io
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .travis.yml
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - lib/pushpop-keen.rb
59
+ - lib/pushpop-keen/version.rb
60
+ - pushpop-keen.gemspec
61
+ - spec/pushpop-keen_spec.rb
62
+ - spec/spec_helper.rb
63
+ homepage: https://github.com/pushpop-project/pushpop-keen
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.23
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Pushpop Keen IO plugin for querying and recording events
87
+ test_files:
88
+ - spec/pushpop-keen_spec.rb
89
+ - spec/spec_helper.rb