km_sidekiq 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/km-sidekiq.gemspec +21 -0
- data/lib/km_sidekiq.rb +24 -0
- data/lib/km_sidekiq/alias_job.rb +13 -0
- data/lib/km_sidekiq/api_client.rb +79 -0
- data/lib/km_sidekiq/configuration.rb +15 -0
- data/lib/km_sidekiq/record_job.rb +13 -0
- data/lib/km_sidekiq/set_job.rb +13 -0
- data/lib/km_sidekiq/version.rb +3 -0
- data/spec/lib/km_sidekiq/alias_job_spec.rb +31 -0
- data/spec/lib/km_sidekiq/record_job_spec.rb +49 -0
- data/spec/lib/km_sidekiq/set_job_spec.rb +31 -0
- data/spec/lib/km_sidekiq/sidekiq_spec.rb +75 -0
- data/spec/lib/km_sidekiq_spec.rb +48 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cc62e3585e795197209d19213990ca1c1031d34b
|
4
|
+
data.tar.gz: 13d5680558d8cff48297496c9a429951e861d506
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ab37eb36a61bf1be20a9155871aae9f011c56a51da39f2109ddb44cbfd3f6442e13a9eaae8230a6ba2c7900e7ead65cd4dba8ef6f2b7c11db7f2dc06ce183294
|
7
|
+
data.tar.gz: 1c9eaa7d92b3d1e20f53f51abcf8d292aff01491ac90f53f7796bd6827c1acbaa47160074634e0acc16b5ba0c6dabffae52680b38c430e63935ffafe74023373
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Luke Melia
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# KmSidekiq
|
2
|
+
|
3
|
+
An interface for interacting with the KISSmetrics API via Sidekiq. Keeps all direct interactions with the KISSMetrics API out of your requests.
|
4
|
+
|
5
|
+
[![Build Status](https://secure.travis-ci.org/yapplabs/km_sidekiq.png)](http://travis-ci.org/yapplabs/km_sidekiq)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'km_sidekiq'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install km_sidekiq
|
20
|
+
|
21
|
+
Configure your API key:
|
22
|
+
|
23
|
+
KmSidekiq.configure do |config|
|
24
|
+
config.key = '<YOUR-KISSMETRICS-API-KEY>'
|
25
|
+
end
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
KmSidekiq.alias(anonymous_id, user.id)
|
30
|
+
KmSidekiq.record(user.id, 'signed_up', { :source => 'contest' })
|
31
|
+
KmSidekiq.set(user.id, { :gender => 'F' })
|
32
|
+
|
33
|
+
## Running specs
|
34
|
+
|
35
|
+
$ bundle exec rspec spec/
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
1. Fork it
|
40
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
41
|
+
3. Commit your changes (`git commit -am 'Added some feature'`); don't forget the specs!
|
42
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
43
|
+
5. Create new Pull Request
|
44
|
+
|
45
|
+
## Credits
|
46
|
+
|
47
|
+
KmResque originally written by Luke Melia. Adapted by Ray Cohen and Stefan Penner for Sidekiq. Inspiration from delayed_kiss and km-delay.
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
km_sidekiq is available under the terms of the MIT License http://www.opensource.org/licenses/mit-license.php
|
data/Rakefile
ADDED
data/km-sidekiq.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/km_sidekiq/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Luke Melia"]
|
6
|
+
gem.email = ["luke@lukemelia.com"]
|
7
|
+
gem.description = %q{Interact with the KISSMetrics API via Sidekiq}
|
8
|
+
gem.summary = %q{Interact with the KISSMetrics API via Sidekiq}
|
9
|
+
gem.homepage = "https://github.com/yapplabs/km_sidekiq"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "km_sidekiq"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = KmSidekiq::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'sidekiq', '>= 2.0.0'
|
19
|
+
gem.add_development_dependency 'rspec-sidekiq'
|
20
|
+
gem.add_development_dependency 'webmock'
|
21
|
+
end
|
data/lib/km_sidekiq.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "km_sidekiq/version"
|
2
|
+
require "km_sidekiq/configuration"
|
3
|
+
require "km_sidekiq/alias_job"
|
4
|
+
require "km_sidekiq/set_job"
|
5
|
+
require "km_sidekiq/record_job"
|
6
|
+
|
7
|
+
class KmSidekiq
|
8
|
+
class Error < RuntimeError; end
|
9
|
+
def self.configure(&block)
|
10
|
+
yield configuration
|
11
|
+
end
|
12
|
+
def self.configuration
|
13
|
+
@configuration ||= Configuration.new
|
14
|
+
end
|
15
|
+
def self.alias(identifier1, identifier2, timestamp=Time.now.to_i)
|
16
|
+
Sidekiq::Client.enqueue(AliasJob, identifier1, identifier2, timestamp)
|
17
|
+
end
|
18
|
+
def self.set(identifier, properties, timestamp=Time.now.to_i)
|
19
|
+
Sidekiq::Client.enqueue(SetJob, identifier, properties, timestamp)
|
20
|
+
end
|
21
|
+
def self.record(identifier, eventName, properties, timestamp=Time.now.to_i)
|
22
|
+
Sidekiq::Client.enqueue(RecordJob, identifier, eventName, properties, timestamp)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'km_sidekiq/api_client'
|
2
|
+
require 'sidekiq'
|
3
|
+
|
4
|
+
class KmSidekiq
|
5
|
+
class AliasJob
|
6
|
+
include Sidekiq::Worker
|
7
|
+
sidekiq_options :queue => :km
|
8
|
+
|
9
|
+
def perform(identifier1, identifier2, timestamp)
|
10
|
+
ApiClient.new.alias(identifier1, identifier2, timestamp.to_i)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'km_sidekiq'
|
2
|
+
|
3
|
+
class KmSidekiq
|
4
|
+
class ApiClient
|
5
|
+
def alias(identifier1, identifier2, timestamp)
|
6
|
+
hit('a', { '_n' => identifier2,
|
7
|
+
'_p' => identifier1,
|
8
|
+
'_t' => timestamp
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
def record(identifier, event_name, properties, timestamp)
|
13
|
+
hit('e', { '_p' => identifier,
|
14
|
+
'_n' => event_name,
|
15
|
+
'_t' => timestamp
|
16
|
+
}.merge(properties || {}))
|
17
|
+
end
|
18
|
+
|
19
|
+
def set(identifier, properties, timestamp)
|
20
|
+
hit('s', { '_p' => identifier,
|
21
|
+
'_t' => timestamp
|
22
|
+
}.merge(properties))
|
23
|
+
end
|
24
|
+
|
25
|
+
def api_key
|
26
|
+
@api_key ||= KmSidekiq.configuration.key
|
27
|
+
end
|
28
|
+
|
29
|
+
def host
|
30
|
+
@host ||= KmSidekiq.configuration.host
|
31
|
+
end
|
32
|
+
|
33
|
+
def port
|
34
|
+
@port ||= KmSidekiq.configuration.port
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def hit(type, data)
|
40
|
+
unless data['_p']
|
41
|
+
raise Error.new("Can't hit the API without an identity")
|
42
|
+
end
|
43
|
+
|
44
|
+
data['_k'] = api_key
|
45
|
+
unless data['_k']
|
46
|
+
raise Error.new("Can't hit the API without an API Key")
|
47
|
+
end
|
48
|
+
|
49
|
+
if data['_t']
|
50
|
+
data['_d'] = 1
|
51
|
+
unless validate_timestamp(data['_t'])
|
52
|
+
raise Error.new("Timestamp #{data['_t']} is invalid")
|
53
|
+
end
|
54
|
+
else
|
55
|
+
data['_t'] = Time.now.to_i
|
56
|
+
end
|
57
|
+
|
58
|
+
unsafe = Regexp.new("[^#{URI::REGEXP::PATTERN::UNRESERVED}]", false, 'N')
|
59
|
+
|
60
|
+
query_parts = []
|
61
|
+
query = ''
|
62
|
+
data.inject(query) do |query, key_val|
|
63
|
+
query_parts << key_val.collect { |i| URI.escape(i.to_s, unsafe) }.join('=')
|
64
|
+
end
|
65
|
+
query = '/' + type + '?' + query_parts.join('&')
|
66
|
+
proxy = URI.parse(ENV['http_proxy'] || ENV['HTTP_PROXY'] || '')
|
67
|
+
res = Net::HTTP::Proxy(proxy.host, proxy.port, proxy.user, proxy.password).start(host, port) do |http|
|
68
|
+
http.get(query)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
SECONDS_IN_ONE_HUNDRED_YEARS = 60 * 60 * 24 * 365 * 100
|
73
|
+
|
74
|
+
def validate_timestamp(timestamp)
|
75
|
+
timestamp = timestamp.to_i
|
76
|
+
(timestamp > 0) && (timestamp < (Time.now.to_i + SECONDS_IN_ONE_HUNDRED_YEARS))
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'km_sidekiq/api_client'
|
2
|
+
require 'sidekiq'
|
3
|
+
|
4
|
+
class KmSidekiq
|
5
|
+
class RecordJob
|
6
|
+
include Sidekiq::Worker
|
7
|
+
sidekiq_options :queue => :km
|
8
|
+
|
9
|
+
def perform(identifier, event_name, properties, timestamp)
|
10
|
+
ApiClient.new.record(identifier, event_name, properties, timestamp.to_i)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'km_sidekiq/api_client'
|
2
|
+
require 'sidekiq'
|
3
|
+
|
4
|
+
class KmSidekiq
|
5
|
+
class SetJob
|
6
|
+
include Sidekiq::Worker
|
7
|
+
sidekiq_options :queue => :km
|
8
|
+
|
9
|
+
def perform(identifier, properties, timestamp)
|
10
|
+
ApiClient.new.set(identifier, properties, timestamp.to_i)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.push File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'webmock/rspec'
|
3
|
+
require 'km_sidekiq/alias_job'
|
4
|
+
|
5
|
+
describe "KmSidekiq::AliasJob" do
|
6
|
+
before do
|
7
|
+
stub_request(:any, %r{http://trk.kissmetrics.com.*})
|
8
|
+
KmSidekiq.configure do |config|
|
9
|
+
config.key = "abc123"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
describe "perform" do
|
13
|
+
subject do
|
14
|
+
KmSidekiq::AliasJob.new
|
15
|
+
end
|
16
|
+
it "should hit the KM API" do
|
17
|
+
timestamp = Time.now.to_i
|
18
|
+
subject.perform("identifier1", "identifier2", timestamp)
|
19
|
+
expected_api_hit = "http://trk.kissmetrics.com/a?_d=1&_k=abc123&_n=identifier2&_p=identifier1&_t=#{timestamp}"
|
20
|
+
WebMock.should have_requested(:get, expected_api_hit)
|
21
|
+
end
|
22
|
+
it "should round off any decimal in timestamp" do
|
23
|
+
now = Time.now
|
24
|
+
timestamp_float = now.to_f
|
25
|
+
timeStamp_int = now.to_i
|
26
|
+
subject.perform("identifier1", "identifier2", timestamp_float)
|
27
|
+
expected_api_hit = "http://trk.kissmetrics.com/a?_d=1&_k=abc123&_n=identifier2&_p=identifier1&_t=#{timeStamp_int}"
|
28
|
+
WebMock.should have_requested(:get, expected_api_hit)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
$:.push File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'webmock/rspec'
|
3
|
+
require 'km_sidekiq/record_job'
|
4
|
+
|
5
|
+
describe "KmSidekiq::RecordJob" do
|
6
|
+
before do
|
7
|
+
stub_request(:any, %r{http://trk.kissmetrics.com.*})
|
8
|
+
KmSidekiq.configure do |config|
|
9
|
+
config.key = "abc123"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
describe "perform" do
|
13
|
+
subject do
|
14
|
+
KmSidekiq::RecordJob.new
|
15
|
+
end
|
16
|
+
it "should hit the KM API" do
|
17
|
+
timestamp = Time.now.to_i
|
18
|
+
subject.perform("identifier", "eventName", { :foo => 'bar', :baz => 'bay'}, timestamp)
|
19
|
+
expected_api_hit = "http://trk.kissmetrics.com/e?_d=1&_k=abc123&_n=eventName&_p=identifier&_t=#{timestamp}&baz=bay&foo=bar"
|
20
|
+
WebMock.should have_requested(:get, expected_api_hit)
|
21
|
+
end
|
22
|
+
it "should succceed with no properties" do
|
23
|
+
timestamp = Time.now.to_i
|
24
|
+
subject.perform("identifier", "eventName", nil, timestamp)
|
25
|
+
expected_api_hit = "http://trk.kissmetrics.com/e?_d=1&_k=abc123&_n=eventName&_p=identifier&_t=#{timestamp}"
|
26
|
+
WebMock.should have_requested(:get, expected_api_hit)
|
27
|
+
end
|
28
|
+
it "should raise an error when no identity is provided" do
|
29
|
+
timestamp = Time.now.to_i
|
30
|
+
lambda {
|
31
|
+
subject.perform(nil, "eventName", { :foo => 'bar', :baz => 'bay'}, timestamp)
|
32
|
+
}.should raise_error(KmSidekiq::Error)
|
33
|
+
end
|
34
|
+
it "should raise an error when an invalid timestamp is provided" do
|
35
|
+
timestamp = Time.now.to_i * 1000 # common mistake is providing milliseconds instead of seconds
|
36
|
+
lambda {
|
37
|
+
subject.perform("identifier", "eventName", { :foo => 'bar', :baz => 'bay'}, timestamp)
|
38
|
+
}.should raise_error(KmSidekiq::Error)
|
39
|
+
end
|
40
|
+
it "should round off any decimal in timestamp" do
|
41
|
+
now = Time.now
|
42
|
+
timestamp_float = now.to_f
|
43
|
+
timeStamp_int = now.to_i
|
44
|
+
subject.perform("identifier", "eventName", { :foo => 'bar', :baz => 'bay'}, timestamp_float)
|
45
|
+
expected_api_hit = "http://trk.kissmetrics.com/e?_d=1&_k=abc123&_n=eventName&_p=identifier&_t=#{timeStamp_int}&baz=bay&foo=bar"
|
46
|
+
WebMock.should have_requested(:get, expected_api_hit)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
$:.push File.expand_path('../../lib', __FILE__)
|
2
|
+
require 'webmock/rspec'
|
3
|
+
require 'km_sidekiq/set_job'
|
4
|
+
|
5
|
+
describe "KmSidekiq::SetJob" do
|
6
|
+
before do
|
7
|
+
stub_request(:any, %r{http://trk.kissmetrics.com.*})
|
8
|
+
KmSidekiq.configure do |config|
|
9
|
+
config.key = "abc123"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
describe "perform" do
|
13
|
+
subject do
|
14
|
+
KmSidekiq::SetJob.new
|
15
|
+
end
|
16
|
+
it "should hit the KM API" do
|
17
|
+
timestamp = Time.now.to_i
|
18
|
+
subject.perform("identifier", { :foo => 'bar', :baz => 'bay'}, timestamp)
|
19
|
+
expected_api_hit = "http://trk.kissmetrics.com/s?_d=1&_k=abc123&_p=identifier&_t=#{timestamp}&baz=bay&foo=bar"
|
20
|
+
WebMock.should have_requested(:get, expected_api_hit)
|
21
|
+
end
|
22
|
+
it "should round off any decimal in timestamp" do
|
23
|
+
now = Time.now
|
24
|
+
timestamp_float = now.to_f
|
25
|
+
timeStamp_int = now.to_i
|
26
|
+
subject.perform("identifier", { :foo => 'bar', :baz => 'bay'}, timestamp_float)
|
27
|
+
expected_api_hit = "http://trk.kissmetrics.com/s?_d=1&_k=abc123&_p=identifier&_t=#{timeStamp_int}&baz=bay&foo=bar"
|
28
|
+
WebMock.should have_requested(:get, expected_api_hit)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'km_sidekiq'
|
3
|
+
require 'rspec-sidekiq'
|
4
|
+
|
5
|
+
describe "KmSidekiq" do
|
6
|
+
before do
|
7
|
+
Time.stub(:now => Time.now)
|
8
|
+
@prior_timestamp = Time.now.to_i-(60 * 60 * 24)
|
9
|
+
@timestamp = Time.now.to_i
|
10
|
+
end
|
11
|
+
describe "configuring" do
|
12
|
+
it "should capture the API key" do
|
13
|
+
KmSidekiq.configure do |config|
|
14
|
+
config.key = "foo"
|
15
|
+
end
|
16
|
+
KmSidekiq.configuration.key.should == "foo"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
describe "alias" do
|
20
|
+
it "should queue an AliasJob with current time" do
|
21
|
+
KmSidekiq.alias("identifier1", "identifier2")
|
22
|
+
KmSidekiq::AliasJob.should have_enqueued_job("identifier1",
|
23
|
+
"identifier2",
|
24
|
+
@timestamp
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
describe "set" do
|
29
|
+
it "should queue a SetJob with current time" do
|
30
|
+
KmSidekiq.set("identifier", {:some_prop => 'some_val'})
|
31
|
+
KmSidekiq::SetJob.should have_enqueued_job("identifier",
|
32
|
+
{'some_prop' => 'some_val'},
|
33
|
+
@timestamp
|
34
|
+
)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
describe "record" do
|
38
|
+
it "should queue a RecordJob with current time" do
|
39
|
+
KmSidekiq.record("identifier", "myEventName", {:some_prop => 'some_val'})
|
40
|
+
KmSidekiq::RecordJob.should have_enqueued_job("identifier",
|
41
|
+
"myEventName",
|
42
|
+
{'some_prop' => 'some_val'},
|
43
|
+
@timestamp
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
describe "alias" do
|
48
|
+
it "should queue an AliasJob with arbitrary timestamp" do
|
49
|
+
KmSidekiq.alias("identifier1", "identifier2", @prior_timestamp)
|
50
|
+
KmSidekiq::AliasJob.should have_enqueued_job("identifier1",
|
51
|
+
"identifier2",
|
52
|
+
@prior_timestamp
|
53
|
+
)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
describe "set" do
|
57
|
+
it "should queue a SetJob with arbitrary timestamp" do
|
58
|
+
KmSidekiq.set("identifier", {:some_prop => 'some_val'}, @prior_timestamp)
|
59
|
+
KmSidekiq::SetJob.should have_enqueued_job("identifier",
|
60
|
+
{'some_prop' => 'some_val'},
|
61
|
+
@prior_timestamp
|
62
|
+
)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
describe "record" do
|
66
|
+
it "should queue a RecordJob with arbitrary timestamp" do
|
67
|
+
KmSidekiq.record("identifier", "myEventName", {:some_prop => 'some_val'}, @prior_timestamp)
|
68
|
+
KmSidekiq::RecordJob.should have_enqueued_job("identifier",
|
69
|
+
"myEventName",
|
70
|
+
{'some_prop' => 'some_val'},
|
71
|
+
@prior_timestamp
|
72
|
+
)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
$:.push File.expand_path('../lib', __FILE__)
|
2
|
+
require 'km_sidekiq'
|
3
|
+
require 'rspec-sidekiq'
|
4
|
+
|
5
|
+
Sidekiq::Testing.fake!
|
6
|
+
|
7
|
+
describe "KmSidekiq" do
|
8
|
+
before do
|
9
|
+
Time.stub(:now => Time.now)
|
10
|
+
@timestamp = Time.now.to_i
|
11
|
+
end
|
12
|
+
describe "configuring" do
|
13
|
+
it "should capture the API key" do
|
14
|
+
KmSidekiq.configure do |config|
|
15
|
+
config.key = "foo"
|
16
|
+
end
|
17
|
+
KmSidekiq.configuration.key.should == "foo"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
describe "alias" do
|
21
|
+
it "should queue an AliasJob" do
|
22
|
+
KmSidekiq.alias("identifier1", "identifier2")
|
23
|
+
KmSidekiq::AliasJob.should have_enqueued_job("identifier1",
|
24
|
+
"identifier2",
|
25
|
+
@timestamp
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
describe "set" do
|
30
|
+
it "should queue an SetJob" do
|
31
|
+
KmSidekiq.set("identifier", {:some_prop => 'some_val'})
|
32
|
+
KmSidekiq::SetJob.should have_enqueued_job("identifier",
|
33
|
+
{'some_prop' => 'some_val'},
|
34
|
+
@timestamp
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
describe "record" do
|
39
|
+
it "should queue an RecordJob" do
|
40
|
+
KmSidekiq.record("identifier", "myEventName", {:some_prop => 'some_val'})
|
41
|
+
KmSidekiq::RecordJob.should have_enqueued_job("identifier",
|
42
|
+
"myEventName",
|
43
|
+
{'some_prop' => 'some_val'},
|
44
|
+
@timestamp
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: km_sidekiq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luke Melia
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sidekiq
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-sidekiq
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Interact with the KISSMetrics API via Sidekiq
|
56
|
+
email:
|
57
|
+
- luke@lukemelia.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- km-sidekiq.gemspec
|
69
|
+
- lib/km_sidekiq.rb
|
70
|
+
- lib/km_sidekiq/alias_job.rb
|
71
|
+
- lib/km_sidekiq/api_client.rb
|
72
|
+
- lib/km_sidekiq/configuration.rb
|
73
|
+
- lib/km_sidekiq/record_job.rb
|
74
|
+
- lib/km_sidekiq/set_job.rb
|
75
|
+
- lib/km_sidekiq/version.rb
|
76
|
+
- spec/lib/km_sidekiq/alias_job_spec.rb
|
77
|
+
- spec/lib/km_sidekiq/record_job_spec.rb
|
78
|
+
- spec/lib/km_sidekiq/set_job_spec.rb
|
79
|
+
- spec/lib/km_sidekiq/sidekiq_spec.rb
|
80
|
+
- spec/lib/km_sidekiq_spec.rb
|
81
|
+
homepage: https://github.com/yapplabs/km_sidekiq
|
82
|
+
licenses: []
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.1.10
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Interact with the KISSMetrics API via Sidekiq
|
104
|
+
test_files:
|
105
|
+
- spec/lib/km_sidekiq/alias_job_spec.rb
|
106
|
+
- spec/lib/km_sidekiq/record_job_spec.rb
|
107
|
+
- spec/lib/km_sidekiq/set_job_spec.rb
|
108
|
+
- spec/lib/km_sidekiq/sidekiq_spec.rb
|
109
|
+
- spec/lib/km_sidekiq_spec.rb
|