zenbox 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Rakefile CHANGED
@@ -4,13 +4,13 @@ require 'rubygems/package_task'
4
4
  require 'bundler'
5
5
  Bundler::GemHelper.install_tasks
6
6
 
7
- require './lib/contextify/version'
7
+ require './lib/zenbox/version'
8
8
 
9
9
  namespace :changeling do
10
10
  desc "Bumps the version by a minor or patch version, depending on what was passed in."
11
11
  task :bump, :part do |t, args|
12
12
  # Thanks, Jeweler!
13
- if Contextify::VERSION =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
13
+ if Zenbox::VERSION =~ /^(\d+)\.(\d+)\.(\d+)(?:\.(.*?))?$/
14
14
  major = $1.to_i
15
15
  minor = $2.to_i
16
16
  patch = $3.to_i
@@ -31,9 +31,9 @@ namespace :changeling do
31
31
 
32
32
  version = [major, minor, patch, build].compact.join('.')
33
33
 
34
- File.open(File.join("lib", "contextify", "version.rb"), "w") do |f|
34
+ File.open(File.join("lib", "zenbox", "version.rb"), "w") do |f|
35
35
  f.write <<EOF
36
- module Contextify
36
+ module Zenbox
37
37
  VERSION = "#{version}".freeze
38
38
  end
39
39
  EOF
@@ -1,6 +1,6 @@
1
1
  <% if Rails::VERSION::MAJOR < 3 && Rails::VERSION::MINOR < 2 -%>
2
- require 'contextify/rails'
2
+ require 'zenbox/rails'
3
3
  <% end -%>
4
- Contextify.configure do |config|
4
+ Zenbox.configure do |config|
5
5
  config.api_key = <%= api_key_expression %>
6
6
  end
@@ -1,21 +1,21 @@
1
1
  # Don't load anything when running the gems:* tasks.
2
- # Otherwise, contextify will be considered a framework gem.
2
+ # Otherwise, zenbox will be considered a framework gem.
3
3
  # https://thoughtbot.lighthouseapp.com/projects/14221/tickets/629
4
4
  unless ARGV.any? {|a| a =~ /^gems/}
5
5
 
6
- Dir[File.join(Rails.root, 'vendor', 'gems', 'contextify-*')].each do |vendored_notifier|
6
+ Dir[File.join(Rails.root, 'vendor', 'gems', 'zenbox-*')].each do |vendored_notifier|
7
7
  $: << File.join(vendored_notifier, 'lib')
8
8
  end
9
9
 
10
10
  begin
11
- require 'contextify/tasks'
11
+ require 'zenbox/tasks'
12
12
  rescue LoadError => exception
13
- namespace :contextify do
13
+ namespace :zenbox do
14
14
  %w(deploy test log_stdout).each do |task_name|
15
- desc "Missing dependency for contextify:#{task_name}"
15
+ desc "Missing dependency for zenbox:#{task_name}"
16
16
  task task_name do
17
- $stderr.puts "Failed to run contextify:#{task_name} because of missing dependency."
18
- $stderr.puts "You probably need to run `rake gems:install` to install the contextify gem"
17
+ $stderr.puts "Failed to run zenbox:#{task_name} because of missing dependency."
18
+ $stderr.puts "You probably need to run `rake gems:install` to install the zenbox gem"
19
19
  abort exception.inspect
20
20
  end
21
21
  end
@@ -1,35 +1,35 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/lib/insert_commands.rb")
2
2
  require File.expand_path(File.dirname(__FILE__) + "/lib/rake_commands.rb")
3
3
 
4
- class ContextifyGenerator < Rails::Generator::Base
4
+ class ZenboxGenerator < Rails::Generator::Base
5
5
  def add_options!(opt)
6
- opt.on('-k', '--api-key=token', String, "Your Contextify API key") { |v| options[:api_key] = v}
7
- opt.on('-h', '--heroku', "Use the Heroku addon to provide your Contextify API key") { |v| options[:heroku] = v}
6
+ opt.on('-k', '--api-key=token', String, "Your Zenbox API key") { |v| options[:api_key] = v}
7
+ opt.on('-h', '--heroku', "Use the Heroku addon to provide your Zenbox API key") { |v| options[:heroku] = v}
8
8
  opt.on('-a', '--app=myapp', String, "Your Heroku app name (only required if deploying to >1 Heroku app)") { |v| options[:app] = v}
