Module: Zenbox

Defined in:
lib/zenbox.rb,
lib/zenbox/rails.rb,
lib/zenbox/sender.rb,
lib/zenbox/railtie.rb,
lib/zenbox/version.rb,
lib/zenbox/user_helper.rb,
lib/zenbox/configuration.rb

Defined Under Namespace

Modules: Rails, UserHelper Classes: Configuration, Railtie, Sender

Constant Summary collapse

API_VERSION =
"1.0"
LOG_PREFIX =
"** [Zenbox] "
VERSION =
"0.0.8"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

The configuration object.

See Also:



57
58
59
# File 'lib/zenbox.rb', line 57

def configuration
  @configuration ||= Configuration.new
end

.modelObject

Names the Zenbox model we should be watching. Set automatically when using zenbox_user



22
23
24
# File 'lib/zenbox.rb', line 22

def model
  @model
end

.senderObject

The sender object is responsible for delivering formatted data to the Zenbox server. Must respond to #send_to_zenbox. See Zenbox::Sender.



18
19
20
# File 'lib/zenbox.rb', line 18

def sender
  @sender
end

Class Method Details

.configure(silent = false) {|configuration| ... } ⇒ Object

Call this method to modify defaults in your initializers.

Examples:

Zenbox.configure do |config|
  config.api_key = '1234567890abcdef'
  config.secure  = false
end

Yields:



50
51
52
53
# File 'lib/zenbox.rb', line 50

def configure(silent = false)
  yield(configuration)
  self.sender = Sender.new(configuration)
end

.loggerObject

Look for the Rails logger currently defined



39
40
41
# File 'lib/zenbox.rb', line 39

def logger
  self.configuration.logger
end

.post(email, data) ⇒ Object

Sends data to zenbox

Parameters:

  • email (String)

    The email address you want to send data about.

  • opts (Hash)

    Data that will be sent to Zenbox.



65
66
67
68
69
70
71
72
# File 'lib/zenbox.rb', line 65

def post(email, data)
  post_data = {
    :api_key => configuration.api_key,
    :email      => email,
    :data       => data.to_json
  }
  sender.send_to_zenbox(post_data)
end

.report_response_body(response) ⇒ Object

Prints out the response body from Zenbox for debugging help



29
30
31
# File 'lib/zenbox.rb', line 29

def report_response_body(response)
  write_verbose_log("Response from Zenbox: \n#{response}")
end

.write_verbose_log(message) ⇒ Object

Writes out the given message to the #logger



34
35
36
# File 'lib/zenbox.rb', line 34

def write_verbose_log(message)
  logger.info LOG_PREFIX + message if logger
end