mixpanel_client 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,61 +8,24 @@ Ruby access to the [Mixpanel](http://mixpanel.com/) web analytics tool.
8
8
  gem install mixpanel_client
9
9
 
10
10
 
11
- ## New Usage
11
+ ## Usage
12
12
 
13
13
  require 'rubygems'
14
14
  require 'mixpanel_client'
15
15
 
16
- config = {'api_key' => 'changeme', 'api_secret' => 'changeme'}
16
+ client = Mixpanel::Client.new('api_key' => 'changeme', 'api_secret' => 'changeme')
17
17
 
18
- client = Mixpanel::Client.new(config)
19
-
20
- # Get all results for 'test-event' in the last 24 hours from the test bucket
21
18
  data = client.request do
22
- resource 'events'
19
+ resource 'events/retention'
23
20
  event '["test-event"]'
24
21
  type 'general'
25
22
  unit 'hour'
26
23
  interval 24
27
24
  bucket 'test'
28
25
  end
29
- puts data.inspect
30
26
 
31
- # Get the top property names for 'test-event'
32
- data = client.request do
33
- resource 'events/properties/top'
34
- event '["test-event"]'
35
- type 'general'
36
- end
37
27
  puts data.inspect
38
28
 
39
-
40
- ## Old Usage (versions prior to 0.5.0)
41
-
42
- __NOTE: This old usage is deprecated and will be removed in future versions.__
43
-
44
- require 'rubygems'
45
- require 'mixpanel_client'
46
-
47
- config = {:api_key => 'changeme', :api_secret => 'changeme'}
48
-
49
- api = Mixpanel::Client.new(config)
50
-
51
- # Example without an endpoint
52
- data = api.request(nil, :events, {
53
- :event => '["test-event"]',
54
- :unit => 'hour',
55
- :interval => 24
56
- })
57
- puts data.inspect
58
-
59
- # Example with an endpoint and method
60
- data = api.request(:events, :top, {
61
- :type => 'general'
62
- })
63
- puts data.inspect
64
-
65
-
66
29
  ## Copyright
67
30
 
68
31
  Copyright (c) 2009+ Keolo Keagy. See LICENSE for details.
data/Rakefile CHANGED
@@ -11,9 +11,8 @@ begin
11
11
  gem.email = 'keolo@dreampointmedia.com'
12
12
  gem.homepage = 'http://github.com/keolo/mixpanel_client'
13
13
  gem.authors = ['Keolo Keagy']
14
- gem.add_development_dependency 'rspec', '>= 1.2.9'
15
- gem.add_development_dependency 'cucumber', '>= 0'
16
- gem.add_development_dependency 'webmock', '>= 1.3.5'
14
+ gem.add_development_dependency 'rspec', '>= 2.4.0'
15
+ gem.add_development_dependency 'webmock', '>= 1.6.2'
17
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
17
  end
19
18
  Jeweler::GemcutterTasks.new
@@ -21,21 +20,21 @@ rescue LoadError
21
20
  puts 'Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler'
22
21
  end
23
22
 
24
- require 'spec/rake/spectask'
25
- Spec::Rake::SpecTask.new(:spec) do |spec|
26
- spec.libs << 'lib' << 'spec'
27
- spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ require 'rspec/core/rake_task'
24
+ RSpec::Core::RakeTask.new(:spec) do |spec|
25
+ spec.pattern = 'spec/**/*_spec.rb'
26
+ spec.rspec_opts = ['--color']
28
27
  end
29
28
 
30
29
  namespace :spec do
31
30
  desc 'Run all tests that depend on external dependencies'
32
- Spec::Rake::SpecTask.new(:externals) do |t|
33
- t.spec_files = FileList['spec/**/*_externalspec.rb']
31
+ RSpec::Core::RakeTask.new(:externals) do |t|
32
+ t.pattern = 'spec/**/*_externalspec.rb'
33
+ t.rspec_opts = ['--color']
34
34
  end
35
35
  end
36
36
 
37
- Spec::Rake::SpecTask.new(:rcov) do |spec|
38
- spec.libs << 'lib' << 'spec'
37
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
39
38
  spec.pattern = 'spec/**/*_spec.rb'
40
39
  spec.rcov = true
41
40
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -39,34 +39,28 @@ module Mixpanel
39
39
 
40
40
  def params
41
41
  OPTIONS.inject({}) do |params, param|
42
- params.merge!(param => send(param)) if param != :resource && !send(param).nil?
42
+ option = send(param)
43
+ params.merge!(param => option) if param != :resource && !option.nil?
43
44
  params
44
45
  end
45
46
  end
46
47
 
47
- def request(deprecated_endpoint=nil, deprecated_meth=nil, deprecated_params=nil, &options)
48
+ def request(&options)
48
49
  reset_options
49
- if block_given?
50
- instance_eval &options
51
- @uri = URI.mixpanel(resource, normalize_params(params))
52
- response = URI.get(@uri)
53
- to_hash(response)
54
- else
55
- warn 'This usage is deprecated. Please use the new block form (see README).'
56
- @uri = URI.deprecated_mixpanel(deprecated_endpoint, deprecated_meth, normalize_params(deprecated_params))
57
- response = URI.get(@uri)
58
- to_hash(response)
59
- end
50
+ instance_eval(&options)
51
+ @uri = URI.mixpanel(resource, normalize_params(params))
52
+ response = URI.get(@uri)
53
+ to_hash(response)
60
54
  end
61
55
 
62
56
  def normalize_params(params)
63
57
  params.merge!(
64
58
  :api_key => @api_key,
65
59
  :expire => Time.now.to_i + 600 # Grant this request 10 minutes
66
- ).merge!(:sig => hash_args(params))
60
+ ).merge!(:sig => generate_signature(params))
67
61
  end
