mailjet 1.5.2 → 1.5.3

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: 2e5aca2e6992e3629225e95b54f92c345b9a425a
4
- data.tar.gz: eb1f16741cb17b0a1db5303e29fd57fc853c44ae
3
+ metadata.gz: ce7a69f28969e1a632cc70e07a8a04b973576f5f
4
+ data.tar.gz: 3a7bf17b3fd83efeb88427b6bc09f184d41b9996
5
5
  SHA512:
6
- metadata.gz: 48c6bd96487aa123c5a201157e4d1d199325ebe582c54423bad89b0ad58c5c9d1f3f5d692ff94257ecd6745625ab1939dfb908cf81f55258a6081125a9d0747b
7
- data.tar.gz: 54836996f885ea2286b23ff127d09913722fac7819764436e9f757cbd93bd8d4f0374fd207615438ef417acc1199d575896c8b91688198057abad0c81d43bf30
6
+ metadata.gz: 3043cf5a15c67cb008677ea98b439ef656e5ce5f6bcad3f3fba3497ea1dae6f8f99e637d7a27cb07c11ee1f12d46e4e30b573ea01258e1901f32cdc6a4c7a5c2
7
+ data.tar.gz: 672355e584024830232f12dcbea25e1d6e5ac543ddf56476cd2a64b55e45b9a920eb4f667a7e08ae6f9ca5f0a7bf6f0d22812013705ecf49bac69ad70e344e5d
@@ -2,18 +2,17 @@ require 'active_support/core_ext/module/attribute_accessors'
2
2
 
3
3
  module Mailjet
4
4
  module Configuration
5
- mattr_accessor :api_key
6
- mattr_accessor :secret_key
7
- mattr_accessor :default_from
8
- mattr_accessor :api_version do
9
- 'v3'
10
- end
11
- mattr_accessor :end_point do
12
- 'https://api.mailjet.com'
13
- end
14
- mattr_accessor :perform_api_call do
15
- true
16
- end
5
+ mattr_accessor :api_key, :secret_key, :default_from
17
6
 
7
+ DEFAULT = {
8
+ api_version: 'v3',
9
+ end_point: 'https://api.mailjet.com',
10
+ perform_api_call: true,
11
+ }
12
+
13
+ DEFAULT.each do |param, default_value|
14
+ mattr_accessor param
15
+ self.send("#{param}=", default_value)
16
+ end
18
17
  end
19
18
  end
@@ -69,7 +69,7 @@ module Mailjet
69
69
  @adapter.send(method, formatted_payload, additional_headers, &block)
70
70
  end
71
71
  else
72
- return {'Count': 0, 'Data': [mock_api_call: true], 'Total': 0}.to_json
72
+ return {'Count' => 0, 'Data' => [mock_api_call: true], 'Total' => 0}.to_json
73
73
  end
74
74
  rescue RestClient::Exception => e
75
75
  handle_exception(e, additional_headers, formatted_payload)
@@ -49,8 +49,7 @@ class Mailjet::APIMailer
49
49
  )
50
50
  end
51
51
 
52
- def deliver!(mail, options = nil)
53
- # p mail.header.fields
52
+ def deliver!(mail, options = {})
54
53
 
55
54
  if (options && options.kind_of?(Object) && options['version'].present?)
56
55
  @version = options['version']
@@ -66,20 +65,27 @@ class Mailjet::APIMailer
66
65
  end
67
66
 
68
67
  if (@version == 'v3.1')
69
- Mailjet::Send.create({:Messages => [setContentV3_1(mail)]})
68
+ Mailjet::Send.create({:Messages => [setContentV3_1(mail)]}, options)
70
69
  else
71
- Mailjet::Send.create(setContentV3_0(mail))
70
+ Mailjet::Send.create(setContentV3_0(mail), options)
72
71
  end
73
72
  end
74
73
 
75
74
  def setContentV3_1(mail)
76
75
  content = {}
76
+
77
77
  content[:TextPart] = mail.text_part.try(:decoded) if !mail.text_part.blank?
78
78
  content[:HTMLPart] = mail.html_part.try(:decoded) if !mail.html_part.blank?
79
79
 
80
+ # try message `body` as fallback if no content found
81
+ unless content[:TextPart] || content[:HTMLPart] || mail.body.try(:raw_source).empty?
82
+ content[mail.content_type.try(:include?,'text/html') ? :HTMLPart : :TextPart] = mail.body.raw_source
83
+ end
84
+
85
+
80
86
  if mail.attachments.any?
81
87
  content[:Attachments] = []
82
- content[:InlineAttachments] = []
88
+ content[:InlinedAttachments] = []
83
89
 
84
90
  mail.attachments.each do |attachment|
85
91
  mailjet_attachment = {
@@ -90,7 +96,7 @@ class Mailjet::APIMailer
90
96
 
91
97
  if attachment.inline?
92
98
  mailjet_attachment['ContentId'] = attachment.content_id
93
- content[:InlineAttachments].push(mailjet_attachment)
99
+ content[:InlinedAttachments].push(mailjet_attachment)
94
100
  else
95
101
  content[:Attachments].push(mailjet_attachment)
96
102
  end
@@ -108,14 +114,14 @@ class Mailjet::APIMailer
108
114
  end
109
115
  end
110
116
 
111
- # Reply-To is not a property in Mailjet Send API
117
+ # ReplyTo property was added in v3.1
112
118
  # Passing it as an header if mail.reply_to
113
119
 
114
120
  if mail.reply_to
115
- if mail.reply_to.display_names.first
116
- content[:Headers]['Reply-To'] = {:Email=> mail[:reply_to].addresses.first, :Name=> mail[:reply_to].display_names.first}
121
+ if mail.reply_to.respond_to?(:display_names) && mail.reply_to.display_names.first
122
+ content[:ReplyTo] = {:Email=> mail[:reply_to].addresses.first, :Name=> mail[:reply_to].display_names.first}
117
123
  else
118
- content[:Headers]['Reply-To'] = {:Email=> mail[:reply_to].addresses.first}
124
+ content[:ReplyTo] = {:Email=> mail[:reply_to].addresses.first}
119
125
  end
120
126
  end
121
127
 
@@ -199,6 +205,11 @@ class Mailjet::APIMailer
199
205
  content[:text_part] = mail.text_part.try(:decoded) if !mail.text_part.blank?
200
206
  content[:html_part] = mail.html_part.try(:decoded) if !mail.html_part.blank?
201
207
 
208
+ # try message `body` as fallback if no content found
209
+ unless content[:text_part] || content[:html_part] || mail.body.try(:raw_source).empty?
210
+ content[mail.content_type.try(:include?,'text/html') ? :html_part : :text_part] = mail.body.raw_source
211
+ end
212
+
202
213
  # Formatting attachments (inline + regular)
203
214
  unless mail.attachments.empty?
204
215
  content[:attachments] = []
@@ -3,7 +3,7 @@ module Mailjet
3
3
  include Mailjet::Resource
4
4
  self.action = "schedule"
5
5
  self.resource_path = "REST/newsletter/id/#{self.action}"
6
- self.public_operations = [:post, :delete]
6
+ self.public_operations = [:get, :post, :delete]
7
7
  self.filters = []
8
8
  self.resourceprop = [:date]
9
9
 
@@ -1,3 +1,3 @@
1
1
  module Mailjet
2
- VERSION = "1.5.2"
2
+ VERSION = "1.5.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailjet
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Nappy
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-06-05 00:00:00.000000000 Z
14
+ date: 2017-06-30 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport