mixpanel_typhoeus 1.0.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/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +38 -0
- data/LICENSE.txt +20 -0
- data/README.md +79 -0
- data/README.md.html +83 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/lib/mixpanel_typhoeus.rb +43 -0
- data/lib/mixpanel_typhoeus/support.rb +20 -0
- data/mixpanel_typhoeus.gemspec +94 -0
- data/spec/fixtures/vcr_cassettes/track/good_response.yml +30 -0
- data/spec/mixpanel_typhoeus/support_spec.rb +27 -0
- data/spec/mixpanel_typhoeus_spec.rb +53 -0
- data/spec/spec_helper.rb +18 -0
- metadata +273 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
json (1.5.1)
|
11
|
+
mime-types (1.16)
|
12
|
+
monster_mash (0.2.3)
|
13
|
+
typhoeus (>= 0.2.4)
|
14
|
+
typhoeus (>= 0.2.4)
|
15
|
+
rake (0.8.7)
|
16
|
+
rspec (2.3.0)
|
17
|
+
rspec-core (~> 2.3.0)
|
18
|
+
rspec-expectations (~> 2.3.0)
|
19
|
+
rspec-mocks (~> 2.3.0)
|
20
|
+
rspec-core (2.3.1)
|
21
|
+
rspec-expectations (2.3.0)
|
22
|
+
diff-lcs (~> 1.1.2)
|
23
|
+
rspec-mocks (2.3.0)
|
24
|
+
typhoeus (0.2.4)
|
25
|
+
mime-types
|
26
|
+
mime-types
|
27
|
+
vcr (1.6.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.0.0)
|
34
|
+
jeweler (~> 1.5.2)
|
35
|
+
json
|
36
|
+
monster_mash (>= 0.2.3)
|
37
|
+
rspec (~> 2.3.0)
|
38
|
+
vcr (>= 1.6.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 David Balatero
|
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.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
mixpanel_typhoeus
|
2
|
+
=================
|
3
|
+
|
4
|
+
This is a Mixpanel gem that allows you to make parallel API calls easily, thanks to being built on top of Typhoeus.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
To track a datapoint, the API is similar to the JavaScript one.
|
9
|
+
|
10
|
+
MixpanelTyphoeus.track(event, properties = {})
|
11
|
+
|
12
|
+
There are two requirements for calling `track()`.
|
13
|
+
|
14
|
+
* You must set your API token first. `MixpanelTyphoeus.token = 'mytoken'`.
|
15
|
+
* You must include either the `ip` or `distinct_id` parameters in the `properties` hash of each call.
|
16
|
+
|
17
|
+
The `time` parameter will automatically be calculated and sent with every datapoint, so you don't have to worry about it.
|
18
|
+
|
19
|
+
Serial (blocking) API calls
|
20
|
+
---------------------------
|
21
|
+
|
22
|
+
require 'mixpanel_typhoeus'
|
23
|
+
MixpanelTyphoeus.token = 'mytoken'
|
24
|
+
|
25
|
+
user_id = 10
|
26
|
+
result = MixpanelTyphoeus.track(:my_datapoint,
|
27
|
+
:distinct_id => user_id)
|
28
|
+
if result
|
29
|
+
puts "yay!"
|
30
|
+
else
|
31
|
+
puts "awwww :("
|
32
|
+
end
|
33
|
+
|
34
|
+
Parallel API calls
|
35
|
+
------------------
|
36
|
+
It's easy to make parallel API calls, since this library is built on Typhoeus/monster_mash.
|
37
|
+
|
38
|
+
require 'mixpanel_typhoeus'
|
39
|
+
MixpanelTyphoeus.token = 'mytoken'
|
40
|
+
|
41
|
+
user_ids = [1, 2, 3, 4, 5, 6, 7]
|
42
|
+
|
43
|
+
hydra = Typhoeus::Hydra.new
|
44
|
+
mixpanel = MixpanelTyphoeus.new(hydra)
|
45
|
+
|
46
|
+
completed_successfully = 0
|
47
|
+
failed = 0
|
48
|
+
user_ids.each do |id|
|
49
|
+
# Queue each HTTP request to be fired when we call hydra.run
|
50
|
+
mixpanel.track(:my_datapoint, :distinct_id => id) do |result, error|
|
51
|
+
if result
|
52
|
+
completed_successfully += 1
|
53
|
+
else
|
54
|
+
failed += 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
hydra.run # fire all requests, block until all complete.
|
60
|
+
|
61
|
+
puts "completed successfuly: #{completed_successfully}"
|
62
|
+
puts "failed: #{failed}"
|
63
|
+
puts ":)" if failed == 0
|
64
|
+
|
65
|
+
Contributing to mixpanel_typhoeus
|
66
|
+
---------------------------------
|
67
|
+
|
68
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
69
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
70
|
+
* Fork the project
|
71
|
+
* Start a feature/bugfix branch
|
72
|
+
* Commit and push until you are happy with your contribution
|
73
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
74
|
+
* 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.
|
75
|
+
|
76
|
+
Copyright
|
77
|
+
---------
|
78
|
+
Copyright (c) 2011 David Balatero / MediaPiston. See LICENSE.txt for
|
79
|
+
further details.
|
data/README.md.html
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
<h1>mixpanel_typhoeus</h1>
|
2
|
+
|
3
|
+
<p>This is a Mixpanel gem that allows you to make parallel API calls easily, thanks to being built on top of Typhoeus.</p>
|
4
|
+
|
5
|
+
<h2>Usage</h2>
|
6
|
+
|
7
|
+
<p>To track a datapoint, the API is similar to the JavaScript one.</p>
|
8
|
+
|
9
|
+
<pre><code>MixpanelTyphoeus.track(event, properties = {})
|
10
|
+
</code></pre>
|
11
|
+
|
12
|
+
<p>There are two requirements for calling <code>track()</code>.</p>
|
13
|
+
|
14
|
+
<ul>
|
15
|
+
<li>You must set your API token first. <code>MixpanelTyphoeus.token = 'mytoken'</code>.</li>
|
16
|
+
<li>You must include either the <code>ip</code> or <code>distinct_id</code> parameters in the <code>properties</code> hash of each call.</li>
|
17
|
+
</ul>
|
18
|
+
|
19
|
+
<p>The <code>time</code> parameter will automatically be calculated and sent with every datapoint, so you don’t have to worry about it.</p>
|
20
|
+
|
21
|
+
<h2>Serial (blocking) API calls</h2>
|
22
|
+
|
23
|
+
<pre><code>require 'mixpanel_typhoeus'
|
24
|
+
MixpanelTyphoeus.token = 'mytoken'
|
25
|
+
|
26
|
+
user_id = 10
|
27
|
+
result = MixpanelTyphoeus.track(:my_datapoint,
|
28
|
+
:distinct_id => user_id)
|
29
|
+
if result
|
30
|
+
puts "yay!"
|
31
|
+
else
|
32
|
+
puts "awwww :("
|
33
|
+
end
|
34
|
+
</code></pre>
|
35
|
+
|
36
|
+
<h2>Parallel API calls</h2>
|
37
|
+
|
38
|
+
<p>It’s easy to make parallel API calls, since this library is built on Typhoeus/monster_mash.</p>
|
39
|
+
|
40
|
+
<pre><code>require 'mixpanel_typhoeus'
|
41
|
+
MixpanelTyphoeus.token = 'mytoken'
|
42
|
+
|
43
|
+
user_ids = [1, 2, 3, 4, 5, 6, 7]
|
44
|
+
|
45
|
+
hydra = Typhoeus::Hydra.new
|
46
|
+
mixpanel = MixpanelTyphoeus.new(hydra)
|
47
|
+
|
48
|
+
completed_successfully = 0
|
49
|
+
failed = 0
|
50
|
+
user_ids.each do |id|
|
51
|
+
# Queue each HTTP request to be fired when we call hydra.run
|
52
|
+
mixpanel.track(:my_datapoint, :distinct_id => id) do |result, error|
|
53
|
+
if result
|
54
|
+
completed_successfully += 1
|
55
|
+
else
|
56
|
+
failed += 1
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
hydra.run # fire all requests, block until all complete.
|
62
|
+
|
63
|
+
puts "completed successfuly: #{completed_successfully}"
|
64
|
+
puts "failed: #{failed}"
|
65
|
+
puts ":)" if failed == 0
|
66
|
+
</code></pre>
|
67
|
+
|
68
|
+
<h2>Contributing to mixpanel_typhoeus</h2>
|
69
|
+
|
70
|
+
<ul>
|
71
|
+
<li>Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet</li>
|
72
|
+
<li>Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it</li>
|
73
|
+
<li>Fork the project</li>
|
74
|
+
<li>Start a feature/bugfix branch</li>
|
75
|
+
<li>Commit and push until you are happy with your contribution</li>
|
76
|
+
<li>Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.</li>
|
77
|
+
<li>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.</li>
|
78
|
+
</ul>
|
79
|
+
|
80
|
+
<h2>Copyright</h2>
|
81
|
+
|
82
|
+
<p>Copyright (c) 2011 David Balatero / MediaPiston. See LICENSE.txt for
|
83
|
+
further details.</p>
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "mixpanel_typhoeus"
|
16
|
+
gem.homepage = "http://github.com/dbalatero/mixpanel_typhoeus"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Provides a Typhoeus-based interface to Mixpanel.}
|
19
|
+
gem.description = %Q{This wraps the Mixpanel API with a serial/parallel Typhoeus interface.}
|
20
|
+
gem.email = "dbalatero@gmail.com"
|
21
|
+
gem.authors = ["David Balatero"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
gem.add_runtime_dependency 'monster_mash', '>= 0.2.3'
|
27
|
+
gem.add_runtime_dependency 'json'
|
28
|
+
|
29
|
+
gem.add_development_dependency 'rspec', '~> 2.3.0'
|
30
|
+
gem.add_development_dependency 'bundler', '~> 1.0.0'
|
31
|
+
gem.add_development_dependency 'jeweler', '~> 1.5.2'
|
32
|
+
gem.add_development_dependency 'vcr', '>= 1.6.0'
|
33
|
+
end
|
34
|
+
Jeweler::RubygemsDotOrgTasks.new
|
35
|
+
|
36
|
+
require 'rspec/core'
|
37
|
+
require 'rspec/core/rake_task'
|
38
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
39
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
40
|
+
end
|
41
|
+
|
42
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
43
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
44
|
+
spec.rcov = true
|
45
|
+
end
|
46
|
+
|
47
|
+
task :default => :spec
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "mixpanel_typhoeus #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'monster_mash'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class MixpanelTyphoeus < MonsterMash::Base
|
5
|
+
class << self
|
6
|
+
attr_accessor :token
|
7
|
+
end
|
8
|
+
@token = nil
|
9
|
+
|
10
|
+
post(:track) do |event, *args|
|
11
|
+
raise ArgumentError, "Missing API token. Please set MixpanelTyphoeus.token." if token.nil?
|
12
|
+
|
13
|
+
properties = {
|
14
|
+
:token => token,
|
15
|
+
:time => Time.now.utc.to_i
|
16
|
+
}.merge(args.first || {})
|
17
|
+
|
18
|
+
check_for_unique_id!(properties)
|
19
|
+
|
20
|
+
uri 'http://api.mixpanel.com/track'
|
21
|
+
params(:data => encode_data(:event => event,
|
22
|
+
:properties => properties))
|
23
|
+
handler do |response|
|
24
|
+
result = response.body.strip.to_i
|
25
|
+
result == 1
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.encode_data(params = {})
|
30
|
+
json = JSON.generate(params)
|
31
|
+
Support.encode64s(json)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.check_for_unique_id!(properties)
|
35
|
+
if !properties.has_key?(:ip) && !properties.has_key?('ip') &&
|
36
|
+
!properties.has_key?(:distinct_id) && !properties.has_key?('distinct_id')
|
37
|
+
raise ArgumentError, "Mixpanel requires you to pass either the 'ip' property or 'distinct_id', for a unique ID."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
base = File.dirname(__FILE__)
|
43
|
+
require "#{base}/mixpanel_typhoeus/support"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class MixpanelTyphoeus
|
2
|
+
# Grabbed these ActiveSupport functions from ActiveSupport::Base64.
|
3
|
+
# Reduces dependency on ActiveSupport.
|
4
|
+
module Support
|
5
|
+
def encode64(data)
|
6
|
+
[data].pack('m')
|
7
|
+
end
|
8
|
+
module_function :encode64
|
9
|
+
|
10
|
+
def decode64(data)
|
11
|
+
data.unpack("m").first
|
12
|
+
end
|
13
|
+
module_function :decode64
|
14
|
+
|
15
|
+
def encode64s(value)
|
16
|
+
encode64(value).gsub(/\n/, '')
|
17
|
+
end
|
18
|
+
module_function :encode64s
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,94 @@
|
|
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{mixpanel_typhoeus}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["David Balatero"]
|
12
|
+
s.date = %q{2011-02-24}
|
13
|
+
s.description = %q{This wraps the Mixpanel API with a serial/parallel Typhoeus interface.}
|
14
|
+
s.email = %q{dbalatero@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md",
|
18
|
+
"README.md.html"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".rspec",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"lib/mixpanel_typhoeus.rb",
|
30
|
+
"lib/mixpanel_typhoeus/support.rb",
|
31
|
+
"mixpanel_typhoeus.gemspec",
|
32
|
+
"spec/fixtures/vcr_cassettes/track/good_response.yml",
|
33
|
+
"spec/mixpanel_typhoeus/support_spec.rb",
|
34
|
+
"spec/mixpanel_typhoeus_spec.rb",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = %q{http://github.com/dbalatero/mixpanel_typhoeus}
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = %q{1.3.7}
|
41
|
+
s.summary = %q{Provides a Typhoeus-based interface to Mixpanel.}
|
42
|
+
s.test_files = [
|
43
|
+
"spec/mixpanel_typhoeus/support_spec.rb",
|
44
|
+
"spec/mixpanel_typhoeus_spec.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_runtime_dependency(%q<monster_mash>, [">= 0.2.3"])
|
54
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
56
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
57
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
58
|
+
s.add_development_dependency(%q<vcr>, [">= 1.6.0"])
|
59
|
+
s.add_runtime_dependency(%q<monster_mash>, [">= 0.2.3"])
|
60
|
+
s.add_runtime_dependency(%q<json>, [">= 0"])
|
61
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
62
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
63
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
64
|
+
s.add_development_dependency(%q<vcr>, [">= 1.6.0"])
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<monster_mash>, [">= 0.2.3"])
|
67
|
+
s.add_dependency(%q<json>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
71
|
+
s.add_dependency(%q<vcr>, [">= 1.6.0"])
|
72
|
+
s.add_dependency(%q<monster_mash>, [">= 0.2.3"])
|
73
|
+
s.add_dependency(%q<json>, [">= 0"])
|
74
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
75
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
76
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
77
|
+
s.add_dependency(%q<vcr>, [">= 1.6.0"])
|
78
|
+
end
|
79
|
+
else
|
80
|
+
s.add_dependency(%q<monster_mash>, [">= 0.2.3"])
|
81
|
+
s.add_dependency(%q<json>, [">= 0"])
|
82
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
83
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
84
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
85
|
+
s.add_dependency(%q<vcr>, [">= 1.6.0"])
|
86
|
+
s.add_dependency(%q<monster_mash>, [">= 0.2.3"])
|
87
|
+
s.add_dependency(%q<json>, [">= 0"])
|
88
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
89
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
90
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
91
|
+
s.add_dependency(%q<vcr>, [">= 1.6.0"])
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :post
|
5
|
+
uri: http://api.mixpanel.com:80/track
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
response: !ruby/struct:VCR::Response
|
9
|
+
status: !ruby/struct:VCR::ResponseStatus
|
10
|
+
code: 200
|
11
|
+
message: OK
|
12
|
+
headers:
|
13
|
+
access-control-allow-headers:
|
14
|
+
- X-Requested-With
|
15
|
+
access-control-allow-methods:
|
16
|
+
- GET, POST, OPTIONS
|
17
|
+
expires:
|
18
|
+
- Fri, 25 Feb 2011 03:34:04 GMT
|
19
|
+
access-control-allow-origin:
|
20
|
+
- "*"
|
21
|
+
server:
|
22
|
+
- nginx/0.7.65
|
23
|
+
date:
|
24
|
+
- Fri, 25 Feb 2011 03:34:05 GMT
|
25
|
+
content-length:
|
26
|
+
- "1"
|
27
|
+
access-control-max-age:
|
28
|
+
- "1728000"
|
29
|
+
body: "1"
|
30
|
+
http_version: "1.1"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../spec_helper"
|
2
|
+
|
3
|
+
describe MixpanelTyphoeus::Support do
|
4
|
+
before(:all) do
|
5
|
+
@klass = MixpanelTyphoeus::Support
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#encode64" do
|
9
|
+
it "should encode correctly" do
|
10
|
+
@klass.encode64('Original unencoded string').should ==
|
11
|
+
"T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw==\n"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "encoding/decoding" do
|
16
|
+
it "should go fwd/backward" do
|
17
|
+
@klass.decode64(@klass.encode64('foo')).should == 'foo'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#encode64s" do
|
22
|
+
it "should chop off \n chars" do
|
23
|
+
@klass.encode64s('Original unencoded string').should ==
|
24
|
+
"T3JpZ2luYWwgdW5lbmNvZGVkIHN0cmluZw=="
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe MixpanelTyphoeus do
|
4
|
+
before(:each) do
|
5
|
+
MixpanelTyphoeus.token = 'bootleg-token'
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "token" do
|
9
|
+
it "should be settable" do
|
10
|
+
old_value = MixpanelTyphoeus.token
|
11
|
+
begin
|
12
|
+
MixpanelTyphoeus.token = 'fdsa'
|
13
|
+
MixpanelTyphoeus.token.should == 'fdsa'
|
14
|
+
ensure
|
15
|
+
MixpanelTyphoeus.token = old_value
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#track" do
|
21
|
+
describe "sanity-checks" do
|
22
|
+
it "should fail if no token is set" do
|
23
|
+
old_token = MixpanelTyphoeus.token
|
24
|
+
begin
|
25
|
+
MixpanelTyphoeus.token = nil
|
26
|
+
lambda {
|
27
|
+
result = MixpanelTyphoeus.track('test_point')
|
28
|
+
}.should raise_error(ArgumentError)
|
29
|
+
ensure
|
30
|
+
MixpanelTyphoeus.token = old_token
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should require a unique identifier to be passed" do
|
35
|
+
lambda {
|
36
|
+
MixpanelTyphoeus.track('test')
|
37
|
+
}.should raise_error(ArgumentError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "a good response" do
|
42
|
+
use_vcr_cassette 'track/good_response', :record => :new_episodes
|
43
|
+
|
44
|
+
it "should return true" do
|
45
|
+
# called with a good token, but not committed to git
|
46
|
+
# for security.
|
47
|
+
result = MixpanelTyphoeus.track(:my_event,
|
48
|
+
:distinct_id => '1')
|
49
|
+
result.should be_true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'vcr'
|
5
|
+
require 'mixpanel_typhoeus'
|
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
|
+
VCR.config do |c|
|
12
|
+
c.cassette_library_dir = File.dirname(__FILE__) + '/fixtures/vcr_cassettes'
|
13
|
+
c.stub_with :typhoeus # or :fakeweb
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.extend VCR::RSpec::Macros
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mixpanel_typhoeus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- David Balatero
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-24 00:00:00 -08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 17
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
version: 0.2.3
|
35
|
+
name: monster_mash
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
name: json
|
50
|
+
requirement: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
type: :development
|
53
|
+
prerelease: false
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 2
|
62
|
+
- 3
|
63
|
+
- 0
|
64
|
+
version: 2.3.0
|
65
|
+
name: rspec
|
66
|
+
requirement: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 23
|
76
|
+
segments:
|
77
|
+
- 1
|
78
|
+
- 0
|
79
|
+
- 0
|
80
|
+
version: 1.0.0
|
81
|
+
name: bundler
|
82
|
+
requirement: *id004
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
type: :development
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ~>
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 7
|
92
|
+
segments:
|
93
|
+
- 1
|
94
|
+
- 5
|
95
|
+
- 2
|
96
|
+
version: 1.5.2
|
97
|
+
name: jeweler
|
98
|
+
requirement: *id005
|
99
|
+
- !ruby/object:Gem::Dependency
|
100
|
+
type: :development
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 15
|
108
|
+
segments:
|
109
|
+
- 1
|
110
|
+
- 6
|
111
|
+
- 0
|
112
|
+
version: 1.6.0
|
113
|
+
name: vcr
|
114
|
+
requirement: *id006
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
type: :runtime
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 17
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
- 2
|
127
|
+
- 3
|
128
|
+
version: 0.2.3
|
129
|
+
name: monster_mash
|
130
|
+
requirement: *id007
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 3
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
version: "0"
|
143
|
+
name: json
|
144
|
+
requirement: *id008
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ~>
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
hash: 3
|
154
|
+
segments:
|
155
|
+
- 2
|
156
|
+
- 3
|
157
|
+
- 0
|
158
|
+
version: 2.3.0
|
159
|
+
name: rspec
|
160
|
+
requirement: *id009
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
type: :development
|
163
|
+
prerelease: false
|
164
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
165
|
+
none: false
|
166
|
+
requirements:
|
167
|
+
- - ~>
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
hash: 23
|
170
|
+
segments:
|
171
|
+
- 1
|
172
|
+
- 0
|
173
|
+
- 0
|
174
|
+
version: 1.0.0
|
175
|
+
name: bundler
|
176
|
+
requirement: *id010
|
177
|
+
- !ruby/object:Gem::Dependency
|
178
|
+
type: :development
|
179
|
+
prerelease: false
|
180
|
+
version_requirements: &id011 !ruby/object:Gem::Requirement
|
181
|
+
none: false
|
182
|
+
requirements:
|
183
|
+
- - ~>
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
hash: 7
|
186
|
+
segments:
|
187
|
+
- 1
|
188
|
+
- 5
|
189
|
+
- 2
|
190
|
+
version: 1.5.2
|
191
|
+
name: jeweler
|
192
|
+
requirement: *id011
|
193
|
+
- !ruby/object:Gem::Dependency
|
194
|
+
type: :development
|
195
|
+
prerelease: false
|
196
|
+
version_requirements: &id012 !ruby/object:Gem::Requirement
|
197
|
+
none: false
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
hash: 15
|
202
|
+
segments:
|
203
|
+
- 1
|
204
|
+
- 6
|
205
|
+
- 0
|
206
|
+
version: 1.6.0
|
207
|
+
name: vcr
|
208
|
+
requirement: *id012
|
209
|
+
description: This wraps the Mixpanel API with a serial/parallel Typhoeus interface.
|
210
|
+
email: dbalatero@gmail.com
|
211
|
+
executables: []
|
212
|
+
|
213
|
+
extensions: []
|
214
|
+
|
215
|
+
extra_rdoc_files:
|
216
|
+
- LICENSE.txt
|
217
|
+
- README.md
|
218
|
+
- README.md.html
|
219
|
+
files:
|
220
|
+
- .document
|
221
|
+
- .rspec
|
222
|
+
- Gemfile
|
223
|
+
- Gemfile.lock
|
224
|
+
- LICENSE.txt
|
225
|
+
- README.md
|
226
|
+
- Rakefile
|
227
|
+
- VERSION
|
228
|
+
- lib/mixpanel_typhoeus.rb
|
229
|
+
- lib/mixpanel_typhoeus/support.rb
|
230
|
+
- mixpanel_typhoeus.gemspec
|
231
|
+
- spec/fixtures/vcr_cassettes/track/good_response.yml
|
232
|
+
- spec/mixpanel_typhoeus/support_spec.rb
|
233
|
+
- spec/mixpanel_typhoeus_spec.rb
|
234
|
+
- spec/spec_helper.rb
|
235
|
+
- README.md.html
|
236
|
+
has_rdoc: true
|
237
|
+
homepage: http://github.com/dbalatero/mixpanel_typhoeus
|
238
|
+
licenses:
|
239
|
+
- MIT
|
240
|
+
post_install_message:
|
241
|
+
rdoc_options: []
|
242
|
+
|
243
|
+
require_paths:
|
244
|
+
- lib
|
245
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
246
|
+
none: false
|
247
|
+
requirements:
|
248
|
+
- - ">="
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
hash: 3
|
251
|
+
segments:
|
252
|
+
- 0
|
253
|
+
version: "0"
|
254
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
255
|
+
none: false
|
256
|
+
requirements:
|
257
|
+
- - ">="
|
258
|
+
- !ruby/object:Gem::Version
|
259
|
+
hash: 3
|
260
|
+
segments:
|
261
|
+
- 0
|
262
|
+
version: "0"
|
263
|
+
requirements: []
|
264
|
+
|
265
|
+
rubyforge_project:
|
266
|
+
rubygems_version: 1.3.7
|
267
|
+
signing_key:
|
268
|
+
specification_version: 3
|
269
|
+
summary: Provides a Typhoeus-based interface to Mixpanel.
|
270
|
+
test_files:
|
271
|
+
- spec/mixpanel_typhoeus/support_spec.rb
|
272
|
+
- spec/mixpanel_typhoeus_spec.rb
|
273
|
+
- spec/spec_helper.rb
|