Skip to content
This repository has been archived by the owner on Nov 18, 2022. It is now read-only.

Commit

Permalink
mandril integrated and working. templates are still an issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
el-feo committed Jun 22, 2014
1 parent 4d5f571 commit 41a7dd9
Show file tree
Hide file tree
Showing 31 changed files with 15,868 additions and 53 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ gem 'sitemap_generator', '~> 5.0.2'
gem 'favicon_maker', '~> 1.3'
gem 'kaminari', '~> 0.16.0'

gem 'mandrill-api', '~> 1.0.51'

group :development do
gem 'foreman', require: false
gem 'spring', '~> 1.1.2'
Expand All @@ -44,4 +46,4 @@ end

group :doc do
gem 'sdoc', '~> 0.4.0', require: false
end
end
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ GEM
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mandrill-api (1.0.51)
excon (>= 0.16.0, < 1.0)
json (>= 1.7.7, < 2.0)
memoizable (0.4.0)
thread_safe (~> 0.1.3)
meta_request (0.3.0)
Expand Down Expand Up @@ -296,6 +299,7 @@ DEPENDENCIES
jquery-rails (~> 3.1.0)
jquery-turbolinks (~> 2.0.2)
kaminari (~> 0.16.0)
mandrill-api (~> 1.0.51)
meta_request (~> 0.3.0)
pg (~> 0.17.1)
puma (~> 2.8.2)
Expand Down
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web: puma -C config/puma.rb | grep -v --line-buffered ' 304 -'
worker: sidekiq -C config/sidekiq.yml
worker: bundle exec sidekiq -C config/sidekiq.yml
log: tail -f log/development.log | grep -xv --line-buffered '^[[:space:]]*' | grep -v --line-buffered '/assets/'
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@
//= require bootstrap/scrollspy
//= require bootstrap/tab
//= require bootstrap/transition
//= require datatables/jquery.dataTables
//= require datatables/dataTables.bootstrap
//= require_tree .
6 changes: 6 additions & 0 deletions app/assets/javascripts/leads.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: https://coffeescript.org/
$(document).ready ->
$("#leads").DataTable()
return
2 changes: 2 additions & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*
*= require_tree .
*= require font-awesome
*= require datatables/dataTables.bootstrap
*= require datatables/dataTables.fontAwesome
*= require_self
*/

Expand Down
3 changes: 3 additions & 0 deletions app/assets/stylesheets/leads.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the leads controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: https://sass-lang.com/
69 changes: 69 additions & 0 deletions app/assets/stylesheets/scaffolds.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
body {
background-color: #fff;
color: #333;
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}

p, ol, ul, td {
font-family: verdana, arial, helvetica, sans-serif;
font-size: 13px;
line-height: 18px;
}

pre {
background-color: #eee;
padding: 10px;
font-size: 11px;
}

a {
color: #000;
&:visited {
color: #666;
}
&:hover {
color: #fff;
background-color: #000;
}
}

div {
&.field, &.actions {
margin-bottom: 10px;
}
}

#notice {
color: green;
}

.field_with_errors {
padding: 2px;
background-color: red;
display: table;
}

#error_explanation {
width: 450px;
border: 2px solid red;
padding: 7px;
padding-bottom: 0;
margin-bottom: 20px;
background-color: #f0f0f0;
h2 {
text-align: left;
font-weight: bold;
padding: 5px 5px 5px 15px;
font-size: 12px;
margin: -7px;
margin-bottom: 0px;
background-color: #c00;
color: #fff;
}
ul li {
font-size: 12px;
list-style: square;
}
}
70 changes: 70 additions & 0 deletions app/controllers/leads_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
class LeadsController < ApplicationController
before_action :set_lead, only: [:show, :edit, :update, :destroy]

# GET /leads
def index
@leads = Lead.all
end

def import
Lead.import(params[:file])
redirect_to leads_path, notice: "Leads imported."
end

def email
leads_array = Lead.where(phase: params[:phase])
leads_array = leads_array.pluck(:id)
CampaignWorker.perform_async(leads_array)
redirect_to leads_path, notice: "Leads scheduled for email."
end

# GET /leads/1
def show
end

# GET /leads/new
def new
@lead = Lead.new
end

