happyfunjuice 0.0.1.beta.1
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 +38 -0
- data/app/controllers/happyfunjuice/happyfunjuice_controller.rb +51 -0
- data/app/controllers/newsletter_signups_controller.rb +23 -0
- data/lib/generators/happyfunjuice/install_generator.rb +47 -0
- data/lib/generators/happyfunjuice/js_generator.rb +22 -0
- data/lib/generators/happyfunjuice/landing_page_generator.rb +90 -0
- data/lib/generators/happyfunjuice/migrations/create_newsletter_signups.rb +10 -0
- data/lib/generators/happyfunjuice/templates/app/assets/javascripts/happyfunjuice.js +33 -0
- data/lib/generators/happyfunjuice/templates/app/assets/javascripts/landing_page.js +0 -0
- data/lib/generators/happyfunjuice/templates/app/assets/stylesheets/landing_page.css.scss +0 -0
- data/lib/generators/happyfunjuice/templates/app/models/newsletter_signup.rb +71 -0
- data/lib/generators/happyfunjuice/templates/app/views/layouts/landing_page.html.haml +19 -0
- data/lib/generators/happyfunjuice/templates/app/views/newsletter_signups/new.html.haml +13 -0
- data/lib/generators/happyfunjuice/templates/config/initializers/happyfunjuice.rb.erb +32 -0
- data/lib/happyfunjuice/activity.rb +102 -0
- data/lib/happyfunjuice/config.rb +64 -0
- data/lib/happyfunjuice/engine.rb +8 -0
- data/lib/happyfunjuice/notifications.rb +14 -0
- data/lib/happyfunjuice/routes.rb +37 -0
- data/lib/happyfunjuice/version.rb +10 -0
- data/lib/happyfunjuice.rb +26 -0
- metadata +84 -0
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Happyfunjuice'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
|
30
|
+
Rake::TestTask.new(:test) do |t|
|
31
|
+
t.libs << 'lib'
|
32
|
+
t.libs << 'test'
|
33
|
+
t.pattern = 'test/**/*_test.rb'
|
34
|
+
t.verbose = false
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
task :default => :test
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class Happyfunjuice::HappyfunjuiceController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :verify_key
|
4
|
+
|
5
|
+
def activities
|
6
|
+
|
7
|
+
begin
|
8
|
+
activity = params[:activity]
|
9
|
+
|
10
|
+
render :json=> {
|
11
|
+
activities: Happyfunjuice.activities(
|
12
|
+
page: params[:page],
|
13
|
+
per_page: params[:per_page],
|
14
|
+
type: params[:activity],
|
15
|
+
include_metadata: false
|
16
|
+
)
|
17
|
+
}.merge({:status=>'200'})
|
18
|
+
|
19
|
+
rescue StandardError => e
|
20
|
+
render :json=>{:status=>'500', :error=>e.message}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def metadata
|
26
|
+
|
27
|
+
begin
|
28
|
+
render :json => {
|
29
|
+
activities: Happyfunjuice.activities(
|
30
|
+
query_activities: false,
|
31
|
+
type: params[:activity]
|
32
|
+
)
|
33
|
+
}.merge({:status=>'200'})
|
34
|
+
|
35
|
+
rescue StandardError => e
|
36
|
+
render :json=>{:status=>'500', :error=>e.message}
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def verify_key
|
45
|
+
unless (Happyfunjuice.api_key == params[:api_key] )
|
46
|
+
render :json=>{:status=>'403', :error=>'Access Denied'}
|
47
|
+
return
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
class NewsletterSignupsController < ApplicationController
|
4
|
+
|
5
|
+
layout 'landing_page'
|
6
|
+
|
7
|
+
def new
|
8
|
+
@newsletter_signup = NewsletterSignup.new
|
9
|
+
@newsletter_signup.attributes = session.delete(:newsletter_signup_params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
@newsletter_signup = NewsletterSignup.new(params[:newsletter_signup])
|
14
|
+
|
15
|
+
if @newsletter_signup.save
|
16
|
+
redirect_to root_path, :flash=>{:notice=>'Thank you!'}
|
17
|
+
else
|
18
|
+
session[:newsletter_signup_params] = params[:newsletter_signup]
|
19
|
+
redirect_to root_path, :flash=>{:error=>@newsletter_signup.errors.full_messages}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Happyfunjuice
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
desc "Installs Happyfunjuice"
|
7
|
+
|
8
|
+
class_option :api_key, :type => :string, :required=>true, :desc=>'HappyFunJuice API key'
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def source_root
|
13
|
+
@_source_root ||= File.expand_path("../templates", __FILE__)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_config
|
19
|
+
@api_key = options[:api_key]
|
20
|
+
template 'config/initializers/happyfunjuice.rb.erb', 'config/initializers/happyfunjuice.rb'
|
21
|
+
end
|
22
|
+
|
23
|
+
def insert_routes
|
24
|
+
|
25
|
+
# Indentation is a little finicky here:
|
26
|
+
inject_into_file 'config/routes.rb', <<-END, :after=>'::Application.routes.draw do'
|
27
|
+
|
28
|
+
|
29
|
+
happyfunjuice do
|
30
|
+
activities
|
31
|
+
# landing_page
|
32
|
+
end
|
33
|
+
END
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
# def create_migrations
|
38
|
+
# Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
|
39
|
+
# name = File.basename(filepath)
|
40
|
+
# migration_template "migrations/#{name}", "db/migrate/#{name.gsub(/^\d+_/,'')}"
|
41
|
+
# sleep 1
|
42
|
+
# end
|
43
|
+
# end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rails/generators/base'
|
2
|
+
|
3
|
+
module Happyfunjuice
|
4
|
+
module Generators
|
5
|
+
class JsGenerator < Rails::Generators::Base
|
6
|
+
desc "Installs javascript for client-side instrumentation."
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def source_root
|
11
|
+
@_source_root ||= File.expand_path("../templates", __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def install_js
|
17
|
+
copy_file 'app/assets/javascripts/happyfunjuice.js'
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module Happyfunjuice
|
4
|
+
module Generators
|
5
|
+
class LandingPageGenerator < ActiveRecord::Generators::Base
|
6
|
+
desc "Generates a landing page with sendgrid or mailchimp signup"
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def source_root
|
11
|
+
@_source_root ||= File.expand_path("../templates", __FILE__)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
argument :mailer, :type => :string, :default => "sendgrid"
|
17
|
+
|
18
|
+
|
19
|
+
def activate_landing_page_route
|
20
|
+
uncomment_lines 'config/routes.rb', /landing_page/
|
21
|
+
end
|
22
|
+
|
23
|
+
def install_views
|
24
|
+
copy_file 'app/views/newsletter_signups/new.html.haml'
|
25
|
+
copy_file 'app/views/layouts/landing_page.html.haml'
|
26
|
+
copy_file 'app/assets/javascripts/landing_page.js'
|
27
|
+
copy_file 'app/assets/stylesheets/landing_page.css.scss'
|
28
|
+
end
|
29
|
+
|
30
|
+
def set_root_url
|
31
|
+
inject_into_file 'config/routes.rb', <<-END, :after=>'::Application.routes.draw do'
|
32
|
+
|
33
|
+
|
34
|
+
root :to=>'newsletter_signups#new'
|
35
|
+
|
36
|
+
END
|
37
|
+
end
|
38
|
+
|
39
|
+
def configure_mailer
|
40
|
+
inject_into_file 'config/initializers/happyfunjuice.rb', <<-END, :after=> 'Happyfunjuice.setup do |config|'
|
41
|
+
|
42
|
+
|
43
|
+
# Mailer type and API key for newsletter signup:
|
44
|
+
config.mailer = '#{mailer}'
|
45
|
+
config.mailer_api_user = #{mailer_username}
|
46
|
+
config.mailer_api_key = #{mailer_password}
|
47
|
+
config.newsletter_list = 'newsletters'
|
48
|
+
|
49
|
+
END
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
def create_database_model
|
55
|
+
copy_file 'app/models/newsletter_signup.rb'
|
56
|
+
migration_template "#{self.class.source_root}/../migrations/create_newsletter_signups.rb", "db/migrate/#{File.basename('create_newsletter_signups.rb')}"
|
57
|
+
end
|
58
|
+
|
59
|
+
#def create_migrations
|
60
|
+
#Dir["#{self.class.source_root}/../migrations/*.rb"].sort.each do |filepath|
|
61
|
+
#name = File.basename(filepath)
|
62
|
+
#migration_template "migrations/#{name}", "db/migrate/#{name.gsub(/^\d+_/,'')}"
|
63
|
+
#sleep 1
|
64
|
+
#end
|
65
|
+
#end
|
66
|
+
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
def mailer_username
|
71
|
+
case mailer
|
72
|
+
when 'sendgrid'
|
73
|
+
"ENV['SENDGRID_USERNAME']"
|
74
|
+
when 'mailchimp'
|
75
|
+
'MAILCHIMP API USERNAME'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def mailer_password
|
80
|
+
case mailer
|
81
|
+
when 'sendgrid'
|
82
|
+
"ENV['SENDGRID_PASSWORD']"
|
83
|
+
when 'mailchimp'
|
84
|
+
'MAILCHIMP API KEY'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
// I don't know... maybe a jquery plugin for something?
|
2
|
+
|
3
|
+
;(function ( $, window, undefined ) {
|
4
|
+
|
5
|
+
var pluginName = 'happyfunjuice',
|
6
|
+
document = window.document,
|
7
|
+
defaults = {
|
8
|
+
propertyName: "value"
|
9
|
+
};
|
10
|
+
|
11
|
+
function Plugin( element, options ) {
|
12
|
+
this.element = element;
|
13
|
+
|
14
|
+
this.options = $.extend( {}, defaults, options) ;
|
15
|
+
|
16
|
+
this._defaults = defaults;
|
17
|
+
this._name = pluginName;
|
18
|
+
|
19
|
+
this.init();
|
20
|
+
}
|
21
|
+
|
22
|
+
Plugin.prototype.init = function () {
|
23
|
+
};
|
24
|
+
|
25
|
+
$.fn[pluginName] = function ( options ) {
|
26
|
+
return this.each(function () {
|
27
|
+
if (!$.data(this, pluginName)) {
|
28
|
+
$.data(this, pluginName, new Plugin( this, options ));
|
29
|
+
}
|
30
|
+
});
|
31
|
+
}
|
32
|
+
|
33
|
+
}(jQuery, window));
|
File without changes
|
File without changes
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class NewsletterSignup < ActiveRecord::Base
|
2
|
+
|
3
|
+
attr_accessible :name
|
4
|
+
validates_presence_of :name
|
5
|
+
|
6
|
+
attr_accessible :email
|
7
|
+
validates_presence_of :email
|
8
|
+
validates_format_of :email, :with=>/@/
|
9
|
+
validates_uniqueness_of :email
|
10
|
+
|
11
|
+
#attr_accessible :company
|
12
|
+
#validates_presence_of :company
|
13
|
+
|
14
|
+
|
15
|
+
after_create :submit_to_mailer!
|
16
|
+
|
17
|
+
|
18
|
+
def submit_to_mailer!
|
19
|
+
submit_email_address( self.name, self.email )
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def submit_email_address(name, email)
|
24
|
+
begin
|
25
|
+
uri = URI(newsletter_signup_endpoint)
|
26
|
+
data = newsletter_signup_params(name,email)
|
27
|
+
res = Net::HTTP.post_form( uri, data )
|
28
|
+
logger.info "Successful newsletter signup: #{res}"
|
29
|
+
rescue StandardError => e
|
30
|
+
logger.info "Newsletter error: #{e.message}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def newsletter_signup_endpoint
|
36
|
+
case Happyfunjuice.mailer
|
37
|
+
|
38
|
+
when 'sendgrid'
|
39
|
+
'http://sendgrid.com/api/newsletter/lists/email/add.json'
|
40
|
+
|
41
|
+
when 'mailchimp'
|
42
|
+
provider =~ /-([\w]+)$/
|
43
|
+
region = $1
|
44
|
+
"http://#{region}.api.mailchimp.com/1.3/?method=listSubscribe"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
def newsletter_signup_params(name,email)
|
50
|
+
case Happyfunjuice.mailer
|
51
|
+
|
52
|
+
when 'sendgrid'
|
53
|
+
{
|
54
|
+
api_user: Happyfunjuice.mailer_api_user,
|
55
|
+
api_key: Happyfunjuice.mailer_api_key,
|
56
|
+
list: Happyfunjuice.newsletter_list,
|
57
|
+
data: {name: name, email: email}
|
58
|
+
}
|
59
|
+
|
60
|
+
when 'mailchimp'
|
61
|
+
{
|
62
|
+
apikey: Happyfunjuice.mailer_api_key,
|
63
|
+
id: Happyfunjuice.newsletter_list,
|
64
|
+
email_address: email
|
65
|
+
}
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title Landing Page
|
5
|
+
%meta{name: "viewport", content: "width=device-width, initial-scale=1.0"}
|
6
|
+
= stylesheet_link_tag "landing_page", :media => "all"
|
7
|
+
= javascript_include_tag "landing_page"
|
8
|
+
= csrf_meta_tags
|
9
|
+
%body
|
10
|
+
|
11
|
+
- unless flash[:notice].blank?
|
12
|
+
.flash.notice= flash[:notice]
|
13
|
+
|
14
|
+
- unless flash[:error].blank?
|
15
|
+
%ul.flash.error
|
16
|
+
- flash[:error].each do |e|
|
17
|
+
%li= e
|
18
|
+
|
19
|
+
= yield
|
@@ -0,0 +1,32 @@
|
|
1
|
+
Happyfunjuice.setup do |config|
|
2
|
+
|
3
|
+
# Insert the API key from the HappyFunJuice settings page here:
|
4
|
+
config.api_key = "<%=@api_key%>"
|
5
|
+
|
6
|
+
# Sample usage:
|
7
|
+
#
|
8
|
+
# config.activity :new_user, User do |u|
|
9
|
+
# { id: u.id, email: u.email, name: u.name, created_at: u.created_at }
|
10
|
+
# end
|
11
|
+
#
|
12
|
+
# config.activity :all_postcards, PostCard do |p|
|
13
|
+
# { id: p.id, user_id: p.user_id, url: p.main_url }
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# config.activity :pending_postcard, PostCard.pending do |p|
|
17
|
+
# { id: p.id, user_id: p.user_id, url: p.main_url }
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# config.activity :printing_postcard, PostCard.printing do |p|
|
21
|
+
# { id: p.id, user_id: p.user_id, url: p.main_url }
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# config.activity :shipped_postcard, PostCard.shipped do |p|
|
25
|
+
# { id: p.id, user_id: p.user_id, url: p.main_url }
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# config.activity :transaction, Transaction do |t|
|
29
|
+
# { id: t.id, user_id: t.user_id, amount: t.amount }
|
30
|
+
# end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Happyfunjuice
|
2
|
+
mattr_accessor :activity_list
|
3
|
+
@@activity_list = {}
|
4
|
+
|
5
|
+
DEFAULT_PER_PAGE = 50
|
6
|
+
MAX_PER_PAGE = 1000
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def push_activity( key, scope, opts={}, &block )
|
10
|
+
Happyfunjuice.activity_list[key.to_sym] = Happyfunjuice::Activity.new( key, scope, opts, &block )
|
11
|
+
end
|
12
|
+
|
13
|
+
# Query the list of activities. Data and metadata combined into one method since the
|
14
|
+
# queries are otherwise identical.
|
15
|
+
#
|
16
|
+
# Optional parameters are:
|
17
|
+
#
|
18
|
+
# page: controls pagination with DEFAULT_PER_PAGE activities returned at a time
|
19
|
+
#
|
20
|
+
# type: if specified, queries only this type of activity. Otherwise returns all activities.
|
21
|
+
#
|
22
|
+
# include_metadata: true/false
|
23
|
+
#
|
24
|
+
# query_activities: true/false
|
25
|
+
#
|
26
|
+
def activities( opts = {} )
|
27
|
+
# Default options
|
28
|
+
opts.reverse_merge!({
|
29
|
+
page:1,
|
30
|
+
per_page: DEFAULT_PER_PAGE,
|
31
|
+
type: nil,
|
32
|
+
include_metadata: true,
|
33
|
+
query_activities: true
|
34
|
+
})
|
35
|
+
|
36
|
+
# If page unspecified or invalid, return page 1
|
37
|
+
_per_page = [(opts[:per_page] || DEFAULT_PER_PAGE).to_i,1].max
|
38
|
+
_page = [opts[:page].to_i || 1,1].max
|
39
|
+
|
40
|
+
raise StandardError.new("No more than #{MAX_PER_PAGE} records may be returned in a single response.") if _per_page > MAX_PER_PAGE
|
41
|
+
|
42
|
+
ret = {}
|
43
|
+
|
44
|
+
# Choose specified activity or else all activities
|
45
|
+
types = [(opts[:type].to_sym rescue nil)].reject(&:nil?)
|
46
|
+
types = Happyfunjuice.activity_list.keys if types.empty?
|
47
|
+
|
48
|
+
# Iterate through activity types to build response
|
49
|
+
types.each do |k|
|
50
|
+
|
51
|
+
# Error message returned to user if activity invalid
|
52
|
+
unless Happyfunjuice.activity_list.include? k
|
53
|
+
raise StandardError.new("No activity '#{k.to_s}' is defined")
|
54
|
+
end
|
55
|
+
|
56
|
+
activity = Happyfunjuice.activity_list[k]
|
57
|
+
|
58
|
+
_ret = {}
|
59
|
+
_ret.merge!({data: activity.query(_page,_per_page)}) if opts[:query_activities]
|
60
|
+
_ret.merge!({metadata: activity.metadata }) if opts[:include_metadata]
|
61
|
+
|
62
|
+
ret[k] = _ret
|
63
|
+
end
|
64
|
+
|
65
|
+
ret
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
class Activity
|
71
|
+
attr_accessor :key, :scope, :block
|
72
|
+
|
73
|
+
def initialize( key, scope, opts={}, &block )
|
74
|
+
@options = opts
|
75
|
+
@key = key.to_sym
|
76
|
+
@scope = scope
|
77
|
+
@block = block
|
78
|
+
end
|
79
|
+
|
80
|
+
# Kinda gross, but instantiate an object and yield the block on it to get the list of returned keys.
|
81
|
+
def fields
|
82
|
+
block.yield(@scope.new).keys
|
83
|
+
end
|
84
|
+
|
85
|
+
# Execute the query. Reorder (not order, just in case a default order is specified) by id desc
|
86
|
+
# and paginate.
|
87
|
+
def query( page=1, limit=DEFAULT_PER_PAGE )
|
88
|
+
scope.reorder('id desc').limit(limit).offset((page-1)*limit).collect do |activity|
|
89
|
+
block.yield activity
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Metadata for this activity
|
94
|
+
def metadata
|
95
|
+
{
|
96
|
+
key: @key,
|
97
|
+
name: @options[:name] || @key.to_s.humanize,
|
98
|
+
fields: fields
|
99
|
+
}
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Happyfunjuice
|
2
|
+
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def setup( &block )
|
6
|
+
|
7
|
+
# This MUST happen after initialization otherwise configuration variables
|
8
|
+
# are not known to the models at the time activity reports are configured:
|
9
|
+
Rails.application.config.after_initialize do
|
10
|
+
HappyfunjuiceConfig.class_eval(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
# An extra class so there's no ambiguity between mattr_accessors in config.rb
|
16
|
+
# and the methods here:
|
17
|
+
class HappyfunjuiceConfig
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def api_key= key
|
21
|
+
Happyfunjuice.api_key = key.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def notifications
|
25
|
+
Happyfunjuice.notifications
|
26
|
+
end
|
27
|
+
|
28
|
+
def environment= env
|
29
|
+
Happyfunjuice.environment = env.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
def debug_mode= bool
|
33
|
+
Happyfunjuice.debug_mode = !!(bool)
|
34
|
+
end
|
35
|
+
|
36
|
+
def activity( key, scope, opts={}, &block )
|
37
|
+
Happyfunjuice.push_activity( key, scope, opts, &block )
|
38
|
+
end
|
39
|
+
|
40
|
+
def mailer= value
|
41
|
+
unless %w( mailchimp sendgrid ).include? value.downcase
|
42
|
+
raise ArgumentError.new('Mailer host must be either sendgrid or mailchimp. Choose one and reconfigure it later if necessary.')
|
43
|
+
end
|
44
|
+
Happyfunjuice.mailer = value.downcase
|
45
|
+
end
|
46
|
+
|
47
|
+
def mailer_api_user= value
|
48
|
+
Happyfunjuice.mailer_api_user = value
|
49
|
+
end
|
50
|
+
|
51
|
+
def mailer_api_key= value
|
52
|
+
Happyfunjuice.mailer_api_key = value
|
53
|
+
end
|
54
|
+
|
55
|
+
def newsletter_list= value
|
56
|
+
Happyfunjuice.newsletter_list = value
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Happyfunjuice
|
2
|
+
|
3
|
+
class << self
|
4
|
+
def notifications
|
5
|
+
|
6
|
+
# It'd be nice to do something interesting here:
|
7
|
+
ActiveSupport::Notifications.subscribe do |name, start, finish, id, payload|
|
8
|
+
Rails.logger.debug(["juice_notification:", name, start, finish, id, payload].join(" "))
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ActionDispatch::Routing
|
2
|
+
class Mapper
|
3
|
+
|
4
|
+
# The only helper exposed to happyfunjuice
|
5
|
+
def happyfunjuice(options={}, &block)
|
6
|
+
HappyfunjuiceMapper.new(self,options,&block)
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
# Scope helper methods within HappyfunjuiceMapper to avoid name collisions
|
11
|
+
class HappyfunjuiceMapper
|
12
|
+
def initialize(mapper,options={},&block)
|
13
|
+
@mapper = mapper
|
14
|
+
|
15
|
+
options.reverse_merge!({})
|
16
|
+
|
17
|
+
self.instance_eval(&block)
|
18
|
+
end
|
19
|
+
|
20
|
+
def activities
|
21
|
+
@mapper.namespace :happyfunjuice do
|
22
|
+
@mapper.get 'activities' => 'happyfunjuice#activities'
|
23
|
+
@mapper.get 'metadata' => 'happyfunjuice#metadata'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def landing_page
|
28
|
+
#@mapper.namespace :happyfunjuice do
|
29
|
+
@mapper.resources :newsletter_signups, :only=>[:new, :create]
|
30
|
+
#end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'happyfunjuice/routes'
|
2
|
+
require 'happyfunjuice/version'
|
3
|
+
require 'happyfunjuice/activity'
|
4
|
+
require 'happyfunjuice/engine'
|
5
|
+
require 'happyfunjuice/config'
|
6
|
+
require 'happyfunjuice/notifications'
|
7
|
+
|
8
|
+
# Module-wide data
|
9
|
+
module Happyfunjuice
|
10
|
+
|
11
|
+
# Variables for Juice
|
12
|
+
@@apikey = nil
|
13
|
+
@@debug_mode = false
|
14
|
+
@@environment = 'production'
|
15
|
+
|
16
|
+
# Variables for landing page:
|
17
|
+
@@mailer = 'sendgrid'
|
18
|
+
@@mailer_api_user = 'username'
|
19
|
+
@@mailer_api_key = 'api-key'
|
20
|
+
@@newsletter_list = 'newsletters'
|
21
|
+
|
22
|
+
mattr_accessor :api_key, :debug_mode
|
23
|
+
mattr_accessor :mailer, :mailer_api_user, :mailer_api_key, :newsletter_list
|
24
|
+
mattr_accessor :environment
|
25
|
+
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: happyfunjuice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.beta.1
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ricky Reusser
|
9
|
+
- Will Schenk
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-05-10 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: haml
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
description: Pull data and analytics from your app into HappyFunJuice.
|
32
|
+
email:
|
33
|
+
- ricky@happyfuncorp.com
|
34
|
+
- will@happyfuncorp.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- app/controllers/happyfunjuice/happyfunjuice_controller.rb
|
40
|
+
- app/controllers/newsletter_signups_controller.rb
|
41
|
+
- lib/generators/happyfunjuice/install_generator.rb
|
42
|
+
- lib/generators/happyfunjuice/js_generator.rb
|
43
|
+
- lib/generators/happyfunjuice/landing_page_generator.rb
|
44
|
+
- lib/generators/happyfunjuice/migrations/create_newsletter_signups.rb
|
45
|
+
- lib/generators/happyfunjuice/templates/app/assets/javascripts/happyfunjuice.js
|
46
|
+
- lib/generators/happyfunjuice/templates/app/assets/javascripts/landing_page.js
|
47
|
+
- lib/generators/happyfunjuice/templates/app/assets/stylesheets/landing_page.css.scss
|
48
|
+
- lib/generators/happyfunjuice/templates/app/models/newsletter_signup.rb
|
49
|
+
- lib/generators/happyfunjuice/templates/app/views/layouts/landing_page.html.haml
|
50
|
+
- lib/generators/happyfunjuice/templates/app/views/newsletter_signups/new.html.haml
|
51
|
+
- lib/generators/happyfunjuice/templates/config/initializers/happyfunjuice.rb.erb
|
52
|
+
- lib/happyfunjuice/activity.rb
|
53
|
+
- lib/happyfunjuice/config.rb
|
54
|
+
- lib/happyfunjuice/engine.rb
|
55
|
+
- lib/happyfunjuice/notifications.rb
|
56
|
+
- lib/happyfunjuice/routes.rb
|
57
|
+
- lib/happyfunjuice/version.rb
|
58
|
+
- lib/happyfunjuice.rb
|
59
|
+
- Rakefile
|
60
|
+
homepage: http://happyfunjuice.com
|
61
|
+
licenses: []
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>'
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.3.1
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 1.8.25
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Happy Fun Juice!
|
84
|
+
test_files: []
|