Created
October 13, 2009 20:09
-
-
Save r38y/209516 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
* Forward [email protected] -> [email protected] | |
* Incoming email is passed through a filter if the recipient matches | |
* Stored as a message, delayed job is queued | |
* Delayed job is processed which posts the params to the destination | |
* Params is only JSON with info about attachments including the URL | |
* Mitt parses JSON and lets the app inspect the important stuff | |
* Attachment data is lazy-loaded over the wire so it's only fetched if needed. |
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
class Post < ActiveRecord::Base | |
attr_accessible :title, :body, :posted_at, :owner_email, :owner_name, :photo, :owner, :status | |
has_permalink :title | |
belongs_to :owner, :class_name => 'User' | |
has_attached_file :photo | |
validates_presence_of :title, :posted_at, :photo | |
def self.create_from_emlz(emlz) | |
create( | |
:owner => User.find_by_posting_address(emlz.to), | |
:title => emlz.subject || 'Something Delicious!', | |
:owner_email => emlz.from, | |
:owner_name => emlz.from_name, | |
:body => emlz.body, | |
:photo => emlz.largest_attachment.data, | |
:posted_at => emlz.date | |
) if emlz.has_attachments? | |
end | |
end |
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
class Api::PostsController < ApplicationController | |
skip_before_filter :verify_authenticity_token | |
def create | |
emlz = EMLZ.new(request.body.read) # reads in the json and does stuff with it | |
Post.create_from_emlz(emlz) | |
render :nothing => true | |
end | |
end |
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
class User < ActiveRecord::Base | |
attr_accessible :name, :email, :username, :password, :password_confirmation, :token | |
has_many :posts, :foreign_key => :owner_id | |
def posting_address | |
"#{CONFIG.posting_user}+#{email_token}@shareurmeal.com" | |
end | |
def self.find_by_posting_address(email) | |
return nil if email.blank? | |
token = email.split("@").first.split("+").last | |
find_by_email_token(token) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment