delayed_kiss 0.0.1 → 0.1.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.
data/README.textile CHANGED
@@ -6,38 +6,44 @@ h2. Installation
6
6
 
7
7
  Include the gem in your gemfile:
8
8
 
9
- <pre>
10
- gem 'delayed_kiss'
11
- </pre>
9
+ <pre>gem 'delayed_kiss'</pre>
12
10
 
13
11
  Configure your API key:
14
- <pre>
15
- #in config/kiss_metrics.yml
16
- development:
17
- key: <yourkey>
12
+
13
+ h3. In Version 0.1.0
14
+
15
+ <pre> #in config/delayed_kiss.yml
16
+ development:
17
+ key: yourkey
18
+ whiny_config: true
18
19
  test:
19
- key: <yourkey>
20
- production:
21
- key: <yourkey>
20
+ key: yourkey
21
+ production:
22
+ key: yourkey
22
23
  </pre>
23
- Initialize the API key
24
- <pre>
24
+
25
+ h3. In Version 0.0.1
26
+
27
+ <pre> #in config/kiss_metrics.yml
28
+ development:
29
+ key: yourkey
30
+ test:
31
+ key: yourkey
32
+ production:
33
+ key: yourkey
34
+
25
35
  #in config/initializers
26
- KM_CONFIG = YAML::load(ERB.new(IO.read(File.join(Rails.root, "config/kissmetrics.yml"))).result)[Rails.env]
27
- if !KM_CONFIG.blank?
36
+ KM_CONFIG = YAML::load(ERB.new(IO.read(File.join(Rails.root, "config/kissmetrics.yml"))).result)[Rails.env]
37
+ if !KM_CONFIG.blank?
28
38
  DelayedKiss.configure do |config|
29
- config.key = KM_CONFIG['key']
30
- end
31
- end
32
- </pre>
39
+ config.key = KM_CONFIG['key']
40
+ end
41
+ end</pre>
33
42
 
34
43
  h2. Usage
35
44
 
36
- Start recording events anywhere in your application:
37
- <pre>
38
- DelayedKiss.alias(anonymous_user, user.km_id)
39
- DelayedKiss.record(user.km_id, 'signed up')
40
- </pre>
45
+ Start recording events anywhere in your application: <pre> DelayedKiss.alias(anonymous_user, user.km_id)
46
+ DelayedKiss.record(user.km_id, 'signed up')</pre>
41
47
 
42
48
  h2. Thanks
43
49
 
data/lib/delayed_kiss.rb CHANGED
@@ -1,15 +1,22 @@
1
1
  require "delayed_kiss/version"
2
+ require 'delayed_kiss/railtie' if defined?(Rails)
2
3
 
3
4
  module DelayedKiss
4
5
  mattr_accessor :key
5
6
  @@key = nil
6
7
 
8
+ mattr_accessor :whiny_config
9
+ @@whiny_config = false
10
+
11
+ mattr_accessor :config_file
12
+ @@config_file = "config/delayed_kiss.yml"
13
+
7
14
  def self.configure
8
15
  yield self
9
16
  end
10
17
 
11
18
  def self.record(id, event, query_params={})
12
- raise DelayedKiss::ConfigurationError if @@key.blank?
19
+ self.verify_configuration
13
20
  raise ArgumentError.new("id can't be blank") if id.blank?
14
21
  raise ArgumentError.new("event can't be blank") if event.blank?
15
22
 
@@ -19,11 +26,11 @@ module DelayedKiss
19
26
  '_t' => Time.now.to_i.to_s,
20
27
  '_k' => @@key
21
28
  })
22
- HTTParty.delay.get('https://trk.kissmetrics.com/e?' + query_params.to_param)
29
+ HTTParty.delay.get('https://trk.kissmetrics.com/e?' + query_params.to_param) unless @@key.blank?
23
30
  end
24
31
 
25
32
  def self.alias(alias_from, alias_to)
26
- raise DelayedKiss::ConfigurationError if @@key.blank?
33
+ self.verify_configuration
27
34
  raise ArgumentError.new("you must specify both a from a to value") if alias_from.blank? || alias_to.blank?
28
35
 
29
36
  query_params = {
@@ -32,11 +39,11 @@ module DelayedKiss
32
39
  '_t' => Time.now.to_i.to_s,
33
40
  '_k' => @@key
34
41
  }
35
- HTTParty.delay.get('https://trk.kissmetrics.com/a?' + query_params.to_param)
42
+ HTTParty.delay.get('https://trk.kissmetrics.com/a?' + query_params.to_param) unless @@key.blank?
36
43
  end
37
44
 
38
45
  def self.set(id, query_params)
39
- raise DelayedKiss::ConfigurationError if @@key.blank?
46
+ self.verify_configuration
40
47
  raise ArgumentError.new("id can't be blank") if !id || id.blank?
41
48
  return if query_params.blank? # don't do anything if we're not setting any values on the identity
42
49
 
@@ -45,7 +52,11 @@ module DelayedKiss
45
52
  '_t' => Time.now.to_i.to_s,
46
53
  '_k' => @@key
47
54
  })
48
- HTTParty.delay.get('https://trk.kissmetrics.com/s?' + query_params.to_param)
55
+ HTTParty.delay.get('https://trk.kissmetrics.com/s?' + query_params.to_param) unless @@key.blank?
56
+ end
57
+
58
+ def self.verify_configuration
59
+ raise DelayedKiss::ConfigurationError if @@whiny_config && @@key.blank?
49
60
  end
50
61
 
51
62
  class ConfigurationError < StandardError; end
@@ -0,0 +1,21 @@
1
+ module DelayedKiss
2
+ class Railtie < Rails::Railtie
3
+ initializer "delayed_kiss.load_configuration" do
4
+ env_config = nil
5
+ config_file = File.join(Rails.root, DelayedKiss.config_file)
6
+ if File.exists?(config_file)
7
+ config_from_yaml = YAML::load(ERB.new(IO.read(config_file)).result)
8
+ if !config_from_yaml.blank?
9
+ env_config = config_from_yaml[Rails.env]
10
+ end
11
+ else
12
+ Rails.logger.warn("DelayedKiss: Configuration file not found.")
13
+ end
14
+ if !env_config.blank?
15
+ DelayedKiss.configure do |config|
16
+ config.key = env_config['key']
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module DelayedKiss
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,15 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe DelayedKiss do
4
+ before(:each) do
5
+ DelayedKiss.cache_config
6
+ end
7
+
8
+ after(:each) do
9
+ DelayedKiss.reset_config
10
+ end
11
+
4
12
  describe :configure do
5
- before(:each) do
6
- DelayedKiss.cache_config
7
- end
8
-
9
- after(:each) do
10
- DelayedKiss.reset_config
11
- end
12
-
13
13
  it "should configure the key" do
14
14
  test_key = "youraikeyvalue"
15
15
  DelayedKiss.configure do |config|
@@ -31,7 +31,7 @@ describe DelayedKiss do
31
31
  expect { DelayedKiss.record(nil, "event") }.to raise_error(ArgumentError)
32
32
  end
33
33
 
34
- it "should rais an error without an event" do
34
+ it "should raise an error without an event" do
35
35
  expect { DelayedKiss.record("identity", nil) }.to raise_error(ArgumentError)
36
36
  end
37
37
 
@@ -40,11 +40,23 @@ describe DelayedKiss do
40
40
  DelayedKiss.record("identity", "event", {:type => "crazy"})
41
41
  end
42
42
 
43
- it "should raise an error if the key is not configured" do
44
- DelayedKiss.cache_config
43
+ it "should raise an error if the key is not configured and the whiny config is turned on" do
45
44
  DelayedKiss.key = nil
45
+ DelayedKiss.whiny_config = true
46
46
  expect { DelayedKiss.record("identity", "event") }.to raise_error(DelayedKiss::ConfigurationError)
47
- DelayedKiss.reset_config
47
+ end
48
+
49
+ it "should not raise an error if the key is not configured and the whiny config is turned off" do
50
+ DelayedKiss.whiny_config = false
51
+ expect { DelayedKiss.record("identity", "event") }.to_not raise_error(DelayedKiss::ConfigurationError)
52
+ end
53
+
54
+ it "should not send a request to the KISSmetrics API if the API key is blank and the whiny config is turned off" do
55
+ HTTParty.expects(:get).never
56
+
57
+ DelayedKiss.key = nil
58
+ DelayedKiss.whiny_config = false
59
+ DelayedKiss.record("identity", "event")
48
60
  end
49
61
  end
50
62
 
@@ -72,11 +84,23 @@ describe DelayedKiss do
72
84
  expect { DelayedKiss.alias("oldname", nil) }.to raise_error(ArgumentError)
73
85
  end
74
86
 
75
- it "should raise an error if the key is not configured" do
76
- DelayedKiss.cache_config
87
+ it "should raise an error if the key is not configured and the whiny config is turned on" do
77
88
  DelayedKiss.key = nil
78
- expect { DelayedKiss.record("identity", "event") }.to raise_error(DelayedKiss::ConfigurationError)
79
- DelayedKiss.reset_config
89
+ DelayedKiss.whiny_config = true
90
+ expect { DelayedKiss.alias("oldname", "newname") }.to raise_error(DelayedKiss::ConfigurationError)
91
+ end
92
+
93
+ it "should not raise an error if the key is not configured and the whiny config is turned off" do
94
+ DelayedKiss.whiny_config = false
95
+ expect { DelayedKiss.alias("oldname", "newname") }.to_not raise_error(DelayedKiss::ConfigurationError)
96
+ end
97
+
98
+ it "should not send a request to the KISSmetrics API if the API key is blank and the whiny config is turned off" do
99
+ HTTParty.expects(:get).never
100
+
101
+ DelayedKiss.key = nil
102
+ DelayedKiss.whiny_config = false
103
+ DelayedKiss.alias("oldname", "newname")
80
104
  end
81
105
  end
82
106
 
@@ -100,11 +124,23 @@ describe DelayedKiss do
100
124
  expect { DelayedKiss.set(nil, {:gener => :female}) }.to raise_error(ArgumentError)
101
125
  end
102
126
 
103
- it "should raise an error if the key is not configured" do
104
- DelayedKiss.cache_config
127
+ it "should raise an error if the key is not configured and the whiny config is turned on" do
105
128
  DelayedKiss.key = nil
106
- expect { DelayedKiss.record("identity", "event") }.to raise_error(DelayedKiss::ConfigurationError)
107
- DelayedKiss.reset_config
129
+ DelayedKiss.whiny_config = true
130
+ expect { DelayedKiss.set("identity", {:occupation => "Lab Rat"}) }.to raise_error(DelayedKiss::ConfigurationError)
131
+ end
132
+
133
+ it "should not raise an error if the key is not configured and the whiny config is turned off" do
134
+ DelayedKiss.whiny_config = false
135
+ expect { DelayedKiss.set("identity", {:age => "old"}) }.to_not raise_error(DelayedKiss::ConfigurationError)
136
+ end
137
+
138
+ it "should not send a request to the KISSmetrics API if the API key is blank and the whiny config is turned off" do
139
+ HTTParty.expects(:get).never
140
+
141
+ DelayedKiss.key = nil
142
+ DelayedKiss.whiny_config = false
143
+ DelayedKiss.set("identity", {:education => "college"})
108
144
  end
109
145
  end
110
146
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayed_kiss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-07 00:00:00.000000000 -05:00
12
+ date: 2011-11-15 00:00:00.000000000 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
17
- requirement: &2152316100 !ruby/object:Gem::Requirement
17
+ requirement: &2164268460 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2152316100
25
+ version_requirements: *2164268460
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: i18n
28
- requirement: &2152315680 !ruby/object:Gem::Requirement
28
+ requirement: &2164268040 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2152315680
36
+ version_requirements: *2164268040
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: httparty
39
- requirement: &2152315180 !ruby/object:Gem::Requirement
39
+ requirement: &2164267540 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.8.1
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2152315180
47
+ version_requirements: *2164267540
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: delayed_job
50
- requirement: &2152314680 !ruby/object:Gem::Requirement
50
+ requirement: &2164267040 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: 2.1.4
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *2152314680
58
+ version_requirements: *2164267040
59
59
  description: A simple wrapper for the KissMetrics API using Delayed Job
60
60
  email:
61
61
  - ddeyoung@authorsolutions.com
@@ -70,6 +70,7 @@ files:
70
70
  - Rakefile
71
71
  - delayed_kiss.gemspec
72
72
  - lib/delayed_kiss.rb
73
+ - lib/delayed_kiss/railtie.rb
73
74
  - lib/delayed_kiss/version.rb
74
75
  - spec/delayed_kiss_spec.rb
75
76
  - spec/spec_helper.rb