9
9
  end
10
10
 
11
11
  def manifest
12
12
  if !api_key_configured? && !options[:api_key] && !options[:heroku]
13
- puts "Must pass --api-key or --heroku or create config/initializers/contextify.rb"
13
+ puts "Must pass --api-key or --heroku or create config/initializers/zenbox.rb"
14
14
  exit
15
15
  end
16
16
 
17
17
  record do |m|
18
18
  m.directory 'lib/tasks'
19
- m.file 'contextify_tasks.rake', 'lib/tasks/contextify_tasks.rake'
19
+ m.file 'zenbox_tasks.rake', 'lib/tasks/zenbox_tasks.rake'
20
20
 
21
21
  if api_key_expression
22
22
  if use_initializer?
23
- m.template 'initializer.rb', 'config/initializers/contextify.rb',
23
+ m.template 'initializer.rb', 'config/initializers/zenbox.rb',
24
24
  :assigns => {:api_key => api_key_expression}
25
25
  else
26
- m.template 'initializer.rb', 'config/contextify.rb',
26
+ m.template 'initializer.rb', 'config/zenbox.rb',
27
27
  :assigns => {:api_key => api_key_expression}
28
- m.append_to 'config/environment.rb', "require 'config/contextify'"
28
+ m.append_to 'config/environment.rb', "require 'config/zenbox'"
29
29
  end
30
30
  end
31
31
  determine_api_key if heroku?
32
- m.rake "contextify:test --trace", :generate_only => true
32
+ m.rake "zenbox:test --trace", :generate_only => true
33
33
  end
34
34
  end
35
35
 
@@ -37,21 +37,21 @@ class ContextifyGenerator < Rails::Generator::Base
37
37
  s = if options[:api_key]
38
38
  "'#{options[:api_key]}'"
39
39
  elsif options[:heroku]
40
- "ENV['CONTEXTIFY_API_KEY']"
40
+ "ENV['ZENBOX_API_KEY']"
41
41
  end
42
42
  end
43
43
 
44
44
  def determine_api_key
45
45
  puts "Attempting to determine your API key from Heroku..."
46
- ENV['CONTEXTIFY_API_KEY'] = heroku_api_key
47
- if ENV['CONTEXTIFY_API_KEY'].blank?
46
+ ENV['ZENBOX_API_KEY'] = heroku_api_key
47
+ if ENV['ZENBOX_API_KEY'].blank?
48
48
  puts "... Failed."
49
- puts "WARNING: We were unable to detect the Contextify API key from your Heroku environment."
49
+ puts "WARNING: We were unable to detect the Zenbox API key from your Heroku environment."
50
50
  puts "Your Heroku application environment may not be configured correctly."
51
51
  exit 1
52
52
  else
53
53
  puts "... Done."
54
- puts "Heroku's Contextify API key is '#{ENV['CONTEXTIFY_API_KEY']}'"
54
+ puts "Heroku's Zenbox API key is '#{ENV['ZENBOX_API_KEY']}'"
55
55
  end
56
56
  end
57
57
 
@@ -61,13 +61,13 @@ class ContextifyGenerator < Rails::Generator::Base
61
61
  end
62
62
 
63
63
  def heroku_api_key
64
- heroku_var("contextify_api_key",options[:app]).split.find {|x| x unless x.blank?}
64
+ heroku_var("zenbox_api_key",options[:app]).split.find {|x| x unless x.blank?}
65
65
  end
66
66
 
67
67
  def heroku?
68
68
  options[:heroku] ||
69
- system("grep CONTEXTIFY_API_KEY config/initializers/contextify.rb") ||
70
- system("grep CONTEXTIFY_API_KEY config/environment.rb")
69
+ system("grep ZENBOX_API_KEY config/initializers/zenbox.rb") ||
70
+ system("grep ZENBOX_API_KEY config/environment.rb")
71
71
  end
72
72
 
73
73
  def use_initializer?
@@ -75,11 +75,11 @@ class ContextifyGenerator < Rails::Generator::Base
75
75
  end
76
76
 
77
77
  def api_key_configured?
78
- File.exists?('config/initializers/contextify.rb') ||
79
- system("grep Contextify config/environment.rb")
78
+ File.exists?('config/initializers/zenbox.rb') ||
79
+ system("grep Zenbox config/environment.rb")
80
80
  end
81
81
 
82
82
  def plugin_is_present?
83
- File.exists?('vendor/plugins/contextify')
83
+ File.exists?('vendor/plugins/zenbox')
84
84
  end
85
85
  end
@@ -1,13 +1,13 @@
1
1
  require 'rails/generators'
2
2
 
3
- class ContextifyGenerator < Rails::Generators::Base
3
+ class ZenboxGenerator < Rails::Generators::Base
4
4
 
5
- class_option :api_key, :aliases => "-k", :type => :string, :desc => "Your Contextify API key"
6
- class_option :heroku, :type => :boolean, :desc => "Use the Heroku addon to provide your Contextify API key"
5
+ class_option :api_key, :aliases => "-k", :type => :string, :desc => "Your Zenbox API key"
6
+ class_option :heroku, :type => :boolean, :desc => "Use the Heroku addon to provide your Zenbox API key"
7
7
  class_option :app, :aliases => "-a", :type => :string, :desc => "Your Heroku app name (only required if deploying to >1 Heroku app)"
8
8
 
9
9
  def self.source_root
10
- @_contextify_source_root ||= File.expand_path("../../../../../generators/contextify/templates", __FILE__)
10
+ @_zenbox_source_root ||= File.expand_path("../../../../../generators/zenbox/templates", __FILE__)
11
11
  end
12
12
 
13
13
  def install
@@ -16,21 +16,21 @@ class ContextifyGenerator < Rails::Generators::Base
16
16
  append_capistrano_hook
17
17
  generate_initializer unless api_key_configured?
18
18
  determine_api_key if heroku?
19
- test_contextify
19
+ test_zenbox
20
20
  end
21
21
 
22
22
  private
23
23
 
24
24
  def ensure_api_key_was_configured
25
25
  if !options[:api_key] && !options[:heroku] && !api_key_configured?
26
- puts "Must pass --api-key or --heroku or create config/initializers/contextify.rb"
26
+ puts "Must pass --api-key or --heroku or create config/initializers/zenbox.rb"
27
27
  exit
28
28
  end
29
29
  end
30
30
 
31
31
  def ensure_plugin_is_not_present
32
32
  if plugin_is_present?
33
- puts "You must first remove the contextify plugin. Please run: script/plugin remove contextify"
33
+ puts "You must first remove the zenbox plugin. Please run: script/plugin remove zenbox"
34
34
  exit
35
35
  end
36
36
  end
@@ -40,7 +40,7 @@ class ContextifyGenerator < Rails::Generators::Base
40
40
  append_file('config/deploy.rb', <<-HOOK)
41
41
 
42
42
  require './config/boot'
43
- require 'contextify/capistrano'
43
+ require 'zenbox/capistrano'
44
44
  HOOK
45
45
  end
46
46
  end
@@ -49,25 +49,25 @@ class ContextifyGenerator < Rails::Generators::Base
49
49
  s = if options[:api_key]
50
50
  "'#{options[:api_key]}'"
51
51
  elsif options[:heroku]
52
- "ENV['CONTEXTIFY_API_KEY']"
52
+ "ENV['ZENBOX_API_KEY']"
53
53
  end
54
54
  end
55
55
 
56
56
  def generate_initializer
57
- template 'initializer.rb', 'config/initializers/contextify.rb'
57
+ template 'initializer.rb', 'config/initializers/zenbox.rb'
58
58
  end
59
59
 
60
60
  def determine_api_key
61
61
  puts "Attempting to determine your API key from Heroku..."
62
- ENV['CONTEXTIFY_API_KEY'] = heroku_api_key
63
- if ENV['CONTEXTIFY_API_KEY'].blank?
62
+ ENV['ZENBOX_API_KEY'] = heroku_api_key
63
+ if ENV['ZENBOX_API_KEY'].blank?
64
64
  puts "... Failed."
65
- puts "WARNING: We were unable to detect the Contextify API key from your Heroku environment."
65
+ puts "WARNING: We were unable to detect the Zenbox API key from your Heroku environment."
66
66
  puts "Your Heroku application environment may not be configured correctly."
67
67
  exit 1
68
68
  else
69
69
  puts "... Done."
70
- puts "Heroku's Contextify API key is '#{ENV['CONTEXTIFY_API_KEY']}'"
70
+ puts "Heroku's Zenbox API key is '#{ENV['ZENBOX_API_KEY']}'"
71
71
  end
72
72
  end
73
73
 
@@ -77,24 +77,24 @@ class ContextifyGenerator < Rails::Generators::Base
77
77
  end
78
78
 
79
79
  def heroku_api_key
80
- heroku_var("contextify_api_key",options[:app]).split.find {|x| x unless x.blank?}
80
+ heroku_var("zenbox_api_key",options[:app]).split.find {|x| x unless x.blank?}
81
81
  end
82
82
 
83
83
  def heroku?
84
84
  options[:heroku] ||
85
- system("grep CONTEXTIFY_API_KEY config/initializers/contextify.rb") ||
86
- system("grep CONTEXTIFY_API_KEY config/environment.rb")
85
+ system("grep ZENBOX_API_KEY config/initializers/zenbox.rb") ||
86
+ system("grep ZENBOX_API_KEY config/environment.rb")
87
87
  end
88
88
 
89
89
  def api_key_configured?
90
- File.exists?('config/initializers/contextify.rb')
90
+ File.exists?('config/initializers/zenbox.rb')
91
91
  end
92
92
 
93
- def test_contextify
94
- run("rake contextify:test --trace")
93
+ def test_zenbox
94
+ run("rake zenbox:test --trace")
95
95
  end
96
96
 
97
97
  def plugin_is_present?
98
- File.exists?('vendor/plugins/contextify')
98
+ File.exists?('vendor/plugins/zenbox')
99
99
  end
100
100
  end
data/lib/zenbox.rb CHANGED
@@ -1 +1,74 @@
1
- require 'contextify'
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'rubygems'
4
+ require 'zenbox/version'
5
+ require 'zenbox/configuration'
6
+ require 'zenbox/sender'
7
+ require 'zenbox/user_helper'
8
+
9
+ require 'zenbox/railtie' if defined?(Rails::Railtie)
10
+
11
+ module Zenbox
12
+ API_VERSION = "1.0"
13
+ LOG_PREFIX = "** [Zenbox] "
14
+
15
+ class << self
16
+ # The sender object is responsible for delivering formatted data to the Zenbox server.
17
+ # Must respond to #send_to_zenbox. See Zenbox::Sender.
18
+ attr_accessor :sender
19
+
20
+ # Names the Zenbox model we should be watching. Set
21
+ # automatically when using zenbox_user
22
+ attr_accessor :model
23
+
24
+ # A Zenbox configuration object. Must act like a hash and return sensible
25
+ # values for all Zenbox configuration options. See Zenbox::Configuration.
26
+ attr_writer :configuration
27
+
28
+ # Prints out the response body from Zenbox for debugging help
29
+ def report_response_body(response)
30
+ write_verbose_log("Response from Zenbox: \n#{response}")
31
+ end
32
+
33
+ # Writes out the given message to the #logger
34
+ def write_verbose_log(message)
35
+ logger.info LOG_PREFIX + message if logger
36
+ end
37
+
38
+ # Look for the Rails logger currently defined
39
+ def logger
40
+ self.configuration.logger
41
+ end
42
+
43
+ # Call this method to modify defaults in your initializers.
44
+ #
45
+ # @example
46
+ # Zenbox.configure do |config|
47
+ # config.api_key = '1234567890abcdef'
48
+ # config.secure = false
49
+ # end
50
+ def configure(silent = false)
51
+ yield(configuration)
52
+ self.sender = Sender.new(configuration)
53
+ end
54
+
55
+ # The configuration object.
56
+ # @see Zenbox.configure
57
+ def configuration
58
+ @configuration ||= Configuration.new
59
+ end
60
+
61
+ # Sends data to zenbox
62
+ #
63
+ # @param [String] email The email address you want to send data about.
64
+ # @param [Hash] opts Data that will be sent to Zenbox.
65
+ def post(email, data)
66
+ post_data = {
67
+ :api_key => configuration.api_key,
68
+ :email => email,
69
+ :data => data.to_json
70
+ }
71
+ sender.send_to_zenbox(post_data)
72
+ end
73
+ end
74
+ end
@@ -1,4 +1,4 @@
1
- module Contextify
1
+ module Zenbox
2
2
  # Used to set up and modify settings for the notifier.
