Last active
January 14, 2017 14:41
-
-
Save dliggat/fb6c1d65f1e8bcfc765b to your computer and use it in GitHub Desktop.
Export data from Mixpanel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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