mailjet 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +49 -5
- data/lib/mailjet/configuration.rb +2 -0
- data/lib/mailjet/connection.rb +13 -6
- data/lib/mailjet/mailer.rb +13 -13
- data/lib/mailjet/resource.rb +13 -7
- data/lib/mailjet/resources/contact_getcontactslists.rb +12 -0
- data/lib/mailjet/resources/contact_managecontactslists.rb +12 -0
- data/lib/mailjet/resources/contact_managemanycontacts.rb +13 -0
- data/lib/mailjet/resources/contactslist_managecontact.rb +12 -0
- data/lib/mailjet/resources/contactslist_managemanycontacts.rb +12 -0
- data/lib/mailjet/resources/dns.rb +12 -0
- data/lib/mailjet/resources/dns_check.rb +13 -0
- data/lib/mailjet/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bce510af0e64da9901c04173e262e897483fa7c8
|
4
|
+
data.tar.gz: e8824a8d720e46b0b37d5fdd654b2483a397eb43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d34de055592b05c8b29a801972b6e9b157860650102e441ff13782cbc95ada82ea25b635773075453cd37cd268dd2f184773da37c87b7abdfb71a3661648b60b
|
7
|
+
data.tar.gz: 471a5630d3258ebc1c7a245dcc6c86cacc6ddacdd8413e44fe19a4742d01029471e2ff81a9aa486cc359dc55aae853cc6ed66aa06716e493f9c7726d2e9daad6
|
data/README.md
CHANGED
@@ -92,7 +92,7 @@ end
|
|
92
92
|
```
|
93
93
|
|
94
94
|
|
95
|
-
`default_from` is optional if you send emails with
|
95
|
+
`default_from` is optional if you send emails with `:mailjet`'s SMTP (below)
|
96
96
|
|
97
97
|
### Send emails with ActionMailer
|
98
98
|
A quick walkthrough to using Action Mailer from the documentation [HERE](http://guides.rubyonrails.org/action_mailer_basics.html)
|
@@ -152,12 +152,12 @@ class UserMailer < ApplicationMailer
|
|
152
152
|
end
|
153
153
|
end
|
154
154
|
```
|
155
|
-
For sending email, you can call the method with a variety of MessageDelivery priorities:
|
155
|
+
For sending email, you can call the method with a variety of `MessageDelivery` priorities:
|
156
156
|
```ruby
|
157
157
|
#In this example, we are sending immediately
|
158
158
|
UserMailer.welcome_email.deliver_now!
|
159
159
|
```
|
160
|
-
For more information on ActionMailer::MessageDeilvery
|
160
|
+
For more information on `ActionMailer::MessageDeilvery`, see the documentation [HERE](http://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html)
|
161
161
|
|
162
162
|
|
163
163
|
|
@@ -239,16 +239,58 @@ You can refine queries using [API Filters][apidoc-recipient]`*` as well as the f
|
|
239
239
|
=> #<Mailjet::Listrecipient>
|
240
240
|
```
|
241
241
|
|
242
|
+
### Action Endpoints
|
243
|
+
|
244
|
+
Some APIs allow the use of action endpoints:
|
245
|
+
* [/newsletter](http://dev.mailjet.com/email-api/v3/newsletter/)
|
246
|
+
* [/contact](http://dev.mailjet.com/email-api/v3/contact/)
|
247
|
+
* [/contactslist](http://dev.mailjet.com/email-api/v3/contactslist/)
|
248
|
+
|
249
|
+
To use them in this wrapper, the API endpoint is in the beginning, followed by an underscore, followed by the action you are performing.
|
250
|
+
|
251
|
+
For example, the following performs `managemanycontacts` on the `contactslist` endpoint:
|
252
|
+
where 4 is the `listid` and 3025 is the `jobid`
|
253
|
+
``` ruby
|
254
|
+
Mailjet::Contactslist_managemanycontacts.find(4, 3025)
|
255
|
+
```
|
256
|
+
|
257
|
+
Each action endpoint requires the ID of the object you are changing. To 'create' (POST), pass the ID as a variable like such:
|
258
|
+
``` ruby
|
259
|
+
Mailjet::Contactslist_managecontact.create(id: 1, action: "unsub", email: "example@me.com", name: "tyler")
|
260
|
+
```
|
261
|
+
|
262
|
+
To 'find' (GET), pass the ID as a variable like such:
|
263
|
+
``` ruby
|
264
|
+
Mailjet::Contact_getcontactslists.find(1)
|
265
|
+
# will return all the lists containing the contact with id 1
|
266
|
+
```
|
267
|
+
|
268
|
+
Managing large amount of contacts asyncronously, uploading many contacts and returns a `job_id`
|
269
|
+
``` ruby
|
270
|
+
managecontactslists = Mailjet::Contact_managemanycontacts.create(contacts_lists: [{:ListID => 234, :action => "addnoforce"}])
|
271
|
+
```
|
272
|
+
|
273
|
+
To 'find' (GET) with also a job ID, pass two parameters - first, the ID of the object; second, the job ID:
|
274
|
+
``` ruby
|
275
|
+
Mailjet::Contactslist_managemanycontacts.find(1, 34062)
|
276
|
+
# where 1 is the contactlist id and 34062 is the job id
|
277
|
+
```
|
278
|
+
|
279
|
+
Some actions are not attached to a specific resource, like /contact/managemanycontacts. In these cases when there is a job ID but no ID for the object when 'find'ing, pass `nil` as the first parameter:
|
280
|
+
``` ruby
|
281
|
+
Mailjet::Contact_managemanycontacts.find(nil, 34062)
|
282
|
+
```
|
283
|
+
|
242
284
|
## Send emails through API
|
243
285
|
|
244
286
|
In order to send emails through the API, you just have to `create` a new `MessageDelivery` resource.
|
245
287
|
|
246
|
-
```
|
288
|
+
``` ruby
|
247
289
|
Mailjet::MessageDelivery.create(from: "me@example.com", to: "you@example.com", subject: "Mailjet is awesome", text: "Yes, it is!")
|
248
290
|
```
|
249
291
|
|
250
292
|
If you want to send it to multiple recipients, just use an array:
|
251
|
-
```
|
293
|
+
``` ruby
|
252
294
|
Mailjet::MessageDelivery.create(from: "me@example.com", to: ["you@example.com", "someone-else@example.com"], subject: "Mailjet is awesome", text: "Yes, it is!")
|
253
295
|
```
|
254
296
|
|
@@ -262,6 +304,8 @@ In these modifiers, there is now the ability to add a Mailjet custom-id or Mailj
|
|
262
304
|
|
263
305
|
For more information on custom properties and available params, see the [official doc][send-api-doc].
|
264
306
|
|
307
|
+
##
|
308
|
+
|
265
309
|
## Track email delivery
|
266
310
|
|
267
311
|
You can setup your Rack application in order to receive feedback on emails you sent (clicks, etc.)
|
data/lib/mailjet/connection.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rest_client'
|
2
2
|
require 'mailjet/gem_extensions/rest_client'
|
3
3
|
require 'active_support/core_ext/module/delegation'
|
4
|
+
require 'json'
|
4
5
|
|
5
6
|
module Mailjet
|
6
7
|
class Connection
|
@@ -11,7 +12,12 @@ module Mailjet
|
|
11
12
|
delegate :options, :concat_urls, :url, to: :adapter
|
12
13
|
|
13
14
|
def [](suburl, &new_block)
|
14
|
-
|
15
|
+
broken_url = url.split("/")
|
16
|
+
if broken_url.include?("contactslist") && broken_url.include?("managemanycontacts") && broken_url.last.to_i > 0
|
17
|
+
self.class.new(url, options[:user], options[:password], options)
|
18
|
+
else
|
19
|
+
self.class.new(concat_urls(url, suburl), options[:user], options[:password], options)
|
20
|
+
end
|
15
21
|
end
|
16
22
|
|
17
23
|
def initialize(end_point, api_key, secret_key, options = {})
|
@@ -52,16 +58,16 @@ module Mailjet
|
|
52
58
|
private
|
53
59
|
|
54
60
|
def handle_api_call(method, additional_headers = {}, payload = {}, &block)
|
55
|
-
|
61
|
+
formatted_payload = (additional_headers[:content_type] == :json) ? payload.to_json : payload
|
56
62
|
raise Mailjet::MethodNotAllowed unless method_allowed(method)
|
57
63
|
|
58
64
|
if [:get, :delete].include?(method)
|
59
65
|
@adapter.send(method, additional_headers, &block)
|
60
66
|
else
|
61
|
-
@adapter.send(method,
|
67
|
+
@adapter.send(method, formatted_payload, additional_headers, &block)
|
62
68
|
end
|
63
69
|
rescue RestClient::Exception => e
|
64
|
-
|
70
|
+
handle_exception(e, additional_headers, formatted_payload)
|
65
71
|
end
|
66
72
|
|
67
73
|
def method_allowed(method)
|
@@ -69,9 +75,10 @@ module Mailjet
|
|
69
75
|
public_operations.include?(method) && (method == :get || !read_only?)
|
70
76
|
end
|
71
77
|
|
72
|
-
def
|
78
|
+
def handle_exception(e, additional_headers, payload = {})
|
73
79
|
params = additional_headers[:params] || {}
|
74
|
-
|
80
|
+
formatted_payload = (additional_headers[:content_type] == :json) ? JSON.parse(payload) : payload
|
81
|
+
params = params.merge(formatted_payload)
|
75
82
|
|
76
83
|
raise Mailjet::ApiError.new(e.http_code, e.http_body, @adapter, @adapter.url, params)
|
77
84
|
end
|
data/lib/mailjet/mailer.rb
CHANGED
@@ -28,24 +28,24 @@ class Mailjet::APIMailer
|
|
28
28
|
def deliver!(mail)
|
29
29
|
if mail.multipart?
|
30
30
|
content = {
|
31
|
-
text
|
32
|
-
html
|
33
|
-
attachment
|
34
|
-
inlineattachment
|
31
|
+
:text => mail.text_part.try(:decoded),
|
32
|
+
:html => mail.html_part.try(:decoded),
|
33
|
+
:attachment => mail.attachments.select{ |a| !a.inline? }.try(:decoded),
|
34
|
+
:inlineattachment => mail.attachments.select{ |a| !a.inline? }.try(:decoded)
|
35
35
|
}
|
36
36
|
else
|
37
|
-
content = (mail.mime_type == "text/html") ? {html
|
37
|
+
content = (mail.mime_type == "text/html") ? {:html => mail.body.decoded} : {:text => mail.body.decoded}
|
38
38
|
end
|
39
39
|
|
40
40
|
payload = {
|
41
|
-
from
|
42
|
-
sender
|
43
|
-
to
|
44
|
-
cc
|
45
|
-
bcc
|
46
|
-
subject
|
47
|
-
'mj-customid'
|
48
|
-
'mj-eventpayload'
|
41
|
+
:from => mail.from || Mailjet.config.default_from,
|
42
|
+
:sender => mail.sender,
|
43
|
+
:to => mail.to,
|
44
|
+
:cc => mail.cc,
|
45
|
+
:bcc => mail.bcc,
|
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
|
49
49
|
}.merge(content).merge(@delivery_method_options)
|
50
50
|
|
51
51
|
Mailjet::MessageDelivery.create(payload)
|
data/lib/mailjet/resource.rb
CHANGED
@@ -38,10 +38,11 @@ module Mailjet
|
|
38
38
|
|
39
39
|
def self.default_headers
|
40
40
|
if @non_json_urls.include?(self.resource_path)#don't use JSON if Send API
|
41
|
-
{ accept: :json, accept_encoding: :deflate }
|
41
|
+
default_headers = { accept: :json, accept_encoding: :deflate }
|
42
42
|
else
|
43
|
-
{ accept: :json, accept_encoding: :deflate, content_type: :json } #use JSON if *not* Send API
|
43
|
+
default_headers = { accept: :json, accept_encoding: :deflate, content_type: :json } #use JSON if *not* Send API
|
44
44
|
end
|
45
|
+
return default_headers.merge(user_agent: "mailjet-api-v3-ruby/#{Gem.loaded_specs["mailjet"].version}")
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
@@ -62,9 +63,9 @@ module Mailjet
|
|
62
63
|
response_hash['Total']
|
63
64
|
end
|
64
65
|
|
65
|
-
def find(id)
|
66
|
+
def find(id, job_id = nil)
|
66
67
|
# if action method, ammend url to appropriate id
|
67
|
-
self.resource_path = create_action_resource_path(id) if self.action
|
68
|
+
self.resource_path = create_action_resource_path(id, job_id) if self.action
|
68
69
|
#
|
69
70
|
attributes = parse_api_json(connection[id].get(default_headers)).first
|
70
71
|
instanciate_from_api(attributes)
|
@@ -108,10 +109,15 @@ module Mailjet
|
|
108
109
|
response_data_array.map{ |response_data| underscore_keys(response_data) }
|
109
110
|
end
|
110
111
|
|
111
|
-
def create_action_resource_path(id)
|
112
|
+
def create_action_resource_path(id, job_id = nil)
|
112
113
|
url_elements = self.resource_path.split("/")
|
113
|
-
url_elements
|
114
|
-
|
114
|
+
url_elements.delete_at(url_elements.length-1) if url_elements.last.to_i > 0 #if there is a trailing number for the job id from last call, delete it
|
115
|
+
if self.action != "managemanycontacts" || (self.action == "managemanycontacts" && url_elements[2] == "contactslist")
|
116
|
+
url_elements[3] = id.to_s
|
117
|
+
end
|
118
|
+
url_elements << job_id.to_s if job_id #if job_id exists, ammend it to end of the URI
|
119
|
+
url = url_elements.join("/")
|
120
|
+
return url
|
115
121
|
end
|
116
122
|
|
117
123
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'mailjet/resource'
|
2
|
+
|
3
|
+
module Mailjet
|
4
|
+
class Contact_getcontactslists
|
5
|
+
include Mailjet::Resource
|
6
|
+
self.action = "getcontactslists"
|
7
|
+
self.resource_path = "v3/REST/contact/id/#{self.action}"
|
8
|
+
self.public_operations = [:get]
|
9
|
+
self.filters = []
|
10
|
+
self.properties = []
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'mailjet/resource'
|
2
|
+
|
3
|
+
module Mailjet
|
4
|
+
class Contact_managecontactslists
|
5
|
+
include Mailjet::Resource
|
6
|
+
self.action = "managecontactslists"
|
7
|
+
self.resource_path = "v3/REST/contact/id/#{self.action}"
|
8
|
+
self.public_operations = [:post]
|
9
|
+
self.filters = []
|
10
|
+
self.properties = [:contacts_lists, 'ListID', :list_id, :action] #need 'ListID' and :action in a subpacket
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'mailjet/resource'
|
2
|
+
|
3
|
+
module Mailjet
|
4
|
+
class Contact_managemanycontacts
|
5
|
+
include Mailjet::Resource
|
6
|
+
self.action = "managemanycontacts"
|
7
|
+
#might be different
|
8
|
+
self.resource_path = "v3/REST/contact/#{self.action}"
|
9
|
+
self.public_operations = [:post, :get] #GET is for job_id ammended at the end
|
10
|
+
self.filters = []
|
11
|
+
self.properties = [:contacts_lists, :contacts, :list_id, 'ListID', :action, :email, :name, :properties] #need 'ListID' and :action in a subpacket
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'mailjet/resource'
|
2
|
+
|
3
|
+
module Mailjet
|
4
|
+
class Contactslist_managecontact
|
5
|
+
include Mailjet::Resource
|
6
|
+
self.action = "managecontact"
|
7
|
+
self.resource_path = "v3/REST/contactslist/id/#{self.action}"
|
8
|
+
self.public_operations = [:post]
|
9
|
+
self.filters = []
|
10
|
+
self.properties = [:email, :name, :action, :properties]
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'mailjet/resource'
|
2
|
+
|
3
|
+
module Mailjet
|
4
|
+
class Contactslist_managemanycontacts
|
5
|
+
include Mailjet::Resource
|
6
|
+
self.action = "managemanycontacts"
|
7
|
+
self.resource_path = "v3/REST/contactslist/id/#{self.action}"
|
8
|
+
self.public_operations = [:post, :get] #GET is for when job_id is there
|
9
|
+
self.filters = []
|
10
|
+
self.properties = [:action, :contacts, :email, :name, :properties]
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'mailjet/resource'
|
2
|
+
|
3
|
+
module Mailjet
|
4
|
+
class DNS
|
5
|
+
include Mailjet::Resource
|
6
|
+
self.resource_path = 'v3/REST/dns'
|
7
|
+
self.public_operations = [:get]
|
8
|
+
self.filters = []
|
9
|
+
self.properties = [:id, :isCheckInProgress, :DKIMStatus, :DKIMValue, :DKIMName, :format, :lastCheckedAt, :SPFStatus, :SPFValue, :ownershipToken]
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'mailjet/resource'
|
2
|
+
|
3
|
+
module Mailjet
|
4
|
+
class DNS_check
|
5
|
+
include Mailjet::Resource
|
6
|
+
self.action = "check"
|
7
|
+
self.resource_path = "v3/REST/dns/id/#{self.action}"
|
8
|
+
self.public_operations = [:post]
|
9
|
+
self.filters = []
|
10
|
+
self.properties = []
|
11
|
+
|
12
|
+
end
|
13
|
+
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.1.0
|
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-08-20 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -300,14 +300,21 @@ files:
|
|
300
300
|
- lib/mailjet/resources/campaignstatistics.rb
|
301
301
|
- lib/mailjet/resources/clickstatistics.rb
|
302
302
|
- lib/mailjet/resources/contact.rb
|
303
|
+
- lib/mailjet/resources/contact_getcontactslists.rb
|
304
|
+
- lib/mailjet/resources/contact_managecontactslists.rb
|
305
|
+
- lib/mailjet/resources/contact_managemanycontacts.rb
|
303
306
|
- lib/mailjet/resources/contactdata.rb
|
304
307
|
- lib/mailjet/resources/contactfilter.rb
|
305
308
|
- lib/mailjet/resources/contacthistorydata.rb
|
306
309
|
- lib/mailjet/resources/contactmetadata.rb
|
307
310
|
- lib/mailjet/resources/contactslist.rb
|
311
|
+
- lib/mailjet/resources/contactslist_managecontact.rb
|
312
|
+
- lib/mailjet/resources/contactslist_managemanycontacts.rb
|
308
313
|
- lib/mailjet/resources/contactslistsignup.rb
|
309
314
|
- lib/mailjet/resources/contactstatistics.rb
|
310
315
|
- lib/mailjet/resources/csvimport.rb
|
316
|
+
- lib/mailjet/resources/dns.rb
|
317
|
+
- lib/mailjet/resources/dns_check.rb
|
311
318
|
- lib/mailjet/resources/domainstatistics.rb
|
312
319
|
- lib/mailjet/resources/eventcallbackurl.rb
|
313
320
|
- lib/mailjet/resources/geostatistics.rb
|