-
-
Save practicingruby/1720267 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" | |
| def load_list(name) | |
| PostalService::MailingList.new("db/lists/libre-#{name}.store") | |
| end | |
| app = PostalService::Application.new do | |
| match :list_id, "[^.]+" | |
| to(:tag, "{list_id}.subscribe") do | |
| list = load_list(params[:list_id]) | |
| if list.subscriber?(sender) | |
| respond :subject => "ERROR: Already subscribed", | |
| :body => template("subscribe-error"), | |
| :reply_to => "test+#{params[:list_id]}@#{domain}" | |
| else | |
| list.subscribe(sender) | |
| respond :subject => "SUBSCRIBED!", | |
| :body => template("subscribe-success"), | |
| :reply_to => "test+#{params[:list_id]}@#{domain}" | |
| end | |
| end | |
| to(:tag, "{list_id}.unsubscribe") do | |
| list = load_list(params[:list_id]) | |
| 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"), | |
| :reply_to => "test+#{params[:list_id]}@#{domain}" | |
| end | |
| end | |
| to(:tag, "{list_id}") do | |
| list = load_list(params[:list_id]) | |
| if list.subscriber?(sender) | |
| forward_message :bcc => list.subscribers.join(", "), | |
| :reply_to => "test+#{params[:list_id]}@#{domain}" | |
| else | |
| respond :subject => "You are not subscribed", | |
| :body => template("non-subscriber-error"), | |
| :reply_to => "test+#{params[:list_id]}@#{domain}" | |
| end | |
| end | |
| default do | |
| respond :subject => "FAIL" | |
| 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