kissmetrics 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "yard", "~> 0.6.0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.6.2"
13
+ gem "rcov", ">= 0"
14
+ gem "webmock", "~> 1.6.2"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.6)
5
+ crack (0.1.8)
6
+ diff-lcs (1.1.2)
7
+ git (1.2.5)
8
+ jeweler (1.6.2)
9
+ bundler (~> 1.0)
10
+ git (>= 1.2.5)
11
+ rake
12
+ rake (0.9.1)
13
+ rcov (0.9.9)
14
+ rspec (2.3.0)
15
+ rspec-core (~> 2.3.0)
16
+ rspec-expectations (~> 2.3.0)
17
+ rspec-mocks (~> 2.3.0)
18
+ rspec-core (2.3.1)
19
+ rspec-expectations (2.3.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.3.0)
22
+ webmock (1.6.4)
23
+ addressable (~> 2.2, > 2.2.5)
24
+ crack (>= 0.1.7)
25
+ yard (0.6.8)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.0.0)
32
+ jeweler (~> 1.6.2)
33
+ rcov
34
+ rspec (~> 2.3.0)
35
+ webmock (~> 1.6.2)
36
+ yard (~> 0.6.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jason Morrison
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,26 @@
1
+ = kissmetrics
2
+
3
+ This is a very simple wrapper around the KISSmetrics HTTP API: http://support.kissmetrics.com/apis/specifications
4
+
5
+ == Usage
6
+
7
+ kissmetrics = Kissmetrics.new('api-key-here')
8
+ kissmetrics.identify('user_identity')
9
+ kissmetrics.alias('old_identity', 'new_identity')
10
+ kissmetrics.set({ 'some property' => 'some value', 'another property' => 'another value' })
11
+ kissmetrics.record('action', { 'Property' => 'Value' })
12
+
13
+ == Contributing to kissmetrics
14
+
15
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
16
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
17
+ * Fork the project
18
+ * Start a feature/bugfix branch
19
+ * Commit and push until you are happy with your contribution
20
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
21
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
22
+
23
+ == Copyright
24
+
25
+ Copyright (c) 2011 Jason Morrison. See LICENSE.txt for
26
+ further details.
data/Rakefile ADDED
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "kissmetrics"
18
+ gem.homepage = "http://github.com/jasonm/kissmetrics"
19
+ gem.license = "MIT"
20
+ gem.summary = "A simple, clean wrapper around the KISSmetrics HTTP API"
21
+ gem.description = "Use the KISSmetrics HTTP API to identify and alias users, track events, and set properties."
22
+ gem.email = "jmorrison@thoughtbot.com"
23
+ gem.authors = ["Jason Morrison"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'yard'
42
+ YARD::Rake::YardocTask.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{kissmetrics}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jason Morrison"]
12
+ s.date = %q{2011-06-02}
13
+ s.description = %q{Use the KISSmetrics HTTP API to identify and alias users, track events, and set properties.}
14
+ s.email = %q{jmorrison@thoughtbot.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "kissmetrics.gemspec",
29
+ "lib/kissmetrics.rb",
30
+ "spec/kissmetrics_spec.rb",
31
+ "spec/spec_helper.rb"
32
+ ]
33
+ s.homepage = %q{http://github.com/jasonm/kissmetrics}
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = %q{1.6.2}
37
+ s.summary = %q{A simple, clean wrapper around the KISSmetrics HTTP API}
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
44
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
45
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
46
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
47
+ s.add_development_dependency(%q<rcov>, [">= 0"])
48
+ s.add_development_dependency(%q<webmock>, ["~> 1.6.2"])
49
+ else
50
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
51
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
54
+ s.add_dependency(%q<rcov>, [">= 0"])
55
+ s.add_dependency(%q<webmock>, ["~> 1.6.2"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
59
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
60
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
61
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
62
+ s.add_dependency(%q<rcov>, [">= 0"])
63
+ s.add_dependency(%q<webmock>, ["~> 1.6.2"])
64
+ end
65
+ end
66
+
@@ -0,0 +1,60 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'cgi'
4
+
5
+ class Kissmetrics
6
+ attr_reader :api_key
7
+
8
+ def initialize(api_key)
9
+ @api_key = api_key
10
+ end
11
+
12
+ def identify(identity)
13
+ @identity = identity
14
+ end
15
+
16
+ def record(event, properties={})
17
+ request('/e', properties.merge({
18
+ '_n' => event
19
+ }))
20
+ end
21
+
22
+ def alias(old_identity, new_identity)
23
+ request('/a', {
24
+ '_p' => old_identity,
25
+ '_n' => new_identity
26
+ })
27
+ end
28
+
29
+ def set(properties)
30
+ request('/s', properties)
31
+ end
32
+
33
+ private
34
+
35
+ def host
36
+ 'trk.kissmetrics.com'
37
+ end
38
+
39
+ def port
40
+ 443
41
+ end
42
+
43
+ def request(path, params)
44
+ http = Net::HTTP.new(host, port)
45
+ http.use_ssl = true
46
+ http.get("#{path}?#{query_string(params)}")
47
+ end
48
+
49
+ def query_string(params)
50
+ query = params.clone
51
+ query['_k'] = @api_key
52
+ query['_p'] = @identity if @identity
53
+
54
+ hash_to_query_string(query)
55
+ end
56
+
57
+ def hash_to_query_string(hash)
58
+ hash.collect { |k,v| "#{k}=#{CGI.escape(v.to_s)}" }.join('&')
59
+ end
60
+ end
@@ -0,0 +1,111 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Kissmetrics, "class" do
4
+ it "is constructed with an API key" do
5
+ Kissmetrics.new("my-api-key").api_key.should == "my-api-key"
6
+ end
7
+ end
8
+
9
+ describe Kissmetrics, "events" do
10
+ subject { Kissmetrics.new("my-api-key") }
11
+
12
+ before do
13
+ stub_request(:get, %r{https://trk.kissmetrics.com/e}).to_return(:body => "")
14
+ end
15
+
16
+ it "records events without properties" do
17
+ subject.record('Signed Up')
18
+ WebMock.should have_requested(:get, "https://trk.kissmetrics.com/e").with({
19
+ :query => {
20
+ :_k => 'my-api-key',
21
+ :_n => 'Signed Up'
22
+ }
23
+ })
24
+ end
25
+
26
+ it "records events with properties" do
27
+ subject.record('Signed Up', { 'Plan' => 'Medium', 'Duration' => 'Year' })
28
+ WebMock.should have_requested(:get, "https://trk.kissmetrics.com/e").with({
29
+ :query => {
30
+ :_k => 'my-api-key',
31
+ :_n => 'Signed Up',
32
+ 'Plan' => 'Medium',
33
+ 'Duration' => 'Year'
34
+ }
35
+ })
36
+ end
37
+
38
+ it "includes identity when recording an event" do
39
+ subject.identify('user@example.com')
40
+ subject.record('Signed Up', { 'Plan' => 'Medium', 'Duration' => 'Year' })
41
+ WebMock.should have_requested(:get, "https://trk.kissmetrics.com/e").with({
42
+ :query => {
43
+ :_k => 'my-api-key',
44
+ :_n => 'Signed Up',
45
+ :_p => 'user@example.com',
46
+ 'Plan' => 'Medium',
47
+ 'Duration' => 'Year'
48
+ }
49
+ })
50
+ end
51
+ end
52
+
53
+ describe Kissmetrics, "aliasing" do
54
+ before do
55
+ stub_request(:get, %r{https://trk.kissmetrics.com/a}).to_return(:body => "")
56
+ end
57
+
58
+ subject { Kissmetrics.new("my-api-key") }
59
+
60
+ it "aliases a person" do
61
+ subject.alias('old_identity', 'new_identity')
62
+
63
+ WebMock.should have_requested(:get, "https://trk.kissmetrics.com/a").with({
64
+ :query => {
65
+ :_k => 'my-api-key',
66
+ :_p => 'old_identity',
67
+ :_n => 'new_identity'
68
+ }
69
+ })
70
+ end
71
+ end
72
+
73
+ describe Kissmetrics, "setting properties" do
74
+ before do
75
+ stub_request(:get, %r{https://trk.kissmetrics.com/s}).to_return(:body => "")
76
+ end
77
+
78
+ subject { Kissmetrics.new("my-api-key") }
79
+
80
+ it "sets properties when unidentified" do
81
+ subject.set({
82
+ 'Button color' => 'Blue',
83
+ 'Background color' => 'Gray'
84
+ })
85
+
86
+ WebMock.should have_requested(:get, "https://trk.kissmetrics.com/s").with({
87
+ :query => {
88
+ :_k => 'my-api-key',
89
+ 'Button color' => 'Blue',
90
+ 'Background color' => 'Gray'
91
+ }
92
+ })
93
+ end
94
+
95
+ it "sets properties when identified" do
96
+ subject.identify('user@example.com')
97
+ subject.set({
98
+ 'Button color' => 'Blue',
99
+ 'Background color' => 'Gray'
100
+ })
101
+
102
+ WebMock.should have_requested(:get, "https://trk.kissmetrics.com/s").with({
103
+ :query => {
104
+ :_k => 'my-api-key',
105
+ :_p => 'user@example.com',
106
+ 'Button color' => 'Blue',
107
+ 'Background color' => 'Gray'
108
+ }
109
+ })
110
+ end
111
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'kissmetrics'
5
+ require 'webmock/rspec'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ config.before do
13
+ WebMock.disable_net_connect!
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kissmetrics
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Jason Morrison
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-02 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rspec
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.0
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: yard
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: 0.6.0
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: jeweler
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: 1.6.2
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: rcov
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: webmock
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 1.6.2
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ description: Use the KISSmetrics HTTP API to identify and alias users, track events, and set properties.
83
+ email: jmorrison@thoughtbot.com
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ files:
92
+ - .document
93
+ - .rspec
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.rdoc
98
+ - Rakefile
99
+ - VERSION
100
+ - kissmetrics.gemspec
101
+ - lib/kissmetrics.rb
102
+ - spec/kissmetrics_spec.rb
103
+ - spec/spec_helper.rb
104
+ has_rdoc: true
105
+ homepage: http://github.com/jasonm/kissmetrics
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 970554408361776796
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: "0"
128
+ requirements: []
129
+
130
+ rubyforge_project:
131
+ rubygems_version: 1.6.2
132
+ signing_key:
133
+ specification_version: 3
134
+ summary: A simple, clean wrapper around the KISSmetrics HTTP API
135
+ test_files: []
136
+