kissmetrics 0.0.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,11 +4,11 @@ This is a very simple wrapper around the KISSmetrics HTTP API: http://support.ki
4
4
 
5
5
  == Usage
6
6
 
7
- kissmetrics = Kissmetrics.new('api-key-here')
8
- kissmetrics.identify('user_identity')
7
+ kissmetrics = Kissmetrics::HttpClient.new('api-key-here')
9
8
  kissmetrics.alias('old_identity', 'new_identity')
10
- kissmetrics.set({ 'some property' => 'some value', 'another property' => 'another value' })
11
- kissmetrics.record('action', { 'Property' => 'Value' })
9
+ kissmetrics.set('identity', { 'some property' => 'some value', 'another property' => 'another value' })
10
+ kissmetrics.record('identity', 'action', { 'Property' => 'Value' })
11
+
12
12
 
13
13
  == Contributing to kissmetrics
14
14
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 1.0.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kissmetrics}
8
- s.version = "0.0.2"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jason Morrison"]
12
- s.date = %q{2011-06-02}
12
+ s.date = %q{2011-06-12}
13
13
  s.description = %q{Use the KISSmetrics HTTP API to identify and alias users, track events, and set properties.}
14
14
  s.email = %q{jmorrison@thoughtbot.com}
15
15
  s.extra_rdoc_files = [
@@ -27,7 +27,8 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "kissmetrics.gemspec",
29
29
  "lib/kissmetrics.rb",
30
- "spec/kissmetrics_spec.rb",
30
+ "lib/kissmetrics/http_client.rb",
31
+ "spec/kissmetrics/http_client_spec.rb",
31
32
  "spec/spec_helper.rb"
32
33
  ]
