mailgun-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/MIT-LICENCE +20 -0
  2. data/README.markdown +0 -0
  3. data/lib/mailgun-rails.rb +62 -0
  4. metadata +84 -0
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 PerfectLine LLC (www.perfectline.co.uk)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File without changes
@@ -0,0 +1,62 @@
1
+ require "action_mailer"
2
+ require "active_support"
3
+ require "curb"
4
+
5
+ module Mailgun
6
+
7
+ class DeliveryError < StandardError
8
+ end
9
+
10
+ class DeliveryMethod
11
+
12
+ attr_accessor :settings
13
+
14
+ def initialize(settings)
15
+ self.settings = settings
16
+ end
17
+
18
+ def api_host
19
+ self.settings[:api_host]
20
+ end
21
+
22
+ def api_key
23
+ self.settings[:api_key]
24
+ end
25
+
26
+ def deliver!(mail)
27
+
28
+ body = Curl::PostField.content("message", mail.encoded)
29
+ body.remote_file = "message"
30
+ body.content_type = "application/octet-stream"
31
+
32
+ data = []
33
+ data << body
34
+
35
+ mail.destinations.each do |destination|
36
+ data << Curl::PostField.content("to", destination)
37
+ end
38
+
39
+ curl = Curl::Easy.new("https://api:#{self.api_key}@api.mailgun.net/v2/#{self.api_host}/messages.mime")
40
+ curl.multipart_form_post = true
41
+ curl.http_post(*data)
42
+
43
+ if curl.response_code != 200
44
+
45
+ begin
46
+ error = ActiveSupport::JSON.decode(curl.body_str)["message"]
47
+ rescue
48
+ error = "Unknown Mailgun Error"
49
+ end
50
+
51
+ raise Mailgun::DeliveryError.new(error)
52
+ end
53
+
54
+ end
55
+
56
+
57
+ end
58
+
59
+ end
60
+
61
+ ActionMailer::Base.add_delivery_method :mailgun, Mailgun::DeliveryMethod
62
+
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mailgun-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tanel Suurhans
9
+ - Tarmo Lehtpuu
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-12-13 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: curb
17
+ requirement: &2155891680 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2155891680
26
+ - !ruby/object:Gem::Dependency
27
+ name: active_support
28
+ requirement: &2155891000 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2155891000
37
+ - !ruby/object:Gem::Dependency
38
+ name: action_mailer
39
+ requirement: &2155890340 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *2155890340
48
+ description: Mailgun adapter for Rails.
49
+ email:
50
+ - tanel.suurhans@perfectline.ee
51
+ - tarmo.lehtpuu@perfectline.ee
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files:
55
+ - README.markdown
56
+ files:
57
+ - MIT-LICENCE
58
+ - README.markdown
59
+ - lib/mailgun-rails.rb
60
+ homepage: https://github.com/perfectline/mailgun-rails
61
+ licenses: []
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 1.8.10
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Mailgun adapter for Rails.
84
+ test_files: []