Git Product home page Git Product logo

postmark-mitt's Introduction

Postmark Mitt

This gem provides a little wrapper object for taking JSON from Postmark’s incoming email system and composing it back into an object resembling an email. This comes in handy when you are trying to figure out what to do with the email.

Postmark-mitt has been verified to work on Ruby Enterprise Edition 1.8.7, 1.9.2 and 1.9.3.

Install

gem install postmark-mitt

Example

require 'lib/postmark_mitt'

# if you are just playing with this library
email = Postmark::Mitt.new(File.read("path/to/json/file/in/spec/fixtures"))

# if you are doing this in a controller
email = Postmark::Mitt.new(request.body.read)

email.to # "[email protected]"
email.from # Bob Bobson <[email protected]>
email.from_email # [email protected]
email.text_body
email.html_body
email.headers # returns a hash of the headers

email.attachments # array of attachment objects

attachment = email.attachments.first
attachment.file_name
attachment.content_type
attachment.read # will base64 decode the content... eventually this will lazy-load the file from Postmark
attachment.size # NYI
# You get the idea

A lot of times you want to do something with the email, like create a post

mitt = Postmark::Mitt.new(request.body.read)
Post.create_from_postmark(mitt)

class Post
  def self.create_from_postmark(mitt)
    author = User.find_by_api_email(mitt.to)
    handle_no_author # send an email back saying we couldn't find them
    post = new
    post.title = mitt.subject
    post.author = author
    post.photo = mitt.attachments.first.read
    post.message_id = mitt.message_id # Make sure we don't process the same email twice
    # You get the idea, right?
    post.save
    post
  end
end

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history.

  • Send me a pull request. Bonus points for topic branches.

Authors & Contributors

  • Randy Schmidt

Copyright © 2011 Randy Schmidt. See LICENSE for details.

postmark-mitt's People

Contributors

coneybeare avatar deepredsky avatar r38y avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.