33
34
  s.homepage = %q{http://github.com/jasonm/kissmetrics}
@@ -1,66 +1,2 @@
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
- QueryStringHash.new(query)
55
- end
56
-
57
- class QueryStringHash
58
- def initialize(hash)
59
- @hash = hash
60
- end
61
-
62
- def to_s
63
- @hash.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join('&')
64
- end
65
- end
1
+ module Kissmetrics
66
2
  end
@@ -0,0 +1,69 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'cgi'
4
+
5
+ module Kissmetrics
6
+ class HttpClient
7
+ attr_reader :api_key
8
+
9
+ def initialize(api_key)
10
+ @api_key = api_key
11
+ end
12
+
13
+ def record(identity, event, properties={})
14
+ request('/e', properties.merge({
15
+ '_p' => identity,
16
+ '_n' => event
17
+ }))
18
+ end
19
+
20
+ def alias(old_identity, new_identity)
21
+ request('/a', {
22
+ '_p' => old_identity,
23
+ '_n' => new_identity
24
+ })
25
+ end
26
+
27
+ def set(identity, properties)
28
+ request('/s', properties.merge({
29
+ '_p' => identity
30
+ }))
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
+ QueryStringHash.new(query)
55
+ end
56
+
57
+ class QueryStringHash
58
+ def initialize(hash)
59
+ @hash = hash
60
+ end
61
+
62
+ def to_s
63
+ @hash.collect do |key, value|
64
+ "#{key}=#{CGI.escape(value.to_s)}"
65
+ end.join('&')
66
+ end
67
+ end
68
+ end
69
+ end
@@ -1,61 +1,49 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
1
+ require 'spec_helper'
2
2
 
3
- describe Kissmetrics, "class" do
3
+ describe Kissmetrics::HttpClient, "class" do
4
4
  it "is constructed with an API key" do
5
- Kissmetrics.new("my-api-key").api_key.should == "my-api-key"
5
+ Kissmetrics::HttpClient.new("my-api-key").api_key.should == "my-api-key"
6
6
  end
7
7
  end
8
8
 
9
- describe Kissmetrics, "events" do
10
- subject { Kissmetrics.new("my-api-key") }
9
+ describe Kissmetrics::HttpClient, "events" do
10
+ subject { Kissmetrics::HttpClient.new("my-api-key") }
11
11
 
12
12
  before do
13
13
  stub_request(:get, %r{https://trk.kissmetrics.com/e}).to_return(:body => "")
14
14
  end
15
15
 
16
16
  it "records events without properties" do
17
- subject.record('Signed Up')
17
+ subject.record('identity', 'Signed Up')
18
18
  WebMock.should have_requested(:get, "https://trk.kissmetrics.com/e").with({
19
19
  :query => {
20
20
  :_k => 'my-api-key',
21
+ :_p => 'identity',
21
22
  :_n => 'Signed Up'
22
23
  }
23
24
  })
24
25
  end
25
26
 
26
27
  it "records events with properties" do
27
- subject.record('Signed Up', { 'Plan' => 'Medium', 'Duration' => 'Year' })
28
+ subject.record('identity', 'Signed Up', { 'Plan' => 'Medium', 'Duration' => 'Year' })
28
29
  WebMock.should have_requested(:get, "https://trk.kissmetrics.com/e").with({
29
30
  :query => {
30
31
  :_k => 'my-api-key',
32
+ :_p => 'identity',
31
33
  :_n => 'Signed Up',
32
34
  'Plan' => 'Medium',
33
35
  'Duration' => 'Year'
34
36
  }
35
37
  })
36
38
  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
39
  end
52
40
 
53
- describe Kissmetrics, "aliasing" do
41
+ describe Kissmetrics::HttpClient, "aliasing" do
54
42
  before do
55
43
  stub_request(:get, %r{https://trk.kissmetrics.com/a}).to_return(:body => "")
56
44
  end
57
45
 
58
- subject { Kissmetrics.new("my-api-key") }
46
+ subject { Kissmetrics::HttpClient.new("my-api-key") }
59
47
 
60
48
  it "aliases a person" do
61
49
  subject.alias('old_identity', 'new_identity')
@@ -70,31 +58,15 @@ describe Kissmetrics, "aliasing" do
70
58
  end
71
59
  end
72
60
 
73
- describe Kissmetrics, "setting properties" do
61
+ describe Kissmetrics::HttpClient, "setting properties" do
74
62
  before do
75
63
  stub_request(:get, %r{https://trk.kissmetrics.com/s}).to_return(:body => "")
76
64
  end
77
65
 
78
- subject { Kissmetrics.new("my-api-key") }
66
+ subject { Kissmetrics::HttpClient.new("my-api-key") }
79
67
 
80
68
  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({
69
+ subject.set('identity', {
98
70
  'Button color' => 'Blue',
99
71
  'Background color' => 'Gray'
100
72
  })
@@ -102,7 +74,7 @@ describe Kissmetrics, "setting properties" do
102
74
  WebMock.should have_requested(:get, "https://trk.kissmetrics.com/s").with({
103
75
  :query => {
104
76
  :_k => 'my-api-key',
105
- :_p => 'user@example.com',
77
+ :_p => 'identity',
106
78
  'Button color' => 'Blue',
107
79
  'Background color' => 'Gray'
108
80
  }
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'kissmetrics'
5
+ require 'kissmetrics/http_client'
5
6
  require 'webmock/rspec'
6
7
 
7
8
  # Requires supporting files with custom matchers and macros, etc,
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: kissmetrics
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jason Morrison
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-02 00:00:00 -04:00
13
+ date: 2011-06-12 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -99,7 +99,8 @@ files:
99
99
  - VERSION
100
100
  - kissmetrics.gemspec
101
101
  - lib/kissmetrics.rb
102
- - spec/kissmetrics_spec.rb
102
+ - lib/kissmetrics/http_client.rb
103
+ - spec/kissmetrics/http_client_spec.rb
103
104
  - spec/spec_helper.rb
104
105
  has_rdoc: true
105
106
  homepage: http://github.com/jasonm/kissmetrics
@@ -115,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
116
  requirements:
116
117
  - - ">="
117
118
  - !ruby/object:Gem::Version
118
- hash: -1757115897083586638
119
+ hash: 4373313552260173621
119
120
  segments:
120
121
  - 0
121
122
  version: "0"