68
62
 
69
- def hash_args(args)
63
+ def generate_signature(args)
70
64
  Digest::MD5.hexdigest(args.map{|key,val| "#{key}=#{val}"}.sort.join + api_secret)
71
65
  end
72
66
 
@@ -87,12 +81,9 @@ module Mixpanel
87
81
 
88
82
  # URI related helpers
89
83
  class URI
84
+ # Create an http error class for us to use
90
85
  class HTTPError < StandardError; end
91
86
 
92
- def self.deprecated_mixpanel(endpoint, meth, params)
93
- File.join([BASE_URI, VERSION, endpoint.to_s, meth.to_s].reject(&:empty?)) + "?#{self.encode(params)}"
94
- end
95
-
96
87
  def self.mixpanel(resource, params)
97
88
  File.join([BASE_URI, VERSION, resource.to_s]) + "?#{self.encode(params)}"
98
89
  end
@@ -1,50 +1,44 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mixpanel_client}
8
- s.version = "0.5.0"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Keolo Keagy"]
12
- s.date = %q{2010-10-14}
12
+ s.date = %q{2011-01-26}
13
13
  s.description = %q{Simple ruby client interface to the Mixpanel API.}
14
14
  s.email = %q{keolo@dreampointmedia.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.md"
17
+ "README.md"
18
18
  ]
19
19
  s.files = [
20
20
  ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.md",
24
- "Rakefile",
25
- "VERSION",
26
- "config/mixpanel.template.yml",
27
- "features/mixpanel_client.feature",
28
- "features/step_definitions/mixpanel_client_steps.rb",
29
- "features/support/env.rb",
30
- "lib/mixpanel_client.rb",
31
- "mixpanel_client.gemspec",
32
- "spec/events_externalspec.rb",
33
- "spec/mixpanel_client_spec.rb",
34
- "spec/spec.opts",
35
- "spec/spec_helper.rb"
21
+ "LICENSE",
22
+ "README.md",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "config/mixpanel.template.yml",
26
+ "lib/mixpanel_client.rb",
27
+ "mixpanel_client.gemspec",
28
+ "spec/events_externalspec.rb",
29
+ "spec/mixpanel_client_spec.rb",
30
+ "spec/spec_helper.rb"
36
31
  ]
