Skip to content

Commit e244b2d

Browse files
Initial hook PoC
1 parent 9c4e566 commit e244b2d

17 files changed

+129
-0
lines changed

Gemfile

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ gem 'rails', '3.0.10'
66
# gem 'rails', :git => 'git://github.com/rails/rails.git'
77

88
gem 'pg'
9+
gem 'haml'
910

1011
# Use unicorn as the web server
1112
# gem 'unicorn'

Gemfile.lock

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ GEM
3232
builder (2.1.2)
3333
erubis (2.6.6)
3434
abstract (>= 1.0.0)
35+
haml (3.1.2)
3536
i18n (0.5.0)
3637
mail (2.2.19)
3738
activesupport (>= 2.3.6)
@@ -72,5 +73,6 @@ PLATFORMS
7273
ruby
7374

7475
DEPENDENCIES
76+
haml
7577
pg
7678
rails (= 3.0.10)

app/controllers/hooks_controller.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class HooksController < ApplicationController
2+
def receive
3+
case params[:type]
4+
when "subscribe"
5+
User.create(:first_name => params[:data][:merges][:FNAME],
6+
:last_name => params[:data][:merges][:LNAME],
7+
:email => params[:data][:email],
8+
:mailchimp_web_id => params[:data][:web_id])
9+
render :text => "ok"
10+
else
11+
# ghetto
12+
if RAILS_ENV == "development"
13+
raise
14+
else
15+
render :text => "ok (unsupported)"
16+
end
17+
end
18+
end
19+
end

app/controllers/users_controller.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class UsersController < ApplicationController
2+
def index
3+
4+
end
5+
end

app/helpers/hooks_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module HooksHelper
2+
end

app/helpers/users_helper.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module UsersHelper
2+
end

app/models/user.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class User < ActiveRecord::Base
2+
validates_presence_of :mailchimp_web_id, :email
3+
validates_uniqueness_of :mailchimp_web_id, :email
4+
5+
def name
6+
"#{first_name} #{last_name}"
7+
end
8+
end

app/views/users/index.haml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- User.all.each do |u|
2+
= "#{u.name} (#{u.email})"

config/routes.rb

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# The priority is based upon order of creation:
33
# first created -> highest priority.
44

5+
match '/hooks/2f94d5ec414b463caa8d6f5f98bff105fd1b2151112' => 'hooks#receive'
6+
7+
resources :users
8+
59
# Sample of regular route:
610
# match 'products/:id' => 'catalog#view'
711
# Keep in mind you can assign values other than :controller and :action
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class CreateUsers < ActiveRecord::Migration
2+
def self.up
3+
create_table :users do |t|
4+
t.text :first_name
5+
t.text :last_name
6+
t.text :email
7+
t.text :mailchimp_web_id
8+
9+
t.timestamps
10+
end
11+
end
12+
13+
def self.down
14+
drop_table :users
15+
end
16+
end

db/schema.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# encoding: UTF-8
2+
# This file is auto-generated from the current state of the database. Instead
3+
# of editing this file, please use the migrations feature of Active Record to
4+
# incrementally modify your database, and then regenerate this schema definition.
5+
#
6+
# Note that this schema.rb definition is the authoritative source for your
7+
# database schema. If you need to create the application database on another
8+
# system, you should be using db:schema:load, not running all the migrations
9+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
10+
# you'll amass, the slower it'll run and the greater likelihood for issues).
11+
#
12+
# It's strongly recommended to check this file into your version control system.
13+
14+
ActiveRecord::Schema.define(:version => 20110820183757) do
15+
16+
create_table "users", :force => true do |t|
17+
t.text "first_name"
18+
t.text "last_name"
19+
t.text "email"
20+
t.text "mailchimp_web_id"
21+
t.datetime "created_at"
22+
t.datetime "updated_at"
23+
end
24+
25+
end

test/fixtures/users.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2+
3+
# This model initially had no columns defined. If you add columns to the
4+
# model remove the '{}' from the fixture names and add the columns immediately
5+
# below each fixture, per the syntax in the comments below
6+
#
7+
one: {}
8+
# column: value
9+
#
10+
two: {}
11+
# column: value
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'test_helper'
2+
3+
class HooksControllerTest < ActionController::TestCase
4+
# Replace this with your real tests.
5+
test "the truth" do
6+
assert true
7+
end
8+
end
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'test_helper'
2+
3+
class UsersControllerTest < ActionController::TestCase
4+
# Replace this with your real tests.
5+
test "the truth" do
6+
assert true
7+
end
8+
end
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'test_helper'
2+
3+
class HooksHelperTest < ActionView::TestCase
4+
end
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
require 'test_helper'
2+
3+
class UsersHelperTest < ActionView::TestCase
4+
end

test/unit/user_test.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'test_helper'
2+
3+
class UserTest < ActiveSupport::TestCase
4+
# Replace this with your real tests.
5+
test "the truth" do
6+
assert true
7+
end
8+
end

0 commit comments

Comments
 (0)