diff --git a/lib/mixpanel-ruby/consumer.rb b/lib/mixpanel-ruby/consumer.rb index f5ce029..435ba1a 100644 --- a/lib/mixpanel-ruby/consumer.rb +++ b/lib/mixpanel-ruby/consumer.rb @@ -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 @@ -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 @@ -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) @@ -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