Created
February 1, 2012 19:47
-
-
Save practicingruby/1718913 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| require_relative "../lib/postal_service" | |
| list = PostalService::MailingList.new("db/lists/simple_mailing_list.store") | |
| app = PostalService::Application.new do | |
| to(:tag, "subscribe") do | |
| if list.subscriber?(sender) | |
| respond :subject => "ERROR: Already subscribed", | |
| :body => template("subscribe-error") | |
| else | |
| list.subscribe(sender) | |
| respond :subject => "SUBSCRIBED!", | |
| :body => template("subscribe-success") | |
| end | |
| end | |
| to(:tag, "unsubscribe") do | |
| if list.subscriber?(sender) | |
| list.unsubscribe(sender) | |
| respond :subject => "UNSUBSCRIBED!", | |
| :body => template("unsubscribe-success") | |
| else | |
| respond :subject => "ERROR: Not on subscriber list", | |
| :body => template("unsubscribe-error") | |
| end | |
| end | |
| default do | |
| if list.subscriber?(sender) | |
| forward_message :bcc => list.subscribers.join(", ") | |
| else | |
| respond :subject => "You are not subscribed", | |
| :body => template("non-subscriber-error") | |
| end | |
| end | |
| end | |
| PostalService::Server.run(:config => eval(File.read("config.rb")), | |
| :apps => [app]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment