Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created February 1, 2012 19:47
Show Gist options
  • Select an option

  • Save practicingruby/1718913 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/1718913 to your computer and use it in GitHub Desktop.
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