mailjet 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +57 -4
- data/lib/mailjet/connection.rb +15 -3
- data/lib/mailjet/mailer.rb +4 -2
- data/lib/mailjet/message_delivery.rb +1 -1
- data/lib/mailjet/resource.rb +7 -2
- data/lib/mailjet/resources/contactdata.rb +1 -1
- data/lib/mailjet/resources/manycontacts.rb +1 -1
- data/lib/mailjet/version.rb +1 -1
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6f0712c222da5b6148645338771953d6885fb65
|
4
|
+
data.tar.gz: 238b87870601f1f7811d25fc8758a681d6f0e194
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8e4431ff38ec080662933322d3a4896dad4ccebb17fe0cfb7dd626c0dfcafef625c39710586f8e9bdf9c4bd6f9c021fc7b56de7f37c90a099bc6a1f653071d2
|
7
|
+
data.tar.gz: 10ab0c2ab2f02c868d866a1496aaa856c77b60a373de65e43d260ea0c847e6cda08667d89e308fdd9c3a4c33917ef7d9367bd856c7bbcd9b2da2009d2979c7f9
|
data/README.md
CHANGED
@@ -91,16 +91,16 @@ Mailjet.configure do |config|
|
|
91
91
|
end
|
92
92
|
```
|
93
93
|
|
94
|
-
`domain` is needed if you send emails with :mailjet's SMTP (below)
|
95
94
|
|
96
95
|
`default_from` is optional if you send emails with :mailjet's SMTP (below)
|
97
96
|
|
98
97
|
### Send emails with ActionMailer
|
98
|
+
A quick walkthrough to using Action Mailer from the documentation [HERE](http://guides.rubyonrails.org/action_mailer_basics.html)
|
99
99
|
|
100
|
-
|
100
|
+
First set your delivery method:
|
101
101
|
|
102
102
|
```ruby
|
103
|
-
# application.rb
|
103
|
+
# application.rb or config/environments specific settings, which take precedence
|
104
104
|
config.action_mailer.delivery_method = :mailjet
|
105
105
|
|
106
106
|
```
|
@@ -114,6 +114,53 @@ config.action_mailer.delivery_method = :mailjet_api
|
|
114
114
|
|
115
115
|
You can use mailjet specific options with `delivery_method_options` as detailed in the official [ActionMailer doc][actionmailerdoc]
|
116
116
|
|
117
|
+
Creating a Mailer:
|
118
|
+
```ruby
|
119
|
+
$ rails generate mailer UserMailer
|
120
|
+
|
121
|
+
create app/mailers/user_mailer.rb
|
122
|
+
create app/mailers/application_mailer.rb
|
123
|
+
invoke erb
|
124
|
+
create app/views/user_mailer
|
125
|
+
create app/views/layouts/mailer.text.erb
|
126
|
+
create app/views/layouts/mailer.html.erb
|
127
|
+
invoke test_unit
|
128
|
+
create test/mailers/user_mailer_test.rb
|
129
|
+
create test/mailers/previews/user_mailer_preview.rb
|
130
|
+
```
|
131
|
+
|
132
|
+
In the UserMailer class you can set up your email method:
|
133
|
+
```ruby
|
134
|
+
#app/mailers/user_mailer.rb
|
135
|
+
class UserMailer < ApplicationMailer
|
136
|
+
def welcome_email()
|
137
|
+
mail(from: "me@mailjet.com", to: "you@mailjet.com",
|
138
|
+
subject: "This is a nice welcome email")
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
```
|
143
|
+
There's also the ability to set [Mailjet custom headers](https://dev.mailjet.com/guides/send-api-guide/)
|
144
|
+
```ruby
|
145
|
+
#app/mailers/user_mailer.rb
|
146
|
+
class UserMailer < ApplicationMailer
|
147
|
+
def welcome_email()
|
148
|
+
mail.header['X-MJ-CustomID'] = 'custom value'
|
149
|
+
mail.header['X-MJ-EventPayload'] = 'custom payload'
|
150
|
+
mail(from: "me@mailjet.com", to: "you@mailjet.com",
|
151
|
+
subject: "This is a nice welcome email")
|
152
|
+
end
|
153
|
+
end
|
154
|
+
```
|
155
|
+
For sending email, you can call the method with a variety of MessageDelivery priorities:
|
156
|
+
```ruby
|
157
|
+
#In this example, we are sending immediately
|
158
|
+
UserMailer.welcome_email.deliver_now!
|
159
|
+
```
|
160
|
+
For more information on ActionMailer::MessageDeilvery, see the documentation [HERE](http://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html)
|
161
|
+
|
162
|
+
|
163
|
+
|
117
164
|
## Manage your campaigns
|
118
165
|
|
119
166
|
This gem provide a convenient wrapper for consuming the mailjet API. The wrapper is highly inspired by [ActiveResource][activeresource] even though it does not depend on it.
|
@@ -207,7 +254,13 @@ Mailjet::MessageDelivery.create(from: "me@example.com", to: ["you@example.com",
|
|
207
254
|
|
208
255
|
In order to Mailjet modifiers, you cannot use the regular form of Ruby 2 hashes. Instead, use a String `e.g.: 'mj-prio' => 2` or a quoted symbol `e.g.: 'mj-prio' => 2`.
|
209
256
|
|
210
|
-
|
257
|
+
In these modifiers, there is now the ability to add a Mailjet custom-id or Mailjet Custom payload using the following:
|
258
|
+
```ruby
|
259
|
+
'mj-customid' => "A useful custom ID"
|
260
|
+
'mj-eventpayload' => '{"message": "hello world"}'
|
261
|
+
```
|
262
|
+
|
263
|
+
For more information on custom properties and available params, see the [official doc][send-api-doc].
|
211
264
|
|
212
265
|
## Track email delivery
|
213
266
|
|
data/lib/mailjet/connection.rb
CHANGED
@@ -15,11 +15,22 @@ module Mailjet
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def initialize(end_point, api_key, secret_key, options = {})
|
18
|
+
##charles proxy
|
19
|
+
# RestClient.proxy = "http://127.0.0.1:8888"
|
20
|
+
##
|
21
|
+
##Output for debugging
|
22
|
+
# RestClient.log =
|
23
|
+
# Object.new.tap do |proxy|
|
24
|
+
# def proxy.<<(message)
|
25
|
+
# Rails.logger.info message
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
##
|
18
29
|
adapter_class = options[:adapter_class] || RestClient::Resource
|
19
|
-
|
20
30
|
self.public_operations = options[:public_operations] || []
|
21
31
|
self.read_only = options[:read_only]
|
22
|
-
self.adapter = adapter_class.new(end_point, options.merge(user: api_key, password: secret_key))
|
32
|
+
# self.adapter = adapter_class.new(end_point, options.merge(user: api_key, password: secret_key, :verify_ssl => false, content_type: 'application/json'))
|
33
|
+
self.adapter = adapter_class.new(end_point, options.merge(user: api_key, password: secret_key, content_type: 'application/json'))
|
23
34
|
end
|
24
35
|
|
25
36
|
def get(additional_headers = {}, &block)
|
@@ -41,12 +52,13 @@ module Mailjet
|
|
41
52
|
private
|
42
53
|
|
43
54
|
def handle_api_call(method, additional_headers = {}, payload = {}, &block)
|
55
|
+
format_payload = (additional_headers[:content_type] == :json) ? payload.to_json : payload
|
44
56
|
raise Mailjet::MethodNotAllowed unless method_allowed(method)
|
45
57
|
|
46
58
|
if [:get, :delete].include?(method)
|
47
59
|
@adapter.send(method, additional_headers, &block)
|
48
60
|
else
|
49
|
-
@adapter.send(method,
|
61
|
+
@adapter.send(method, format_payload, additional_headers, &block)
|
50
62
|
end
|
51
63
|
rescue RestClient::Exception => e
|
52
64
|
handle_exeception(e, additional_headers, payload)
|
data/lib/mailjet/mailer.rb
CHANGED
@@ -22,7 +22,7 @@ ActionMailer::Base.add_delivery_method :mailjet, Mailjet::Mailer
|
|
22
22
|
class Mailjet::APIMailer
|
23
23
|
def initialize(options = {})
|
24
24
|
ActionMailer::Base.default(:from => Mailjet.config.default_from) if Mailjet.config.default_from.present?
|
25
|
-
@delivery_method_options = options.slice(:'mj-prio', :'mj-campaign', :'mj-deduplicatecampaign', :'mj-trackopen', :'mj-trackclick', :'header')
|
25
|
+
@delivery_method_options = options.slice(:'mj-prio', :'mj-campaign', :'mj-deduplicatecampaign', :'mj-trackopen', :'mj-trackclick', :'mj-customid', :'mj-eventpayload', :'header')
|
26
26
|
end
|
27
27
|
|
28
28
|
def deliver!(mail)
|
@@ -43,7 +43,9 @@ class Mailjet::APIMailer
|
|
43
43
|
to: mail.to,
|
44
44
|
cc: mail.cc,
|
45
45
|
bcc: mail.bcc,
|
46
|
-
subject: mail.subject
|
46
|
+
subject: mail.subject,
|
47
|
+
'mj-customid': mail['X-MJ-CustomID'] && mail['X-MJ-CustomID'].value,
|
48
|
+
'mj-eventpayload': mail['X-MJ-EventPayload'] && mail['X-MJ-EventPayload'].value
|
47
49
|
}.merge(content).merge(@delivery_method_options)
|
48
50
|
|
49
51
|
Mailjet::MessageDelivery.create(payload)
|
@@ -5,6 +5,6 @@ module Mailjet
|
|
5
5
|
include Mailjet::Resource
|
6
6
|
self.resource_path = 'v3/send/message'
|
7
7
|
self.public_operations = [:post]
|
8
|
-
self.properties = [:from, :sender, :to, :cc, :bcc, :subject, :text, :html, :attachment, :inlineattachment, :header]
|
8
|
+
self.properties = [:from, :sender, :to, :cc, :bcc, :subject, :text, :html, :attachment, :inlineattachment, :header, :'mj-customid', :'mj-eventpayload', :'mj-trackclick']
|
9
9
|
end
|
10
10
|
end
|
data/lib/mailjet/resource.rb
CHANGED
@@ -19,10 +19,11 @@ module Mailjet
|
|
19
19
|
extend ActiveSupport::Concern
|
20
20
|
|
21
21
|
included do
|
22
|
-
cattr_accessor :resource_path, :public_operations, :read_only, :filters, :properties, :action
|
22
|
+
cattr_accessor :resource_path, :public_operations, :read_only, :filters, :properties, :action, :non_json_urls
|
23
23
|
cattr_writer :connection
|
24
24
|
|
25
25
|
def self.connection
|
26
|
+
@non_json_urls = ["v3/send/message"] #urls that don't accept JSON input
|
26
27
|
class_variable_get(:@@connection) || default_connection
|
27
28
|
end
|
28
29
|
|
@@ -36,7 +37,11 @@ module Mailjet
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def self.default_headers
|
39
|
-
|
40
|
+
if @non_json_urls.include?(self.resource_path)#don't use JSON if Send API
|
41
|
+
{ accept: :json, accept_encoding: :deflate }
|
42
|
+
else
|
43
|
+
{ accept: :json, accept_encoding: :deflate, content_type: :json } #use JSON if *not* Send API
|
44
|
+
end
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
@@ -6,7 +6,7 @@ module Mailjet
|
|
6
6
|
self.resource_path = 'v3/REST/contactdata'
|
7
7
|
self.public_operations = [:get, :put, :post, :delete]
|
8
8
|
self.filters = [:campaign, :contacts_list, :fields, :is_unsubscribed, :last_activity_at, :recipient, :status]
|
9
|
-
self.properties = [:contact_id, :data, :id]
|
9
|
+
self.properties = [:contact_id, :data, :id, 'ContactID', 'Name', 'Value']
|
10
10
|
|
11
11
|
end
|
12
12
|
end
|
@@ -6,7 +6,7 @@ module Mailjet
|
|
6
6
|
self.resource_path = 'v3/REST/manycontacts'
|
7
7
|
self.public_operations = [:post]
|
8
8
|
self.filters = []
|
9
|
-
self.properties = [:action, :addresses, :errors, :force, :
|
9
|
+
self.properties = [:action, :addresses, :errors, :force, :list_id, :recipients]
|
10
10
|
|
11
11
|
end
|
12
12
|
end
|
data/lib/mailjet/version.rb
CHANGED
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.0.
|
4
|
+
version: 1.0.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: 2015-
|
14
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -223,20 +223,6 @@ dependencies:
|
|
223
223
|
- - ">="
|
224
224
|
- !ruby/object:Gem::Version
|
225
225
|
version: '0'
|
226
|
-
- !ruby/object:Gem::Dependency
|
227
|
-
name: debugger
|
228
|
-
requirement: !ruby/object:Gem::Requirement
|
229
|
-
requirements:
|
230
|
-
- - ">="
|
231
|
-
- !ruby/object:Gem::Version
|
232
|
-
version: '0'
|
233
|
-
type: :development
|
234
|
-
prerelease: false
|
235
|
-
version_requirements: !ruby/object:Gem::Requirement
|
236
|
-
requirements:
|
237
|
-
- - ">="
|
238
|
-
- !ruby/object:Gem::Version
|
239
|
-
version: '0'
|
240
226
|
- !ruby/object:Gem::Dependency
|
241
227
|
name: rspec
|
242
228
|
requirement: !ruby/object:Gem::Requirement
|
@@ -382,7 +368,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
382
368
|
version: '0'
|
383
369
|
requirements: []
|
384
370
|
rubyforge_project:
|
385
|
-
rubygems_version: 2.
|
371
|
+
rubygems_version: 2.4.5
|
386
372
|
signing_key:
|
387
373
|
specification_version: 4
|
388
374
|
summary: Mailjet a powerful all-in-one email service provider clients can use to get
|