mixpanel_client 0.2.0 → 0.2.2

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.md CHANGED
@@ -1,20 +1,18 @@
1
- # Ruby Mixpanel API Client
1
+ # Ruby Mixpanel API Client
2
2
 
3
- Ruby access to the [Mixpanel](http://mixpanel.com/) web analytics tool.
3
+ Ruby access to the [Mixpanel](http://mixpanel.com/) web analytics tool.
4
4
 
5
5
  ## Installation
6
- # If you don't already have gemcutter as a rubygems source
7
- gem install gemcutter
8
- gem tumble
9
-
10
- gem install mixpanel_client
6
+ $ gem install mixpanel_client
11
7
 
12
8
  ## Example Usage
13
9
  require 'rubygems'
14
10
  require 'mixpanel_client'
15
11
 
16
- config = {:api_key => 'changeme123', :api_secret => '123changeme'}
12
+ config = {:api_key => 'changeme', :api_secret => 'changeme'}
13
+
17
14
  api = Mixpanel::Client.new(config)
15
+
18
16
  data = api.request(:events, :general, {
19
17
  :event => '["test-event"]',
20
18
  :unit => 'hour',
data/Rakefile CHANGED
@@ -4,19 +4,19 @@ require 'rake'
4
4
  begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
- gem.name = "mixpanel_client"
7
+ gem.name = 'mixpanel_client'
8
8
  gem.summary = 'Ruby Mixpanel API Client Library'
9
9
  gem.description = 'Simple ruby client interface to the Mixpanel API.'
10
- gem.email = "keolo@dreampointmedia.com"
11
- gem.homepage = "http://github.com/keolo/mixpanel_client"
12
- gem.authors = ["Keolo Keagy"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- gem.add_development_dependency "cucumber", ">= 0"
10
+ gem.email = 'keolo@dreampointmedia.com'
11
+ gem.homepage = 'http://github.com/keolo/mixpanel_client'
12
+ gem.authors = ['Keolo Keagy']
13
+ gem.add_development_dependency 'rspec', '>= 1.2.9'
14
+ gem.add_development_dependency 'cucumber', '>= 0'
15
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
16
  end
17
17
  Jeweler::GemcutterTasks.new
18
18
  rescue LoadError
19
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ puts 'Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler'
20
20
  end
21
21
 
22
22
  require 'spec/rake/spectask'
@@ -40,7 +40,7 @@ begin
40
40
  task :features => :check_dependencies
41
41
  rescue LoadError
42
42
  task :features do
43
- abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
43
+ abort 'Cucumber is not available. In order to run features, you must: sudo gem install cucumber'
44
44
  end
45
45
  end
46
46
 
@@ -48,7 +48,7 @@ task :default => :spec
48
48
 
49
49
  require 'rake/rdoctask'
50
50
  Rake::RDocTask.new do |rdoc|
51
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
52
52
 
53
53
  rdoc.rdoc_dir = 'rdoc'
54
54
  rdoc.title = "mixpanel_client #{version}"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.2
@@ -12,8 +12,6 @@
12
12
  require 'cgi'
13
13
  require 'digest/md5'
14
14
  require 'open-uri'
15
- require 'rubygems'
16
- require 'json'
17
15
 
18
16
  module Mixpanel
19
17
  class Client
@@ -28,14 +26,13 @@ module Mixpanel
28
26
  end
29
27
 
30
28
  def request(endpoint, meth, params)
31
- params[:api_key] = api_key
32
- params[:expire] = Time.now.to_i + 600 # Grant this request 10 minutes
33
- params[:format] ||= :json
34
- params[:sig] = hash_args(params)
29
+ params[:api_key] = api_key
30
+ params[:expire] = Time.now.to_i + 600 # Grant this request 10 minutes
31
+ params[:sig] = hash_args(params)
35
32
 
36
33
  @format = params[:format]
37
34
 
38
- response = URI.parse(mixpanel_uri(endpoint, meth, params)).read
35
+ response = get(mixpanel_uri(endpoint, meth, params))
39
36
  to_hash(response)
40
37
  end
41
38
 
@@ -43,6 +40,10 @@ module Mixpanel
43
40
  Digest::MD5.hexdigest(args.map{|k,v| "#{k}=#{v}"}.sort.to_s + api_secret)
44
41
  end
45
42
 
43
+ def get(uri)
44
+ URI.parse(uri).read
45
+ end
46
+
46
47
  def mixpanel_uri(endpoint, meth, params)
47
48
  %Q(#{BASE_URI}/#{endpoint}/#{VERSION}/#{meth}?#{urlencode(params)})
48
49
  end
@@ -51,12 +52,14 @@ module Mixpanel
51
52
  params.map{|k,v| "#{k}=#{CGI.escape(v.to_s)}"}.sort.join('&')
52
53
  end
53
54
 
54
- protected
55
- def to_hash(data)
56
- case @format
57
- when :json
58
- JSON.parse(data)
59
- end
55
+ def to_hash(data)
56
+ case @format
57
+ when :xml
58
+ # TODO: xml parsing
59
+ else :json
60
+ require 'json' unless defined?(JSON)
61
+ JSON.parse(data)
60
62
  end
63
+ end
61
64
  end
62
65
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mixpanel_client}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.2"
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{2009-12-02}
12
+ s.date = %q{2010-01-13}
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 = [
@@ -1,3 +1,5 @@
1
+ require 'rubygems'
2
+
1
3
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
4
 
3
5
  describe 'Mixpanel::Client' do
@@ -7,14 +9,16 @@ describe 'Mixpanel::Client' do
7
9
  end
8
10
 
9
11
  describe '#request' do
10
- it 'should return a valid JSON result set.' do
11
- pending 'Need to setup valid Mixpanel test account.'
12
+ it 'should return json and convert to a ruby hash' do
13
+ # Stub Mixpanel web service
14
+ @api.stub!(:get).and_return('{"some" : "thing"}')
15
+
12
16
  data = @api.request(:events, :general, {
13
17
  :event => '["test-event"]',
14
18
  :unit => 'hour',
15
19
  :interval => 24
16
20
  })
17
- data.should == {:some => 'thing'}
21
+ data.should == {'some' => 'thing'}
18
22
  end
19
23
  end
20
24
 
@@ -39,4 +43,10 @@ describe 'Mixpanel::Client' do
39
43
  @api.urlencode(params).should == 'hey=%21%40%23%24%25%5E%26%2A%28%29%5C%2F%22%C3%9C&soo=h%C3%ABll%C3%B6%3F'
40
44
  end
41
45
  end
46
+
47
+ describe '#to_hash' do
48
+ it 'should return a ruby hash given json as a string' do
49
+ @api.to_hash('{"a" : "aye", "b" : "bee"}').should == {'a' => 'aye', 'b' => 'bee'}
50
+ end
51
+ end
42
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixpanel_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keolo Keagy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-02 00:00:00 -08:00
12
+ date: 2010-01-13 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency