rails-mailgun 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rails-mailgun.rb +1 -1
- data/lib/rails-mailgun/mail.rb +36 -13
- data/lib/rails-mailgun/version.rb +1 -1
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa58d03cd1bbb9b058e23af701a9339a0d4b3c59
|
4
|
+
data.tar.gz: 35a65120f2ee24490c12479f12664bb0e24438bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f654d9b1a0248a70874c1886146a908b2f6e73a2980c11ac8478d91e10a82dcc130588a1fc9083a93d8867692c4576bc5b30e2de1df9e7b3f7ac3d38cf565314
|
7
|
+
data.tar.gz: 307674d92a587bfda5d81138a87560d86bbcff299cfa5dad501d7844d04de246da842d93aa1ac7077efd0a7664c25d530d01abafc145c40165b48d958955d9b6
|
data/lib/rails-mailgun.rb
CHANGED
data/lib/rails-mailgun/mail.rb
CHANGED
@@ -6,25 +6,48 @@ module RailsMailgun
|
|
6
6
|
attr_accessor :settings
|
7
7
|
|
8
8
|
def deliver!(mail)
|
9
|
-
|
9
|
+
client = Mailgun::Client.new(settings[:api_key])
|
10
|
+
client.send_message(settings[:api_host], message_object(mail))
|
10
11
|
end
|
11
12
|
|
12
13
|
private
|
13
|
-
def message_url
|
14
|
-
"https://api:#{settings[:api_key]}@api.mailgun.net/v2/#{settings[:api_host]}/messages"
|
15
|
-
end
|
16
14
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
def message_object(mail)
|
16
|
+
message_object = Mailgun::MessageBuilder.new
|
17
|
+
|
18
|
+
message_object.set_from_address( mail.from.join(' ') )
|
19
|
+
mail.to.each { |t| message_object.add_recipient(:to, t) }
|
20
|
+
|
21
|
+
message_object.set_subject(mail.subject)
|
22
|
+
|
23
|
+
if mail.multipart?
|
24
|
+
set_message_object_body(message_object, mail.parts.first)
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
+
mail.attachments.each do |attachment|
|
27
|
+
tempfile = create_tempfile_from_attachment(attachment)
|
28
|
+
message_object.add_attachment(tempfile.path, attachment.filename)
|
29
|
+
end
|
30
|
+
else
|
31
|
+
set_message_object_body(message_object, mail)
|
32
|
+
end
|
33
|
+
|
34
|
+
message_object
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_message_object_body(message_object, mail)
|
38
|
+
if mail.content_type.match(/html/)
|
39
|
+
message_object.set_html_body(mail.body.to_s)
|
40
|
+
else
|
41
|
+
message_object.set_text_body(mail.body.to_s)
|
42
|
+
end
|
43
|
+
end
|
26
44
|
|
27
|
-
|
45
|
+
def create_tempfile_from_attachment(attachment)
|
46
|
+
tempfile = Tempfile.new(attachment.filename)
|
47
|
+
tempfile.binmode
|
48
|
+
tempfile.write(attachment.body.raw_source)
|
49
|
+
tempfile.close
|
50
|
+
tempfile
|
28
51
|
end
|
29
52
|
end
|
30
53
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-mailgun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuva Kumar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.2.13
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.2.13
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: mailgun-ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.0.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.0.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec-rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 2.14.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.14.0
|
55
55
|
description:
|
@@ -60,13 +60,13 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
+
- MIT-LICENSE
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- lib/rails-mailgun.rb
|
63
67
|
- lib/rails-mailgun/engine.rb
|
64
68
|
- lib/rails-mailgun/mail.rb
|
65
69
|
- lib/rails-mailgun/version.rb
|
66
|
-
- lib/rails-mailgun.rb
|
67
|
-
- MIT-LICENSE
|
68
|
-
- Rakefile
|
69
|
-
- README.md
|
70
70
|
homepage: https://github.com/code-mancers/rails-mailgun
|
71
71
|
licenses: []
|
72
72
|
metadata: {}
|
@@ -76,17 +76,17 @@ require_paths:
|
|
76
76
|
- lib
|
77
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- -
|
79
|
+
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
83
|
requirements:
|
84
|
-
- -
|
84
|
+
- - ">="
|
85
85
|
- !ruby/object:Gem::Version
|
86
86
|
version: '0'
|
87
87
|
requirements: []
|
88
88
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
89
|
+
rubygems_version: 2.2.2
|
90
90
|
signing_key:
|
91
91
|
specification_version: 4
|
92
92
|
summary: Mailgun integration for rails
|