-
Notifications
You must be signed in to change notification settings - Fork 3
/
import.rb
42 lines (36 loc) · 933 Bytes
/
import.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require 'rubygems'
require 'base64'
require 'json'
require 'active_support'
require 'csv'
require 'uri'
require 'net/http'
module CSVToMixpanel
class Import
def initialize(file, token)
@token = token
@file = file
end
def perform!
CSV.foreach(@file, headers: true) do |row|
import_user(row)
end
end
def import_user(attributes)
puts "Importing attributes.inspect..."
params = {
'$set' => {
'$created' => attributes['created'],
'$email' => attributes['email'],
'$first_name' => attributes['first_name'],
'$last_name' => attributes['last_name']
},
'$token' => @token,
'$distinct_id' => attributes['id']
}
data = Base64.strict_encode64(JSON.generate(params))
request_uri = "http://api.mixpanel.com/engage/?data=#{data}"
Net::HTTP.get(URI(request_uri))
end
end
end