3
3
  class Configuration
4
4
 
@@ -7,20 +7,20 @@ module Contextify
7
7
  :use_system_ssl_cert_chain].freeze
8
8
 
9
9
 
10
- # The API key for your Contextify account.
10
+ # The API key for your Zenbox account.
11
11
  attr_accessor :api_key
12
12
 
13
- # The host to connect to (defaults to contextify.me).
13
+ # The host to connect to (defaults to zenbox.me).
14
14
  attr_accessor :host
15
15
 
16
- # The port on which your Contextify server runs (defaults to 443 for secure
16
+ # The port on which your Zenbox server runs (defaults to 443 for secure
17
17
  # connections, 80 for insecure connections).
18
18
  attr_accessor :port
19
19
 
20
20
  # +true+ for https connections, +false+ for http connections.
21
21
  attr_accessor :secure
22
22
 
23
- # +true+ to use whatever CAs OpenSSL has installed on your system. +false+ to use the ca-bundle.crt file included in Contextify itself (recommended and default)
23
+ # +true+ to use whatever CAs OpenSSL has installed on your system. +false+ to use the ca-bundle.crt file included in Zenbox itself (recommended and default)
24
24
  attr_accessor :use_system_ssl_cert_chain
25
25
 
26
26
  # The HTTP open timeout in seconds (defaults to 2).
@@ -41,7 +41,7 @@ module Contextify
41
41
  # The password to use when logging into your proxy server (if using a proxy)
42
42
  attr_accessor :proxy_pass
43
43
 
44
- # The logger used by Contextify
44
+ # The logger used by Zenbox
45
45
  attr_accessor :logger
46
46
 
47
47
  alias_method :secure?, :secure
@@ -50,7 +50,7 @@ module Contextify
50
50
  def initialize
51
51
  @secure = false
52
52
  @use_system_ssl_cert_chain= false
53
- @host = 'contextify.me'
53
+ @host = 'zenbox.me'
54
54
  @http_open_timeout = 2
55
55
  @http_read_timeout = 5
56
56
  end
@@ -1,6 +1,6 @@
1
- require 'contextify'
1
+ require 'zenbox'
2
2
 
3
- module Contextify
3
+ module Zenbox
4
4
  module Rails
5
5
  def self.initialize
6
6
  rails_logger = if defined?(::Rails.logger)
@@ -9,11 +9,11 @@ module Contextify
9
9
  RAILS_DEFAULT_LOGGER
10
10
  end
11
11
 
12
- Contextify.configure(true) do |config|
12
+ Zenbox.configure(true) do |config|
13
13
  config.logger = rails_logger
14
14
  end
15
15
  end
16
16
  end
17
17
  end
18
18
 
19
- Contextify::Rails.initialize
19
+ Zenbox::Rails.initialize
@@ -1,14 +1,14 @@
1
- require 'contextify'
1
+ require 'zenbox'
2
2
  require 'rails'
3
3
 
4
- module Contextify
4
+ module Zenbox
5
5
  class Railtie < ::Rails::Railtie
6
6
  rake_tasks do
7
- require "contextify/tasks"
7
+ require "zenbox/tasks"
8
8
  end
9
9
 
10
10
  config.after_initialize do
11
- Contextify.configure(true) do |config|
11
+ Zenbox.configure(true) do |config|
12
12
  config.logger ||= ::Rails.logger
13
13
  end
14
14
  end