Browse files

- initial version \o/

  • Loading branch information...
1 parent d87f282 commit bd9d2648423ba5c44c7b280462b51e04ea03295d @tarmolehtpuu tarmolehtpuu committed Dec 13, 2011
Showing with 165 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +1 −0 .rvmrc
  3. +20 −0 MIT-LICENCE
  4. +13 −0 README.markdown
  5. +21 −0 Rakefile
  6. +1 −1 VERSION
  7. +62 −0 lib/mailgun-rails.rb
  8. +46 −0 mailgun-rails.gemspec
View
1 .gitignore
@@ -0,0 +1 @@
+*.gem
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm use 1.9.3@mailgun-rails
View
20 MIT-LICENCE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 PerfectLine LLC (www.perfectline.co.uk)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
13 README.markdown
@@ -0,0 +1,13 @@
+### Installation
+
+Add the following to your Gemfile:
+
+ gem 'mailgun-rails'
+
+### Configuration
+
+ config.action_mailer.delivery_method = :mailgun
+ config.action_mailer.mailgun_settings = {
+ :api_key => "YOUR_API_KEY",
+ :api_host => "YOUR_API_HOST"
+ }
View
21 Rakefile
@@ -0,0 +1,21 @@
+require 'rake'
+require 'rake/gempackagetask'
+
+begin
+ require 'jeweler'
+
+ Jeweler::Tasks.new do |jewel|
+ jewel.name = 'mailgun-rails'
+ jewel.summary = 'Mailgun adapter for Rails.'
+ jewel.email = ['tanel.suurhans@perfectline.ee', 'tarmo.lehtpuu@perfectline.ee']
+ jewel.homepage = 'https://github.com/perfectline/mailgun-rails'
+ jewel.description = 'Mailgun adapter for Rails.'
+ jewel.authors = ["Tanel Suurhans", "Tarmo Lehtpuu"]
+ jewel.files = FileList["lib/mailgun-rails.rb", "MIT-LICENCE", "README.markdown"]
+ jewel.add_dependency 'curb'
+ jewel.add_dependency 'active_support'
+ jewel.add_dependency 'action_mailer'
+ end
+rescue LoadError
+ puts "Jeweler not available. Install it with: gem install jeweler"
+end
View
2 VERSION
@@ -1 +1 @@
-0.0.0
+0.1.0
View
62 lib/mailgun-rails.rb
@@ -0,0 +1,62 @@
+require "action_mailer"
+require "active_support"
+require "curb"
+
+module Mailgun
+
+ class DeliveryError < StandardError
+ end
+
+ class DeliveryMethod
+
+ attr_accessor :settings
+
+ def initialize(settings)
+ self.settings = settings
+ end
+
+ def api_host
+ self.settings[:api_host]
+ end
+
+ def api_key
+ self.settings[:api_key]
+ end
+
+ def deliver!(mail)
+
+ body = Curl::PostField.content("message", mail.encoded)
+ body.remote_file = "message"
+ body.content_type = "application/octet-stream"
+
+ data = []
+ data << body
+
+ mail.destinations.each do |destination|
+ data << Curl::PostField.content("to", destination)
+ end
+
+ curl = Curl::Easy.new("https://api:#{self.api_key}@api.mailgun.net/v2/#{self.api_host}/messages.mime")
+ curl.multipart_form_post = true
+ curl.http_post(*data)
+
+ if curl.response_code != 200
+
+ begin
+ error = ActiveSupport::JSON.decode(curl.body_str)["message"]
+ rescue
+ error = "Unknown Mailgun Error"
+ end
+
+ raise Mailgun::DeliveryError.new(error)
+ end
+
+ end
+
+
+ end
+
+end
+
+ActionMailer::Base.add_delivery_method :mailgun, Mailgun::DeliveryMethod
+
View
46 mailgun-rails.gemspec
@@ -0,0 +1,46 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = "mailgun-rails"
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Tanel Suurhans", "Tarmo Lehtpuu"]
+ s.date = "2011-12-13"
+ s.description = "Mailgun adapter for Rails."
+ s.email = ["tanel.suurhans@perfectline.ee", "tarmo.lehtpuu@perfectline.ee"]
+ s.extra_rdoc_files = [
+ "README.markdown"
+ ]
+ s.files = [
+ "MIT-LICENCE",
+ "README.markdown",
+ "lib/mailgun-rails.rb"
+ ]
+ s.homepage = "https://github.com/perfectline/mailgun-rails"
+ s.require_paths = ["lib"]
+ s.rubygems_version = "1.8.10"
+ s.summary = "Mailgun adapter for Rails."
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<curb>, [">= 0"])
+ s.add_runtime_dependency(%q<active_support>, [">= 0"])
+ s.add_runtime_dependency(%q<action_mailer>, [">= 0"])
+ else
+ s.add_dependency(%q<curb>, [">= 0"])
+ s.add_dependency(%q<active_support>, [">= 0"])
+ s.add_dependency(%q<action_mailer>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<curb>, [">= 0"])
+ s.add_dependency(%q<active_support>, [">= 0"])
+ s.add_dependency(%q<action_mailer>, [">= 0"])
+ end
+end
+

0 comments on commit bd9d264

Please sign in to comment.