keolo / mixpanel_client

Ruby interface to the Mixpanel Data API
MIT License
148 stars 72 forks source link

"odd number list for Hash" when trying 'usage' example on Mac OS X 10.8.2 #25

Closed jishaq closed 11 years ago

jishaq commented 11 years ago

I am a Ruby novice, so I hope this isn't a dumb question.

I have a Mac OS X 10.8.2 and am using the pre-installed ruby 1.8.7; when I try to run the usage example, I am getting some errors relating to the hash:

macmini:Ruby jishaq$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]

macmini:Ruby jishaq$ cat usageExample.rb 
#!/usr/bin/env ruby

require 'rubygems'
require 'mixpanel_client'

config = {api_key: 'changeme', api_secret: 'changeme'}
client = Mixpanel::Client.new(config)

data = client.request('events/properties', {
  event:     'splash features',
  name:      'feature',
  values:    '["uno", "dos"]',
  type:      'unique',
  unit:      'day',
  interval:   7,
  limit:      5,
})

puts data.inspect   

macmini:Ruby jishaq$ ./usageExample.rb 
./usageExample.rb:6: odd number list for Hash
config = {api_key: 'changeme', api_secret: 'changeme'}
                  ^
./usageExample.rb:6: syntax error, unexpected ':', expecting '}'
config = {api_key: 'changeme', api_secret: 'changeme'}
                  ^
./usageExample.rb:6: syntax error, unexpected ',', expecting $end
config = {api_key: 'changeme', api_secret: 'changeme'}
                              ^
macmini:Ruby jishaq$ 

It seems that ruby 1.8.7 doesn't support the hash syntax with the ':' character for creating symbols, so I tried to rejigger the usage example, but it fails elsewhere:

macmini:Ruby jishaq$ cat usageExample2.rb 
#!/usr/bin/env ruby

require 'rubygems'
require 'mixpanel_client'

config = {'api_key' => 'changeme', 'api_secret' => 'changeme'}
client = Mixpanel::Client.new(config)

data = client.request('events/properties', {
  'event' =>     'splash features',
  'name' =>      'feature',
  'values' =>    '["uno", "dos"]',
  'type' =>     'unique',
  'unit' =>      'day',
  'interval' =>   7,
  'limit' =>      5,
})

puts data.inspect   

macmini:Ruby jishaq$ ./usageExample2.rb 
/Library/Ruby/Gems/1.8/gems/mixpanel_client-3.1.0/lib/mixpanel/utils.rb:17:in `+': can't convert nil into String (TypeError)
    from /Library/Ruby/Gems/1.8/gems/mixpanel_client-3.1.0/lib/mixpanel/utils.rb:17:in `generate_signature'
    from /Library/Ruby/Gems/1.8/gems/mixpanel_client-3.1.0/lib/mixpanel/client.rb:98:in `normalize_options'
    from /Library/Ruby/Gems/1.8/gems/mixpanel_client-3.1.0/lib/mixpanel/client.rb:50:in `request'
    from ./usageExample2.rb:9
macmini:Ruby jishaq$ 

In utils.rb:17, I am guessing the "nil" in question would be api_secret value:

Digest::MD5.hexdigest(args.map{|key,val| "#{key}=#{val}"}.sort.join + api_secret)

My guess is that mixpanel_client is simply not compatible with ruby 1.8.7 due to its use of the 'symbol' concept with hash tables.

I tried to upgrade to a newer version of ruby (2.0.0) on my mac using rvm, but it was fraught with openssl-related errors, so I gave up and removed (imploded) it and am back to stock 1.8.7.

Any suggestions are appreciated. Thanks very much for your time.

keolo commented 11 years ago

@jishaq I've run into those openssl errors before. They're a pain. I can't remember if mixpanel_client supports ruby 1.8.7 offhand (I'm planning to drop support for it soon). Maybe you'll have better luck with ruby 1.9.x? Let me know if you still have trouble.

jishaq commented 11 years ago

Thanks @keolo ; I gave up using rvm to install a more modern version of ruby on my mac because of the myriad weird errors I was getting.

Instead, I used brew from these instructions. It worked without any issues. After I installed brew, and did brew install ruby, I had ruby 2.0.0 on my mac. Then I updated my path to export PATH=/usr/local/opt/ruby/bin:${PATH} so it would see the brew-installed version of ruby (2.0) rather than Apple's stock 1.8.7 version. After all this, things look much better. The same usage example progresses to certificate failure, which I assume means I just need to plug in my actual mixpanel api token / secret and things might actually work!

macmini:Ruby jishaq$ ruby ./usageExample.rb
/usr/local/Cellar/ruby/2.0.0-p0/lib/ruby/2.0.0/net/http.rb:917:in `connect': SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (OpenSSL::SSL::SSLError)
keolo commented 11 years ago

Interesting that you got further using brew rather than rvm. RVM is pretty awesome. That error looks like the ssl certificate on your mac needs to be updated (which might also make the rvm installation work).

jishaq commented 11 years ago

Thanks for your suggestions; back to the point: closing this issue now - this seems simply to be a ruby 1.8.7 incompatibility.