Skip to content

Instantly share code, notes, and snippets.

@dliggat
Last active January 14, 2017 14:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dliggat/fb6c1d65f1e8bcfc765b to your computer and use it in GitHub Desktop.
Save dliggat/fb6c1d65f1e8bcfc765b to your computer and use it in GitHub Desktop.
Export data from Mixpanel
#!/usr/bin/env ruby
require 'active_support/time'
require 'digest'
API_KEY = 'YOUR KEY'
API_SECRET = 'YOUR SECRET'
args = {
'from_date' => Date.new(2014,9,1).iso8601,
'to_date' => Date.today.iso8601,
'api_key' => API_KEY,
'expire' => 15.minutes.from_now.utc.to_i
}
# Sort the args, and concat without a delimiter.
args = Hash[args.sort]
args_concat = args.map { |k, v| "#{k}=#{v}" }.join ''
# Create a signature using MD5(args_concat + API_SECRET).
md5 = Digest::MD5.new
md5 << args_concat
md5 << API_SECRET
# Add that into the arg hash.
args['sig'] = md5.hexdigest
# Generate the request URL.
url_params = args.map { |k, v| "#{k}=#{v}" }.join '&'
puts "https://data.mixpanel.com/api/2.0/export/?#{url_params}"
# Finally, curl that url and save to a file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment