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/INSTALL +5 -5
- data/README.md +99 -99
- data/Rakefile +4 -4
- data/generators/{contextify → zenbox}/lib/insert_commands.rb +0 -0
- data/generators/{contextify → zenbox}/lib/rake_commands.rb +0 -0
- data/generators/{contextify → zenbox}/templates/initializer.rb +2 -2
- data/generators/{contextify/templates/contextify_tasks.rake → zenbox/templates/zenbox_tasks.rake} +7 -7
- data/generators/{contextify/contextify_generator.rb → zenbox/zenbox_generator.rb} +20 -20
- data/lib/rails/generators/{contextify/contextify_generator.rb → zenbox/zenbox_generator.rb} +21 -21
- data/lib/zenbox.rb +74 -1
- data/lib/{contextify → zenbox}/configuration.rb +7 -7
- data/lib/{contextify → zenbox}/rails.rb +4 -4
- data/lib/{contextify → zenbox}/railtie.rb +4 -4
- data/lib/{contextify → zenbox}/sender.rb +11 -11
- data/lib/{contextify → zenbox}/shared_tasks.rb +1 -1
- data/lib/zenbox/tasks.rb +50 -0
- data/lib/zenbox/user_helper.rb +39 -0
- data/lib/zenbox/version.rb +3 -0
- data/rails/init.rb +1 -1
- data/resources/README.md +3 -3
- data/{contextify.gemspec → zenbox.gemspec} +5 -5
- metadata +52 -56
- data/lib/contextify.rb +0 -74
- data/lib/contextify/tasks.rb +0 -50
- data/lib/contextify/user_helper.rb +0 -39
- data/lib/contextify/version.rb +0 -3
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
2
|
-
# Sends out the notice to
|
1
|
+
module Zenbox
|
2
|
+
# Sends out the notice to Zenbox
|
3
3
|
class Sender
|
4
4
|
|
5
|
-
CUSTOMERS_URI = '/customers'.freeze
|
5
|
+
CUSTOMERS_URI = '/customers.json'.freeze
|
6
6
|
HTTP_ERRORS = [Timeout::Error,
|
7
7
|
Errno::EINVAL,
|
8
8
|
Errno::ECONNRESET,
|
@@ -29,10 +29,10 @@ module Contextify
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
# Sends the customer data off to
|
32
|
+
# Sends the customer data off to Zenbox for processing.
|
33
33
|
#
|
34
34
|
# @param [String] data The JSON notice to be sent off
|
35
|
-
def
|
35
|
+
def send_to_zenbox(data)
|
36
36
|
http = setup_http_connection
|
37
37
|
|
38
38
|
# Set up POST request with formdata and headers
|
@@ -43,7 +43,7 @@ module Contextify
|
|
43
43
|
response = begin
|
44
44
|
http.request(request)
|
45
45
|
rescue *HTTP_ERRORS => e
|
46
|
-
log :error, "Timeout while contacting the
|
46
|
+
log :error, "Timeout while contacting the Zenbox server."
|
47
47
|
nil
|
48
48
|
end
|
49
49
|
|
@@ -57,7 +57,7 @@ module Contextify
|
|
57
57
|
end
|
58
58
|
|
59
59
|
rescue => e
|
60
|
-
log :error, "[
|
60
|
+
log :error, "[Zenbox::Sender#send_to_zenbox] Cannot send notification. Error: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
|
61
61
|
nil
|
62
62
|
end
|
63
63
|
|
@@ -84,11 +84,11 @@ module Contextify
|
|
84
84
|
|
85
85
|
def log(level, message, response = nil)
|
86
86
|
logger.send level, LOG_PREFIX + message if logger
|
87
|
-
|
87
|
+
Zenbox.report_response_body(response.body) if response && response.respond_to?(:body)
|
88
88
|
end
|
89
89
|
|
90
90
|
def logger
|
91
|
-
|
91
|
+
Zenbox.logger
|
92
92
|
end
|
93
93
|
|
94
94
|
def setup_http_connection
|
@@ -107,7 +107,7 @@ module Contextify
|
|
107
107
|
# else
|
108
108
|
# http.ca_file = Sender.local_cert_path # ca-bundle.crt built from source, see resources/README.md
|
109
109
|
# end
|
110
|
-
http.ca_file =
|
110
|
+
http.ca_file = Zenbox.configuration.ca_bundle_path
|
111
111
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
112
112
|
else
|
113
113
|
http.use_ssl = false
|
@@ -115,7 +115,7 @@ module Contextify
|
|
115
115
|
|
116
116
|
http
|
117
117
|
rescue => e
|
118
|
-
log :error, "[
|
118
|
+
log :error, "[Zenbox::Sender#setup_http_connection] Failure initializing the HTTP connection.\nError: #{e.class} - #{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
|
119
119
|
raise e
|
120
120
|
end
|
121
121
|
|
data/lib/zenbox/tasks.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'zenbox'
|
2
|
+
require File.join(File.dirname(__FILE__), 'shared_tasks')
|
3
|
+
|
4
|
+
namespace :zenbox do
|
5
|
+
desc "Verify your zenbox api_key by sending test data to the zenbox service"
|
6
|
+
task :test => :environment do
|
7
|
+
if defined?(RAILS_DEFAULT_LOGGER)
|
8
|
+
# Rails 2
|
9
|
+
RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
|
10
|
+
else
|
11
|
+
# Rails 3
|
12
|
+
Rails.logger = Logger.new(STDOUT)
|
13
|
+
Rails.logger.level = Logger::DEBUG
|
14
|
+
Zenbox.configure(true) do |config|
|
15
|
+
config.logger = Rails.logger
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
unless Zenbox.configuration.api_key
|
20
|
+
puts "Zenbox needs an API key configured! Check the README to see how to add it."
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
|
24
|
+
puts "\nPosting dummy data for 'test@example.com'...\n\n"
|
25
|
+
|
26
|
+
if Zenbox.post "test@example.com", {:test_data => 123}
|
27
|
+
puts "\nZenbox is set up and ready to use!"
|
28
|
+
else
|
29
|
+
puts "\nPlease check your Zenbox configuration or network settings."
|
30
|
+
end
|
31
|
+
puts
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Syncs all user data after the model has been marked. Can be run many times without any side-effects"
|
35
|
+
task :sync => :environment do
|
36
|
+
if Zenbox.model.nil?
|
37
|
+
puts "You must set a model to zenbox. Did you remember to user `zenbox_user :fields...` in your User model? "
|
38
|
+
return
|
39
|
+
end
|
40
|
+
|
41
|
+
model = Zenbox.model.constantize
|
42
|
+
|
43
|
+
puts "Syncing #{model.all.count} models with Zenbox..."
|
44
|
+
|
45
|
+
model.all.each do |model|
|
46
|
+
model.zenbox_sync!
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Zenbox
|
2
|
+
module UserHelper
|
3
|
+
def self.included(base)
|
4
|
+
base.extend(ClassMethods)
|
5
|
+
end
|
6
|
+
|
7
|
+
# TODO: Catch errors because of missing methods and prompt the
|
8
|
+
# user, "Tried to sync a non-existant method with
|
9
|
+
# zenbox. Please make sure to implement #{method_name} on your
|
10
|
+
# model"
|
11
|
+
def zenbox_sync!
|
12
|
+
Zenbox.post(self.email, zenbox_data)
|
13
|
+
end
|
14
|
+
|
15
|
+
def zenbox_data(*fields)
|
16
|
+
fields = fields.empty? ? self.class.class_variable_get('@@zenbox_fields') : fields
|
17
|
+
|
18
|
+
fields.inject({}) { |run, field| run[field] = self.send(field.to_sym); run }
|
19
|
+
end
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
def self.extended(base)
|
23
|
+
base.class_variable_set("@@zenbox_fields", [])
|
24
|
+
|
25
|
+
Zenbox.model = base.to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
def zenbox_fields=(*args)
|
29
|
+
self.class_variable_set("@@zenbox_fields", args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def zenbox_user(*fields)
|
33
|
+
self.send(:zenbox_fields=, *fields)
|
34
|
+
|
35
|
+
after_commit :zenbox_sync!
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/rails/init.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require '
|
1
|
+
require 'zenbox/rails'
|
data/resources/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
Zenbox Resources
|
2
2
|
====================
|
3
3
|
|
4
|
-
|
4
|
+
Zenbox has an SSL mode available.
|
5
5
|
SSL Certificate Authority (CA) certificates are not kept current by default on many environments.
|
6
|
-
When CA certs are stale,
|
6
|
+
When CA certs are stale, Zenbox cannot verify Zenbox's production SSL cert and POSTs fail.
|
7
7
|
To avoid this, we package local CA certs. The production of these certs is detailed here.
|
8
8
|
|
9
9
|
|
@@ -1,20 +1,20 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "
|
3
|
+
require "zenbox/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = %q{zenbox}
|
7
|
-
s.version =
|
8
|
-
s.summary = %q{Send your user information to our hosted service and
|
7
|
+
s.version = Zenbox::VERSION.dup
|
8
|
+
s.summary = %q{Send your user information to our hosted service and zenbox your inbox.}
|
9
9
|
|
10
10
|
s.require_paths = ["lib"]
|
11
11
|
s.files = Dir["{generators/**/*,lib/**/*,rails/**/*,resources/*,script/*}"] +
|
12
|
-
%w(
|
12
|
+
%w(zenbox.gemspec Gemfile INSTALL MIT-LICENSE Rakefile README.md install.rb)
|
13
13
|
s.test_files = Dir.glob("{test,spec,features}/**/*")
|
14
14
|
|
15
15
|
s.add_runtime_dependency("json")
|
16
16
|
|
17
|
-
s.authors = ["
|
17
|
+
s.authors = ["Zenbox"]
|
18
18
|
s.email = %q{support@cloudfuji.com}
|
19
19
|
s.homepage = "http://cloudfuji.com"
|
20
20
|
|
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: zenbox
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
4
5
|
prerelease:
|
5
|
-
version: 0.0.3
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
7
|
+
authors:
|
8
|
+
- Zenbox
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-06-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: json
|
17
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
26
30
|
description:
|
27
31
|
email: support@cloudfuji.com
|
28
32
|
executables: []
|
29
|
-
|
30
33
|
extensions: []
|
31
|
-
|
32
34
|
extra_rdoc_files: []
|
33
|
-
|
34
|
-
|
35
|
-
- generators/
|
36
|
-
- generators/
|
37
|
-
- generators/
|
38
|
-
- generators/
|
39
|
-
- generators/
|
40
|
-
- lib/
|
41
|
-
- lib/
|
42
|
-
- lib/
|
43
|
-
- lib/
|
44
|
-
- lib/
|
45
|
-
- lib/
|
46
|
-
- lib/
|
47
|
-
- lib/
|
48
|
-
- lib/contextify.rb
|
49
|
-
- lib/rails/generators/contextify/contextify_generator.rb
|
35
|
+
files:
|
36
|
+
- generators/zenbox/lib/insert_commands.rb
|
37
|
+
- generators/zenbox/lib/rake_commands.rb
|
38
|
+
- generators/zenbox/templates/initializer.rb
|
39
|
+
- generators/zenbox/templates/zenbox_tasks.rake
|
40
|
+
- generators/zenbox/zenbox_generator.rb
|
41
|
+
- lib/rails/generators/zenbox/zenbox_generator.rb
|
42
|
+
- lib/zenbox/configuration.rb
|
43
|
+
- lib/zenbox/rails.rb
|
44
|
+
- lib/zenbox/railtie.rb
|
45
|
+
- lib/zenbox/sender.rb
|
46
|
+
- lib/zenbox/shared_tasks.rb
|
47
|
+
- lib/zenbox/tasks.rb
|
48
|
+
- lib/zenbox/user_helper.rb
|
49
|
+
- lib/zenbox/version.rb
|
50
50
|
- lib/zenbox.rb
|
51
51
|
- rails/init.rb
|
52
52
|
- resources/ca-bundle.crt
|
53
53
|
- resources/README.md
|
54
|
-
-
|
54
|
+
- zenbox.gemspec
|
55
55
|
- Gemfile
|
56
56
|
- INSTALL
|
57
57
|
- MIT-LICENSE
|
@@ -60,36 +60,32 @@ files:
|
|
60
60
|
- install.rb
|
61
61
|
homepage: http://cloudfuji.com
|
62
62
|
licenses: []
|
63
|
-
|
64
63
|
post_install_message:
|
65
64
|
rdoc_options: []
|
66
|
-
|
67
|
-
require_paths:
|
65
|
+
require_paths:
|
68
66
|
- lib
|
69
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
68
|
none: false
|
71
|
-
requirements:
|
72
|
-
- -
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
segments:
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
segments:
|
76
74
|
- 0
|
77
|
-
|
78
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
hash: 4519474910494744129
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
77
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
83
|
-
|
84
|
-
segments:
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
segments:
|
85
83
|
- 0
|
86
|
-
|
84
|
+
hash: 4519474910494744129
|
87
85
|
requirements: []
|
88
|
-
|
89
86
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.8.
|
87
|
+
rubygems_version: 1.8.24
|
91
88
|
signing_key:
|
92
89
|
specification_version: 3
|
93
|
-
summary: Send your user information to our hosted service and
|
90
|
+
summary: Send your user information to our hosted service and zenbox your inbox.
|
94
91
|
test_files: []
|
95
|
-
|
data/lib/contextify.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'net/https'
|
3
|
-
require 'rubygems'
|
4
|
-
require 'contextify/version'
|
5
|
-
require 'contextify/configuration'
|
6
|
-
require 'contextify/sender'
|
7
|
-
require 'contextify/user_helper'
|
8
|
-
|
9
|
-
require 'contextify/railtie' if defined?(Rails::Railtie)
|
10
|
-
|
11
|
-
module Contextify
|
12
|
-
API_VERSION = "1.0"
|
13
|
-
LOG_PREFIX = "** [Contextify] "
|
14
|
-
|
15
|
-
class << self
|
16
|
-
# The sender object is responsible for delivering formatted data to the Contextify server.
|
17
|
-
# Must respond to #send_to_contextify. See Contextify::Sender.
|
18
|
-
attr_accessor :sender
|
19
|
-
|
20
|
-
# Names the Contextify model we should be watching. Set
|
21
|
-
# automatically when using contextify_user
|
22
|
-
attr_accessor :model
|
23
|
-
|
24
|
-
# A Contextify configuration object. Must act like a hash and return sensible
|
25
|
-
# values for all Contextify configuration options. See Contextify::Configuration.
|
26
|
-
attr_writer :configuration
|
27
|
-
|
28
|
-
# Prints out the response body from Contextify for debugging help
|
29
|
-
def report_response_body(response)
|
30
|
-
write_verbose_log("Response from Contextify: \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
|
-
# Contextify.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 Contextify.configure
|
57
|
-
def configuration
|
58
|
-
@configuration ||= Configuration.new
|
59
|
-
end
|
60
|
-
|
61
|
-
# Sends data to contextify
|
62
|
-
#
|
63
|
-
# @param [String] email The email address you want to send data about.
|
64
|
-
# @param [Hash] opts Data that will be sent to Contextify.
|
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_contextify(post_data)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/lib/contextify/tasks.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'contextify'
|
2
|
-
require File.join(File.dirname(__FILE__), 'shared_tasks')
|
3
|
-
|
4
|
-
namespace :contextify do
|
5
|
-
desc "Verify your contextify api_key by sending test data to the contextify service"
|
6
|
-
task :test => :environment do
|
7
|
-
if defined?(RAILS_DEFAULT_LOGGER)
|
8
|
-
# Rails 2
|
9
|
-
RAILS_DEFAULT_LOGGER.level = Logger::DEBUG
|
10
|
-
else
|
11
|
-
# Rails 3
|
12
|
-
Rails.logger = Logger.new(STDOUT)
|
13
|
-
Rails.logger.level = Logger::DEBUG
|
14
|
-
Contextify.configure(true) do |config|
|
15
|
-
config.logger = Rails.logger
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
unless Contextify.configuration.api_key
|
20
|
-
puts "Contextify needs an API key configured! Check the README to see how to add it."
|
21
|
-
exit
|
22
|
-
end
|
23
|
-
|
24
|
-
puts "\nPosting dummy data for 'test@example.com'...\n\n"
|
25
|
-
|
26
|
-
if Contextify.post "test@example.com", {:test_data => 123}
|
27
|
-
puts "\nContextify is set up and ready to use!"
|
28
|
-
else
|
29
|
-
puts "\nPlease check your Contextify configuration or network settings."
|
30
|
-
end
|
31
|
-
puts
|
32
|
-
end
|
33
|
-
|
34
|
-
desc "Syncs all user data after the model has been marked. Can be run many times without any side-effects"
|
35
|
-
task :sync => :environment do
|
36
|
-
if Contextify.model.nil?
|
37
|
-
puts "You must set a model to contextify. Did you remember to user `contextify_user :fields...` in your User model? "
|
38
|
-
return
|
39
|
-
end
|
40
|
-
|
41
|
-
model = Contextify.model.constantize
|
42
|
-
|
43
|
-
puts "Syncing #{model.all.count} models with Contextify..."
|
44
|
-
|
45
|
-
model.all.each do |model|
|
46
|
-
model.contextify_sync!
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|