37
32
  s.homepage = %q{http://github.com/keolo/mixpanel_client}
38
- s.rdoc_options = ["--charset=UTF-8"]
39
33
  s.require_paths = ["lib"]
40
34
  s.rubygems_version = %q{1.3.6}
41
35
  s.summary = %q{Ruby Mixpanel API Client Library}
42
36
  s.test_files = [
43
37
  "spec/events_externalspec.rb",
44
- "spec/mixpanel_client_spec.rb",
45
- "spec/spec_helper.rb",
46
- "test/manual.rb",
47
- "test/test.rb"
38
+ "spec/mixpanel_client_spec.rb",
39
+ "spec/spec_helper.rb",
40
+ "test/manual.rb",
41
+ "test/test.rb"
48
42
  ]
49
43
 
50
44
  if s.respond_to? :specification_version then
@@ -52,18 +46,15 @@ Gem::Specification.new do |s|
52
46
  s.specification_version = 3
53
47
 
54
48
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
55
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
56
- s.add_development_dependency(%q<cucumber>, [">= 0"])
57
- s.add_development_dependency(%q<webmock>, [">= 1.3.5"])
49
+ s.add_development_dependency(%q<rspec>, [">= 2.4.0"])
50
+ s.add_development_dependency(%q<webmock>, [">= 1.6.2"])
58
51
  else
59
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
- s.add_dependency(%q<cucumber>, [">= 0"])
61
- s.add_dependency(%q<webmock>, [">= 1.3.5"])
52
+ s.add_dependency(%q<rspec>, [">= 2.4.0"])
53
+ s.add_dependency(%q<webmock>, [">= 1.6.2"])
62
54
  end
63
55
  else
64
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
65
- s.add_dependency(%q<cucumber>, [">= 0"])
66
- s.add_dependency(%q<webmock>, [">= 1.3.5"])
56
+ s.add_dependency(%q<rspec>, [">= 2.4.0"])
57
+ s.add_dependency(%q<webmock>, [">= 1.6.2"])
67
58
  end
68
59
  end
69
60
 
@@ -9,17 +9,17 @@ describe Mixpanel::Client do
9
9
  end
10
10
 
11
11
  describe '#request' do
12
- it 'should return json and convert to a ruby hash' do
12
+ it 'should return an argument error "Wrong number of arguments" if using the deprecated usage' do
13
13
  # Stub Mixpanel request
14
14
  stub_request(:get, /^#{@uri}.*/).to_return(:body => '{"legend_size": 0, "data": {"series": [], "values": {}}}')
15
15
 
16
- data = @client.request(nil, :events, {
16
+ data = lambda{@client.request(nil, :events, {
17
17
  :event => '["test-event"]',
18
18
  :unit => 'hour',
19
19
  :interval => 24
20
- })
20
+ })}
21
21
 
22
- data.should == {"data"=>{"series"=>[], "values"=>{}}, "legend_size"=>0}
22
+ data.should raise_error(ArgumentError)
23
23
  end
24
24
  end
25
25
 
@@ -49,13 +49,26 @@ describe Mixpanel::Client do
49
49
  end
50
50
  data.should == {"events"=>[], "type"=>"general"}
51
51
  end
52
+
53
+ it 'should create getter methods for given options' do
54
+ @client.resource.should == 'events/top'
55
+ @client.type.should == 'general'
56
+ end
57
+
58
+ it 'should create setter methods for given options' do
59
+ @client.resource 'hi'
60
+ @client.resource.should == 'hi'
61
+
62
+ @client.type 'ok'
63
+ @client.type.should == 'ok'
64
+ end
52
65
  end
53
66
 
54
67
  describe '#hash_args' do
55
68
  it 'should return a hashed string alpha sorted by key names.' do
56
69
  args = {:c => 'see', :a => 'aye', :d => 'dee', :b => 'bee'}
57
70
  args_alpha_sorted = {:a => 'aye', :b => 'bee', :c => 'see', :d => 'dee'}
58
- @client.hash_args(args).should == @client.hash_args(args_alpha_sorted)
71
+ @client.generate_signature(args).should == @client.generate_signature(args_alpha_sorted)
59
72
  end
60
73
  end
61
74
 
@@ -99,17 +112,6 @@ describe Mixpanel::Client do
99
112
  end
100
113
 
101
114
  describe Mixpanel::URI do
102
- describe '.deprecated_mixpanel' do
103
- it 'should return a properly formatted mixpanel uri as a string (without an endpoint)' do
104
- endpoint, meth, params = [:events, nil, {:c => 'see', :a => 'aye'}]
105
- Mixpanel::URI.deprecated_mixpanel(endpoint, meth, params).should == 'http://mixpanel.com/api/2.0/events?a=aye&c=see'
106
- end
107
- it 'should return a properly formatted mixpanel uri as a string (with an endpoint)' do
108
- endpoint, meth, params = [:events, :top, {:c => 'see', :a => 'aye'}]
109
- Mixpanel::URI.deprecated_mixpanel(endpoint, meth, params).should == 'http://mixpanel.com/api/2.0/events/top?a=aye&c=see'
110
- end
111
- end
112
-
113
115
  describe '.mixpanel' do
114
116
  it 'should return a properly formatted mixpanel uri as a string (without an endpoint)' do
115
117
  resource, params = ['events', {:c => 'see', :a => 'aye'}]
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,8 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'mixpanel_client'
4
- require 'spec'
5
- require 'spec/autorun'
6
4
  require 'webmock/rspec'
7
5
 
8
- Spec::Runner.configure do |config|
9
- config.include WebMock
6
+ RSpec.configure do |config|
7
+ config.include WebMock::API
10
8
  end
data/test/manual.rb CHANGED
@@ -11,7 +11,6 @@
11
11
 
12
12
  require 'rubygems'
13
13
  require "#{File.dirname(__FILE__)}/../lib/mixpanel_client"
14
- #require 'mixpanel_client'
15
14
 
16
15
  config = {'api_key' => 'e81de686c96261747fdc443d4809c297', 'api_secret' => '201ff82db5f1e8766b0004f0acf8d82e'}
17
16
 
@@ -31,18 +30,6 @@ puts client.inspect
31
30
  puts data.inspect
32
31
  puts
33
32
 
34
- # Argument form
35
- data = client.request(nil, :events, {
36
- :event => '["test-event"]',
37
- :unit => 'hour',
38
- :interval => 24,
39
- })
40
-
41
- puts
42
- puts client.inspect
43
- puts data.inspect
44
- puts
45
-
46
33
  # Block form
47
34
  data = client.request do
48
35
  resource 'events/properties/top'
@@ -55,17 +42,6 @@ puts client.inspect
55
42
  puts data.inspect
56
43
  puts
57
44
 
58
- # Argument form
59
- data = client.request(:events, :top, {
60
- :type => 'general',
61
- #:format => :csv
62
- })
63
-
64
- puts
65
- puts client.inspect
66
- puts data.inspect
67
- puts
68
-
69
45
  # Bucket
70
46
  data = client.request do
71
47
  resource 'events'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 5
8
- - 0
9
- version: 0.5.0
8
+ - 1
9
+ version: 0.5.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Keolo Keagy
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-14 00:00:00 -07:00
17
+ date: 2011-01-26 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -25,38 +25,26 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
- - 1
29
28
  - 2
30
- - 9
31
- version: 1.2.9
32
- type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: cucumber
36
- prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
29
+ - 4
42
30
  - 0
43
- version: "0"
31
+ version: 2.4.0
44
32
  type: :development
45
- version_requirements: *id002
33
+ version_requirements: *id001
46
34
  - !ruby/object:Gem::Dependency
47
35
  name: webmock
48
36
  prerelease: false
49
- requirement: &id003 !ruby/object:Gem::Requirement
37
+ requirement: &id002 !ruby/object:Gem::Requirement
50
38
  requirements:
51
39
  - - ">="
52
40
  - !ruby/object:Gem::Version
53
41
  segments:
54
42
  - 1
55
- - 3
56
- - 5
57
- version: 1.3.5
43
+ - 6
44
+ - 2
45
+ version: 1.6.2
58
46
  type: :development
59
- version_requirements: *id003
47
+ version_requirements: *id002
60
48
  description: Simple ruby client interface to the Mixpanel API.
61
49
  email: keolo@dreampointmedia.com
62
50
  executables: []
@@ -68,28 +56,23 @@ extra_rdoc_files:
68
56
  - README.md
69
57
  files:
70
58
  - .document
71
- - .gitignore
72
59
  - LICENSE
73
60
  - README.md
74
61
  - Rakefile
75
62
  - VERSION
76
63
  - config/mixpanel.template.yml
77
- - features/mixpanel_client.feature
78
- - features/step_definitions/mixpanel_client_steps.rb
79
- - features/support/env.rb
80
64
  - lib/mixpanel_client.rb
81
65
  - mixpanel_client.gemspec
82
66
  - spec/events_externalspec.rb
83
67
  - spec/mixpanel_client_spec.rb
84
- - spec/spec.opts
85
68
  - spec/spec_helper.rb
86
69
  has_rdoc: true
87
70
  homepage: http://github.com/keolo/mixpanel_client
88
71
  licenses: []
89
72
 
90
73
  post_install_message:
91
- rdoc_options:
92
- - --charset=UTF-8
74
+ rdoc_options: []
75
+
93
76
  require_paths:
94
77
  - lib
95
78
  required_ruby_version: !ruby/object:Gem::Requirement
data/.gitignore DELETED
@@ -1,24 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- config/mixpanel.yml
18
- coverage
19
- rdoc
20
- pkg
21
-
22
- ## PROJECT::SPECIFIC
23
- test/
24
- tmp/
@@ -1,9 +0,0 @@
1
- Feature: something something
2
- In order to something something
3
- A user something something
4
- something something something
5
-
6
- Scenario: something something
7
- Given inspiration
8
- When I create a sweet new gem
9
- Then everyone should see how awesome I am
File without changes
@@ -1,4 +0,0 @@
1
- $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
- require 'mixpanel_client'
3
-
4
- require 'spec/expectations'
data/spec/spec.opts DELETED
@@ -1 +0,0 @@
1
- --color