Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/mixpanel-ruby/consumer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module Mixpanel
@@init_http = nil
@@init_http_request = nil

# This method exists for backwards compatibility. The preferred
# way to customize or configure the HTTP library of a consumer
Expand All @@ -26,6 +27,20 @@ def self.config_http(&block)
@@init_http = block
end

# This method exists as a doorway to configure the http request object,
# necessary to use the import method, which is dependant on
# your API SECRET in basic_auth
#
# Mixpanel.config_http_request do |http_request|
# http_request.basic_auth "'#{ENV['MIXPANEL_API_SECRET']}'", ''
# end
#
# \Mixpanel Consumer and BufferedConsumer will call your block
# to configure the http request
def self.config_http_request(&block)
@@init_http_request = block
end

# A Consumer receives messages from a Mixpanel::Tracker, and
# sends them elsewhere- probably to Mixpanel's analytics services,
# but can also enqueue them for later processing, log them to a
Expand Down Expand Up @@ -121,6 +136,7 @@ def send(type, message)
def request(endpoint, form_data)
uri = URI(endpoint)
request = Net::HTTP::Post.new(uri.request_uri)
Mixpanel.with_http_request(request)
request.set_form_data(form_data)

client = Net::HTTP.new(uri.host, uri.port)
Expand Down Expand Up @@ -240,4 +256,10 @@ def self.with_http(http)
@@init_http.call(http)
end
end

def self.with_http_request(http_request)
if @@init_http_request
@@init_http_request.call(http_request)
end
end
end