Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subscriber list, top changed tweet, top changed emails through amazon…
… ses
- Loading branch information
Showing
43 changed files
with
608 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'util' | ||
|
||
class SubscribersController < ApplicationController | ||
include Util | ||
def new | ||
@subscriber = Subscriber.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.xml { render :xml => @subscriber } | ||
end | ||
end | ||
|
||
# GET /subscribers/1/edit | ||
def edit | ||
@subscriber = Subscriber.find(params[:id]) | ||
end | ||
|
||
# POST /subscribers | ||
# POST /subscribers.xml | ||
def create | ||
# look for subscriber with this email already | ||
@skip_flash = true | ||
found = Subscriber.find_by_address(params[:subscriber][:address]) | ||
if found | ||
flash[:error] = "The email address \"#{params[:subscriber][:address]}\" has already been subscribed." | ||
else | ||
@subscriber = Subscriber.new(params[:subscriber]) | ||
if @subscriber.save | ||
flash[:notice] = "You have been successfully subscribed." | ||
else | ||
@subscriber.errors.each do |attr_name,message| | ||
attr_name = "email address" unless attr_name.to_s != "address" | ||
flash[:error] = "I'm sorry, #{attr_name} #{message}" | ||
end | ||
|
||
end | ||
end | ||
redirect_to root_url | ||
|
||
end | ||
|
||
def destroy | ||
#check to make sure the signature matches | ||
if params[:signature] == sign_text(params[:id].to_s) | ||
@subscriber = Subscriber.find(params[:id]) | ||
@subscriber.destroy | ||
flash[:notice] = "#{@subscriber.address} has been successfully unsubscribed." | ||
else | ||
flash[:error] ="signatures did not match, please contact us if there was an error." | ||
end | ||
redirect_to root_url | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module SubscriberHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module SubscribersHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class AlertMailer < ActionMailer::Base | ||
default :from => "'The Stock Factor' <thestockfactor@gmail.com>" | ||
layout 'email' | ||
include Util | ||
def top_changed_email(subscriber,symbol) | ||
@signature = sign_text(subscriber.id.to_s) | ||
@subscriber = subscriber | ||
@symbol = symbol | ||
mail(:to => subscriber.address, | ||
:subject => "#{symbol} is now the symbol with the highest stock factor!") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Subscriber < ActiveRecord::Base | ||
attr_accessible :address | ||
validates :address, :presence => true, | ||
:length => {:minimum => 3, :maximum => 254}, | ||
:uniqueness => true, | ||
:format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i} | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= @symbol %> is not the symbol with the highest stock factor. | ||
<br /> | ||
<ul> | ||
<li><%= link_to "See it on the graph",:only_path=>false,:host=>APP_CONFIG[:domain],:controller=>:entries,:action=>:symbol,:id=>@symbol %></li> | ||
<li><a href="http://<%= APP_CONFIG[:domain] %>">See the list of the stocks with the highest factor</a> </li> | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
the symbol with the highest stock factor has changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<%- flash.each do |name, msg| -%> | ||
<%= content_tag :div, msg, :id => "flash_#{name}" %> | ||
<%- end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> | ||
</head> | ||
<body> | ||
<table> | ||
<tr> | ||
<td> | ||
<h3>The Stock Factor</h3> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><%= yield %></td> | ||
</tr> | ||
<tr> | ||
<td> | ||
<a href="<%= "http://#{APP_CONFIG[:domain]}/subscribers/destroy/#{@subscriber.id}?signature=#{@signature}"%>">Unsubscribe from all emails</a> (One click and you are unsubscribed, no confirm step.) | ||
</td> | ||
</tr> | ||
</table> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%= form_for(@subscriber) do |f| %> | ||
<% if @subscriber.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@subscriber.errors.count, "error") %> prohibited this subscriber from being saved:</h2> | ||
|
||
<ul> | ||
<% @subscriber.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="actions"> | ||
<%= f.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing subscriber</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Show', @subscriber %> | | ||
<%= link_to 'Back', subscribers_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<h1>Listing subscribers</h1> | ||
|
||
<table> | ||
<tr> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @subscribers.each do |subscriber| %> | ||
<tr> | ||
<td><%= link_to 'Show', subscriber %></td> | ||
<td><%= link_to 'Edit', edit_subscriber_path(subscriber) %></td> | ||
<td><%= link_to 'Destroy', subscriber, :confirm => 'Are you sure?', :method => :delete %></td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New Subscriber', new_subscriber_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<h1>New subscriber</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', subscribers_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<p id="notice"><%= notice %></p> | ||
|
||
|
||
<%= link_to 'Edit', edit_subscriber_path(@subscriber) %> | | ||
<%= link_to 'Back', subscribers_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ActionMailer::Base.add_delivery_method :ses, AWS::SES::Base, | ||
:access_key_id => APP_CONFIG[:aws_id], | ||
:secret_access_key => APP_CONFIG[:aws_secret] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class AddEmailsContacts < ActiveRecord::Migration | ||
def self.up | ||
create_table :subscribers do |t| | ||
t.timestamps | ||
t.string(:address,:null=>false,:unique=>true) | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :subscribers | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AddIndexOnSubscriberAddress < ActiveRecord::Migration | ||
def self.up | ||
add_index(:subscribers,:address) | ||
end | ||
|
||
def self.down | ||
remove_index(:subscribers,:address) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.