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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 416599af643ce06b2287dc7a210b48cbb11b9322
4
- data.tar.gz: 441ecec58ee0e2b572cc2b1bab9a80ed3890fc86
3
+ metadata.gz: aa58d03cd1bbb9b058e23af701a9339a0d4b3c59
4
+ data.tar.gz: 35a65120f2ee24490c12479f12664bb0e24438bb
5
5
  SHA512:
6
- metadata.gz: 41fa9bb189c2927505fb437c4a406732c5c0bd9a3df8f97bffb1a3de9efc9069595b1c1434c157626114cf46d927ab8e3ce1afbe4740c0c001c6d980db444674
7
- data.tar.gz: 53c458a6d56040cf53661fc88044ff9d541f4a79f18e88d4160ebc8514966f39a56014e4585b80f199424874be1b2f82ca243c38a5825fa3317f621434b358d1
6
+ metadata.gz: f654d9b1a0248a70874c1886146a908b2f6e73a2980c11ac8478d91e10a82dcc130588a1fc9083a93d8867692c4576bc5b30e2de1df9e7b3f7ac3d38cf565314
7
+ data.tar.gz: 307674d92a587bfda5d81138a87560d86bbcff299cfa5dad501d7844d04de246da842d93aa1ac7077efd0a7664c25d530d01abafc145c40165b48d958955d9b6
@@ -1,6 +1,6 @@
1
1
  require "rails-mailgun/engine"
2
2
  require "rails-mailgun/mail"
3
- require "rest-client"
3
+ require 'mailgun'
4
4
 
5
5
  module RailsMailgun
6
6
  end
@@ -6,25 +6,48 @@ module RailsMailgun
6
6
  attr_accessor :settings
7
7
 
8
8
  def deliver!(mail)
9
- RestClient.post message_url, message_params(mail)
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 message_params(mail)
18
- message_params = {
19
- from: mail.from.join(" "),
20
- to: mail.to.join(", "),
21
- subject: mail.subject
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
- type = mail.content_type.match(/html/) ? :html : :text
25
- message_params[type] = mail.body.to_s
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
- message_params
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
@@ -1,3 +1,3 @@
1
1
  module RailsMailgun
2
- VERSION = "0.0.1"
2
+ VERSION = '0.1.0'
3
3
  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.1
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: 2013-09-02 00:00:00.000000000 Z
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: rest-client
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.6.7
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.6.7
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.0.3
89
+ rubygems_version: 2.2.2
90
90
  signing_key:
91
91
  specification_version: 4
92
92
  summary: Mailgun integration for rails