# GET /leads/1/edit
def edit
end

# POST /leads
def create
@lead = Lead.new(lead_params)

if @lead.save
redirect_to @lead, notice: 'Lead was successfully created.'
else
render :new
end
end

# PATCH/PUT /leads/1
def update
if @lead.update(lead_params)
redirect_to @lead, notice: 'Lead was successfully updated.'
else
render :edit
end
end

# DELETE /leads/1
def destroy
@lead.destroy
redirect_to leads_url, notice: 'Lead was successfully destroyed.'
end

private
# Use callbacks to share common setup or constraints between actions.
def set_lead
@lead = Lead.find(params[:id])
end

# Only allow a trusted parameter "white list" through.
def lead_params
params[:lead]
end
end
2 changes: 2 additions & 0 deletions app/helpers/leads_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module LeadsHelper
end
8 changes: 8 additions & 0 deletions app/models/lead.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Lead < ActiveRecord::Base

def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
Lead.create! row.to_hash
end
end
end
17 changes: 17 additions & 0 deletions app/views/leads/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= form_for(@lead) do |f| %>
<% if @lead.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@lead.errors.count, "error") %> prohibited this lead from being saved:</h2>

<ul>
<% @lead.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="actions">
<%= f.submit %>
</div>
<% end %>
6 changes: 6 additions & 0 deletions app/views/leads/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Editing lead</h1>

<%= render 'form' %>
<%= link_to 'Show', @lead %> |
<%= link_to 'Back', leads_path %>
55 changes: 55 additions & 0 deletions app/views/leads/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<h1>Leads</h1>

<div class="">
<%= form_tag import_leads_path, class: "form-inline", multipart: true do %>
<div class="input-group">
<span class="input-group-addon">File:</span>
<%= file_field_tag :file, class: "form-control" %>
</div>
<button type="submit" class="btn btn-default">Submit</button>
<% end %>
<br>
<%= form_tag email_leads_path, class: "form-inline", multipart: true do %>
<div class="input-group">
<span class="input-group-addon">Phase:</span>
<input type="text" class="form-control" id="phase" name="phase" placeholder="Phase">
</div>
<button type="submit" class="btn btn-default">Email</button>
<% end %>
</div>
<br>
<br>
<div class="">
<table id="leads" class="table table-condensed table-hover">
<thead>
<tr>
<th>Phase</th>
<th>First</th>
<th>Last</th>
<th>Email</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>

<tbody>
<% @leads.each do |lead| %>
<tr>
<td><%= lead.phase %></td>
<td><%= lead.first_name %></td>
<td><%= lead.last_name %></td>
<td><%= lead.email %></td>
<td><%= link_to 'Show', lead %></td>
<td><%= link_to 'Edit', edit_lead_path(lead) %></td>
<td><%= link_to 'Destroy', lead, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

</div>

<br>

<%= link_to 'New Lead', new_lead_path %>
5 changes: 5 additions & 0 deletions app/views/leads/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>New lead</h1>

<%= render 'form' %>
<%= link_to 'Back', leads_path %>
4 changes: 4 additions & 0 deletions app/views/leads/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p id="notice"><%= notice %></p>

<%= link_to 'Edit', edit_lead_path(@lead) %> |
<%= link_to 'Back', leads_path %>
26 changes: 26 additions & 0 deletions app/workers/campaign_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class CampaignWorker
include Sidekiq::Worker

def perform(leads_array)
require 'mandrill'
@m = Mandrill::API.new(ENV["MANDRILL_API_KEY"])
leads_array.each do |lead|
@user = Lead.find(lead)
email_lead
sleep(30)
end
end

def email_lead
template_name = "Beta Announcement"
template_content = [{"name"=>"example name", "content"=>"example content"}]
message = {
:subject=> "Production's About to Change",
:from_name=> "Jeb Coleman",
:from_email=> "[email protected]",
:to=>[{:email=> @user.email}]
}
sending = @m.send_template template_name, template_content, message
puts sending
end
end
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require File.expand_path('../boot', __FILE__)

require 'csv'
require 'rails/all'

# Require the gems listed in Gemfile, including any gems
Expand Down
Loading

0 comments on commit 41a7dd9

Please sign in to comment.