require 'net/http' require 'net/https' require 'rubygems' require 'zenbox/version' require 'zenbox/configuration' require 'zenbox/sender' require 'zenbox/user_helper' require 'zenbox/railtie' if defined?(Rails::Railtie) module Zenbox API_VERSION = "1.0" LOG_PREFIX = "** [Zenbox] " class << self # The sender object is responsible for delivering formatted data to the Zenbox server. # Must respond to #send_to_zenbox. See Zenbox::Sender. attr_accessor :sender # Names the Zenbox model we should be watching. Set # automatically when using zenbox_user attr_accessor :model # A Zenbox configuration object. Must act like a hash and return sensible # values for all Zenbox configuration options. See Zenbox::Configuration. attr_writer :configuration # Prints out the response body from Zenbox for debugging help def report_response_body(response) write_verbose_log("Response from Zenbox: \n#{response}") end # Writes out the given message to the #logger def write_verbose_log(message) logger.info LOG_PREFIX + message if logger end # Look for the Rails logger currently defined def logger self.configuration.logger end # Call this method to modify defaults in your initializers. # # @example # Zenbox.configure do |config| # config.api_key = '1234567890abcdef' # config.secure = false # end def configure(silent = false) yield(configuration) self.sender = Sender.new(configuration) end # The configuration object. # @see Zenbox.configure def configuration @configuration ||= Configuration.new end # Sends data to zenbox # # @param [String] email The email address you want to send data about. # @param [Hash] opts Data that will be sent to Zenbox. def post(email, data) post_data = { :api_key => configuration.api_key, :email => email, :data => data.to_json } sender.send_to_zenbox(post_data) end end end