mailjet 1.7.3 → 1.7.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -7
- data/lib/mailjet/connection.rb +23 -8
- data/lib/mailjet/exception/errors.rb +91 -0
- data/lib/mailjet/mailer.rb +5 -8
- data/lib/mailjet/rack/endpoint.rb +2 -2
- data/lib/mailjet/resource.rb +43 -19
- data/lib/mailjet/resources/campaigndraft_detailcontent.rb +1 -1
- data/lib/mailjet/resources/contact_getcontactslists.rb +1 -1
- data/lib/mailjet/resources/contact_pii.rb +8 -0
- data/lib/mailjet/resources/contactslist_csv.rb +8 -0
- data/lib/mailjet/resources/csvimport.rb +0 -1
- data/lib/mailjet/resources/messagehistory.rb +1 -1
- data/lib/mailjet/resources/messageinformation.rb +1 -1
- data/lib/mailjet/resources/openinformation.rb +1 -1
- data/lib/mailjet/resources/retrieve_errors_csv.rb +8 -0
- data/lib/mailjet/resources/template_detailcontent.rb +1 -1
- data/lib/mailjet/version.rb +1 -1
- data/lib/mailjet.rb +2 -4
- metadata +22 -20
- data/lib/mailjet/api_error.rb +0 -28
- data/lib/mailjet/core_extensions/ostruct.rb +0 -9
- data/lib/mailjet/gem_extensions/rest_client.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79ac7a46c18530042c2b6c32c04f7fcb7ef0fac062e13e24a7bc4cf79ee3e9a8
|
4
|
+
data.tar.gz: 6f6c290689c437ab0db53504c759d79595555659c5501a57682d290bd71b62f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a19b7e5d407cf862b3bda199b3fbc5ad34c7f12313efb514be5d5534c319d395ea347983e3103f3dadb012a700bda741f8a11d7265fb63fdd072ab3e5c278a6b
|
7
|
+
data.tar.gz: 1404c4d766bc4b9690508daa052713bc55e0494ebd3e512ebefe4d2e8b18a453cc17edefc5a7c38e24be58430ea4f3a3f27a42c6ea07a893269f50f0c6b4fe06
|
data/README.md
CHANGED
@@ -76,7 +76,7 @@ Check out all the resources and Ruby code examples in the [Offical Documentation
|
|
76
76
|
|
77
77
|
This library requires **Ruby v2.2.X**.
|
78
78
|
|
79
|
-
The Rails ActionMailer integration is designed for Rails
|
79
|
+
The Rails ActionMailer integration is designed for Rails >= 5.
|
80
80
|
|
81
81
|
## Installation
|
82
82
|
|
@@ -139,7 +139,7 @@ Here's an example on how to send an email:
|
|
139
139
|
require 'mailjet'
|
140
140
|
Mailjet.configure do |config|
|
141
141
|
config.api_key = ENV['MJ_APIKEY_PUBLIC']
|
142
|
-
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
142
|
+
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
143
143
|
config.api_version = "v3.1"
|
144
144
|
end
|
145
145
|
variable = Mailjet::Send.create(messages: [{
|
@@ -177,7 +177,7 @@ Since most Email API endpoints are located under `v3`, it is set as the default
|
|
177
177
|
require 'mailjet'
|
178
178
|
Mailjet.configure do |config|
|
179
179
|
config.api_key = ENV['MJ_APIKEY_PUBLIC']
|
180
|
-
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
180
|
+
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
181
181
|
config.api_version = "v3.1"
|
182
182
|
end
|
183
183
|
```
|
@@ -189,7 +189,7 @@ The default base domain name for the Mailjet API is `https://api.mailjet.com`. Y
|
|
189
189
|
```ruby
|
190
190
|
Mailjet.configure do |config|
|
191
191
|
config.api_key = ENV['MJ_APIKEY_PUBLIC']
|
192
|
-
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
192
|
+
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
193
193
|
config.api_version = "v3.1"
|
194
194
|
config.end_point = "https://api.us.mailjet.com"
|
195
195
|
end
|
@@ -221,7 +221,7 @@ Use the `create` method of the Mailjet CLient (i.e. `variable = Mailjet::$resour
|
|
221
221
|
require 'mailjet'
|
222
222
|
Mailjet.configure do |config|
|
223
223
|
config.api_key = ENV['MJ_APIKEY_PUBLIC']
|
224
|
-
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
224
|
+
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
225
225
|
end
|
226
226
|
variable = Mailjet::Contact.create(email: "Mister@mailjet.com"
|
227
227
|
)
|
@@ -239,7 +239,7 @@ Use `id` to specify the ID you want to apply a POST request to (used in case of
|
|
239
239
|
require 'mailjet'
|
240
240
|
Mailjet.configure do |config|
|
241
241
|
config.api_key = ENV['MJ_APIKEY_PUBLIC']
|
242
|
-
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
242
|
+
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
243
243
|
end
|
244
244
|
variable = Mailjet::Contact_managecontactslists.create(id: $ID, contacts_lists: [{
|
245
245
|
'ListID'=> '$ListID_1',
|
@@ -285,7 +285,7 @@ Use the `.find` method to retrieve a specific object. Specify the ID of the obje
|
|
285
285
|
require 'mailjet'
|
286
286
|
Mailjet.configure do |config|
|
287
287
|
config.api_key = ENV['MJ_APIKEY_PUBLIC']
|
288
|
-
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
288
|
+
config.secret_key = ENV['MJ_APIKEY_PRIVATE']
|
289
289
|
end
|
290
290
|
variable = Mailjet::Contact.find($CONTACT_EMAIL)
|
291
291
|
p variable.attributes['Data']
|
@@ -483,6 +483,17 @@ UserMailer.welcome_email.deliver_now!
|
|
483
483
|
|
484
484
|
For more information on `ActionMailer::MessageDelivery`, see the documentation [HERE](http://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html)
|
485
485
|
|
486
|
+
#### Manage contacts via CSV Upload
|
487
|
+
Create the CSV content in a format compatible with the Mailjet API, see the documentation [HERE](https://dev.mailjet.com/email/guides/contact-management/#manage-contacts-via-csv-upload)
|
488
|
+
```ruby
|
489
|
+
Mailjet::ContactslistCsv.send_data(ID_CONTACTLIST, File.open('some_csvdata.csv', 'r'))
|
490
|
+
```
|
491
|
+
|
492
|
+
#### [Delete the Contact](https://dev.mailjet.com/email/guides/contact-management/#gdpr-delete-contacts)
|
493
|
+
```ruby
|
494
|
+
Mailjet::ContactPii.delete(contact_ID)
|
495
|
+
```
|
496
|
+
|
486
497
|
## Track email delivery
|
487
498
|
|
488
499
|
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,5 @@
|
|
1
1
|
require 'rest_client'
|
2
|
-
require '
|
3
|
-
require 'json'
|
2
|
+
require 'yajl'
|
4
3
|
|
5
4
|
module Mailjet
|
6
5
|
class Connection
|
@@ -70,7 +69,7 @@ module Mailjet
|
|
70
69
|
private
|
71
70
|
|
72
71
|
def handle_api_call(method, additional_headers = {}, payload = {}, &block)
|
73
|
-
formatted_payload = (additional_headers[:content_type] == :json) ? payload
|
72
|
+
formatted_payload = (additional_headers[:content_type] == :json) ? Yajl::Encoder.encode(payload) : payload
|
74
73
|
raise Mailjet::MethodNotAllowed unless method_allowed(method)
|
75
74
|
|
76
75
|
if self.perform_api_call
|
@@ -80,7 +79,7 @@ module Mailjet
|
|
80
79
|
@adapter.send(method, formatted_payload, additional_headers, &block)
|
81
80
|
end
|
82
81
|
else
|
83
|
-
return {'Count' => 0, 'Data' => [mock_api_call: true], 'Total' => 0}
|
82
|
+
return Yajl::Encoder.encode({'Count' => 0, 'Data' => [mock_api_call: true], 'Total' => 0})
|
84
83
|
end
|
85
84
|
rescue RestClient::Exception => e
|
86
85
|
handle_exception(e, additional_headers, formatted_payload)
|
@@ -92,9 +91,11 @@ module Mailjet
|
|
92
91
|
end
|
93
92
|
|
94
93
|
def handle_exception(e, additional_headers, payload = {})
|
94
|
+
return e.http_body if e.http_headers[:content_type].include?("text/plain")
|
95
|
+
|
95
96
|
params = additional_headers[:params] || {}
|
96
|
-
formatted_payload = (additional_headers[:content_type] == :json) ?
|
97
|
-
params = params.merge(formatted_payload)
|
97
|
+
formatted_payload = (additional_headers[:content_type] == :json) ? Yajl::Parser.parse(payload) : payload
|
98
|
+
params = params.merge!(formatted_payload) if formatted_payload.is_a?(Hash)
|
98
99
|
|
99
100
|
http_body = if e.http_headers[:content_type].include?("application/json")
|
100
101
|
e.http_body
|
@@ -105,15 +106,29 @@ module Mailjet
|
|
105
106
|
if sent_invalid_email?(e.http_body, @adapter.url)
|
106
107
|
return e.http_body
|
107
108
|
else
|
108
|
-
raise
|
109
|
+
raise communication_error(e)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def communication_error(e)
|
114
|
+
if e.respond_to?(:response) && e.response
|
115
|
+
return case e.response.code
|
116
|
+
when Unauthorized::CODE
|
117
|
+
Unauthorized.new(e.message, e.response)
|
118
|
+
when BadRequest::CODE
|
119
|
+
BadRequest.new(e.message, e.response)
|
120
|
+
else
|
121
|
+
CommunicationError.new(e.message, e.response)
|
122
|
+
end
|
109
123
|
end
|
124
|
+
CommunicationError.new(e.message)
|
110
125
|
end
|
111
126
|
|
112
127
|
def sent_invalid_email?(error_http_body, url)
|
113
128
|
return false unless url.include?('v3.1/send')
|
114
129
|
return unless error_http_body
|
115
130
|
|
116
|
-
parsed_body =
|
131
|
+
parsed_body = Yajl::Parser.parse(error_http_body)
|
117
132
|
error_message = parsed_body.dig('Messages')&.first&.dig('Errors')&.first&.dig('ErrorMessage') || []
|
118
133
|
error_message.include?('is an invalid email address.')
|
119
134
|
rescue
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Mailjet
|
2
|
+
class Error < StandardError
|
3
|
+
attr_reader :object
|
4
|
+
|
5
|
+
def initialize(message = nil, object = nil)
|
6
|
+
super(message)
|
7
|
+
@object = object
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class ApiError < StandardError
|
12
|
+
attr_reader :code, :reason
|
13
|
+
|
14
|
+
# @param code [Integer] HTTP response status code
|
15
|
+
# @param body [String] JSON response body
|
16
|
+
# @param request [Object] any request object
|
17
|
+
# @param url [String] request URL
|
18
|
+
# @param params [Hash] request headers and parameters
|
19
|
+
def initialize(code, body, request, url, params)
|
20
|
+
@code = code
|
21
|
+
@reason = begin
|
22
|
+
resdec = JSON.parse(body)
|
23
|
+
resdec['ErrorMessage']
|
24
|
+
rescue JSON::ParserError
|
25
|
+
body
|
26
|
+
end
|
27
|
+
|
28
|
+
if request.respond_to?(:options)
|
29
|
+
request.options[:user] = '***'
|
30
|
+
request.options[:password] = '***'
|
31
|
+
end
|
32
|
+
|
33
|
+
message = "error #{code} while sending #{request.inspect} to #{url} with #{params.inspect}"
|
34
|
+
error_details = body.inspect
|
35
|
+
hint = "Please see https://dev.mailjet.com/email/reference/overview/errors/ for more informations on error numbers."
|
36
|
+
|
37
|
+
super("#{message}\n\n#{error_details}\n\n#{hint}\n\n")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class CommunicationError < Error
|
42
|
+
attr_reader :code
|
43
|
+
|
44
|
+
NOCODE = 000
|
45
|
+
|
46
|
+
def initialize(message = nil, response = nil)
|
47
|
+
@response = response
|
48
|
+
@code = if response.nil?
|
49
|
+
NOCODE
|
50
|
+
else
|
51
|
+
response.code
|
52
|
+
end
|
53
|
+
|
54
|
+
api_message = begin
|
55
|
+
Yajl::Parser.parse(response.body)['ErrorMessage']
|
56
|
+
rescue Yajl::ParseError
|
57
|
+
response.body
|
58
|
+
rescue NoMethodError
|
59
|
+
"Unknown API error"
|
60
|
+
rescue
|
61
|
+
'Unknown API error'
|
62
|
+
end
|
63
|
+
|
64
|
+
message ||= ''
|
65
|
+
api_message ||= ''
|
66
|
+
message = message + ': ' + api_message
|
67
|
+
|
68
|
+
super(message, response)
|
69
|
+
rescue NoMethodError, JSON::ParserError
|
70
|
+
@code = NOCODE
|
71
|
+
super(message, response)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class Unauthorized < CommunicationError
|
76
|
+
CODE = 401
|
77
|
+
|
78
|
+
def initialize(error_message, response)
|
79
|
+
error_message = error_message + ' - Invalid Domain or API key'
|
80
|
+
super(error_message, response)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class BadRequest < CommunicationError
|
85
|
+
CODE = 400
|
86
|
+
|
87
|
+
def initialize(error_message, response)
|
88
|
+
super(error_message, response)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/mailjet/mailer.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'action_mailer'
|
2
2
|
require 'mail'
|
3
3
|
require 'base64'
|
4
|
-
require '
|
4
|
+
require 'yajl/json_gem'
|
5
|
+
|
5
6
|
|
6
7
|
# Mailjet::Mailer enables to send a Mail::Message via Mailjet SMTP relay servers
|
7
8
|
# User is the API key, and password the API secret
|
@@ -15,7 +16,7 @@ class Mailjet::Mailer < ::Mail::SMTP
|
|
15
16
|
user_name: options.delete(:api_key) || Mailjet.config.api_key,
|
16
17
|
password: options.delete(:secret_key) || Mailjet.config.secret_key,
|
17
18
|
enable_starttls_auto: true
|
18
|
-
}.merge(options))
|
19
|
+
}.merge!(options))
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -202,9 +203,7 @@ class Mailjet::APIMailer
|
|
202
203
|
|
203
204
|
payload = {
|
204
205
|
:To=> to,
|
205
|
-
}.merge(content)
|
206
|
-
.merge(base_from)
|
207
|
-
.merge(@delivery_method_options_v3_1)
|
206
|
+
}.merge!(content, base_from, @delivery_method_options_v3_1)
|
208
207
|
|
209
208
|
payload[:Subject] = mail.subject if !mail.subject.blank?
|
210
209
|
payload[:Sender] = mail[:sender] if !mail[:sender].blank?
|
@@ -294,9 +293,7 @@ class Mailjet::APIMailer
|
|
294
293
|
payload[:bcc] = mail[:bcc].formatted.join(', ') if mail[:bcc]
|
295
294
|
|
296
295
|
# Send the final payload to Mailjet Send API
|
297
|
-
payload.merge(content)
|
298
|
-
.merge(base_from)
|
299
|
-
.merge(@delivery_method_options_v3_0)
|
296
|
+
payload.merge!(content, base_from, @delivery_method_options_v3_0)
|
300
297
|
end
|
301
298
|
end
|
302
299
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rack/request'
|
2
|
-
require '
|
2
|
+
require 'yajl'
|
3
3
|
|
4
4
|
module Mailjet
|
5
5
|
module Rack
|
@@ -12,7 +12,7 @@ module Mailjet
|
|
12
12
|
|
13
13
|
def call(env)
|
14
14
|
if env['PATH_INFO'] == @path && (content = env['rack.input'].read)
|
15
|
-
@block.call(
|
15
|
+
@block.call(Yajl::Parser.parse(content))
|
16
16
|
[200, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
|
17
17
|
else
|
18
18
|
@app.call(env)
|
data/lib/mailjet/resource.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
require 'mailjet/connection'
|
2
|
+
require 'yajl'
|
3
|
+
require 'active_support'
|
2
4
|
require 'active_support/core_ext/string'
|
3
|
-
require 'active_support/core_ext/
|
4
|
-
|
5
|
-
require 'active_support/hash_with_indifferent_access'
|
6
|
-
require 'active_support/core_ext/hash'
|
7
|
-
require 'active_support/json/decoding'
|
8
|
-
require 'json'
|
5
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
6
|
+
|
9
7
|
|
10
8
|
|
11
9
|
# This option automatically transforms the date output by the API into something a bit more readable.
|
@@ -16,11 +14,11 @@ require 'json'
|
|
16
14
|
|
17
15
|
module Mailjet
|
18
16
|
module Resource
|
19
|
-
|
20
17
|
# define here available options for filtering
|
21
18
|
OPTIONS = [:version, :url, :perform_api_call, :api_key, :secret_key, :read_timeout, :open_timeout]
|
22
19
|
|
23
20
|
NON_JSON_URLS = ['v3/send/message'] # urls that don't accept JSON input
|
21
|
+
DATA_URLS = ['plain', 'csv'] # url for send binary data , 'CSVError/text:csv'
|
24
22
|
|
25
23
|
def self.included(base)
|
26
24
|
base.extend ClassMethods
|
@@ -49,10 +47,13 @@ module Mailjet
|
|
49
47
|
def self.default_headers
|
50
48
|
if NON_JSON_URLS.include?(self.resource_path) # don't use JSON if Send API
|
51
49
|
default_headers = { accept: :json, accept_encoding: :deflate }
|
50
|
+
elsif DATA_URLS.any? { |data_type| default_headers = { content_type: "text/#{data_type}" } if
|
51
|
+
self.resource_path.include?(data_type)
|
52
|
+
}
|
52
53
|
else
|
53
54
|
default_headers = { accept: :json, accept_encoding: :deflate, content_type: :json } #use JSON if *not* Send API
|
54
55
|
end
|
55
|
-
return default_headers.merge(user_agent: "mailjet-api-v3-ruby/#{Gem.loaded_specs["mailjet"].version}")
|
56
|
+
return default_headers.merge!(user_agent: "mailjet-api-v3-ruby/#{Gem.loaded_specs["mailjet"].version}")
|
56
57
|
end
|
57
58
|
end
|
58
59
|
end
|
@@ -60,21 +61,27 @@ module Mailjet
|
|
60
61
|
module ClassMethods
|
61
62
|
def first(params = {}, options = {})
|
62
63
|
all(params.merge!(limit: 1), options).first
|
64
|
+
rescue Mailjet::ApiError => error
|
65
|
+
raise error
|
63
66
|
end
|
64
67
|
|
65
68
|
def all(params = {}, options = {})
|
66
69
|
opts = define_options(options)
|
67
70
|
params = format_params(params)
|
68
|
-
response = connection(opts).get(default_headers.merge(params: params))
|
71
|
+
response = connection(opts).get(default_headers.merge!(params: params))
|
69
72
|
attribute_array = parse_api_json(response)
|
70
73
|
attribute_array.map{ |attributes| instanciate_from_api(attributes) }
|
74
|
+
rescue Mailjet::ApiError => error
|
75
|
+
raise error
|
71
76
|
end
|
72
77
|
|
73
78
|
def count(options = {})
|
74
79
|
opts = define_options(options)
|
75
|
-
response_json = connection(opts).get(default_headers.merge(params: {limit: 1, countrecords: 1}))
|
76
|
-
response_hash =
|
80
|
+
response_json = connection(opts).get(default_headers.merge!(params: {limit: 1, countrecords: 1}))
|
81
|
+
response_hash = Yajl::Parser.parse(response_json)
|
77
82
|
response_hash['Total']
|
83
|
+
rescue Mailjet::ApiError => error
|
84
|
+
raise error
|
78
85
|
end
|
79
86
|
|
80
87
|
def find(id, job_id = nil, options = {})
|
@@ -87,11 +94,11 @@ module Mailjet
|
|
87
94
|
# if action method, ammend url to appropriate id
|
88
95
|
opts = define_options(options)
|
89
96
|
self.resource_path = create_action_resource_path(normalized_id, job_id) if self.action
|
90
|
-
|
97
|
+
|
91
98
|
attributes = parse_api_json(connection(opts)[normalized_id].get(default_headers)).first
|
92
99
|
instanciate_from_api(attributes)
|
93
100
|
|
94
|
-
rescue Mailjet::
|
101
|
+
rescue Mailjet::CommunicationError => e
|
95
102
|
if e.code == 404
|
96
103
|
nil
|
97
104
|
else
|
@@ -118,7 +125,6 @@ module Mailjet
|
|
118
125
|
resource.save!(opts)
|
119
126
|
resource.attributes[:persisted] = true
|
120
127
|
end
|
121
|
-
|
122
128
|
end
|
123
129
|
|
124
130
|
def delete(id, options = {})
|
@@ -126,14 +132,32 @@ module Mailjet
|
|
126
132
|
opts = define_options(options)
|
127
133
|
self.resource_path = create_action_resource_path(id) if self.action
|
128
134
|
connection(opts)[id].delete(default_headers)
|
135
|
+
rescue Mailjet::ApiError => error
|
136
|
+
raise error
|
137
|
+
end
|
138
|
+
|
139
|
+
def send_data(id, binary_data = nil, options = {})
|
140
|
+
opts = define_options(options)
|
141
|
+
self.resource_path = create_action_resource_path(id) if self.action
|
142
|
+
|
143
|
+
response_hash = Yajl::Parser.parse(connection(opts).post(binary_data, default_headers))
|
144
|
+
response_hash['ID'] ? response_hash['ID'] : response_hash
|
145
|
+
end
|
146
|
+
|
147
|
+
def find_by_id(id, options = {})
|
148
|
+
# if action method, ammend url to appropriate id
|
149
|
+
opts = define_options(options)
|
150
|
+
self.resource_path = create_action_resource_path(id) if self.action
|
151
|
+
|
152
|
+
connection(opts).get(default_headers)
|
129
153
|
end
|
130
154
|
|
131
155
|
def instanciate_from_api(attributes = {})
|
132
|
-
self.new(attributes.merge(persisted: true))
|
156
|
+
self.new(attributes.merge!(persisted: true))
|
133
157
|
end
|
134
158
|
|
135
159
|
def parse_api_json(response_json)
|
136
|
-
response_hash =
|
160
|
+
response_hash = Yajl::Parser.parse(response_json)
|
137
161
|
|
138
162
|
#Take the response from the API and put it through a method -- taken from the ActiveSupport library -- which converts
|
139
163
|
#the date-time from "2014-05-19T15:31:09Z" to "Mon, 19 May 2014 15:31:09 +0000" format.
|
@@ -169,9 +193,9 @@ module Mailjet
|
|
169
193
|
case data
|
170
194
|
when nil
|
171
195
|
nil
|
172
|
-
|
196
|
+
when /^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?))$/
|
173
197
|
begin
|
174
|
-
DateTime.
|
198
|
+
DateTime.iso8601(data)
|
175
199
|
rescue ArgumentError
|
176
200
|
data
|
177
201
|
end
|
@@ -260,7 +284,7 @@ module Mailjet
|
|
260
284
|
if opts[:perform_api_call] && !persisted?
|
261
285
|
# get attributes only for entity creation
|
262
286
|
self.attributes = if self.resource_path == 'send'
|
263
|
-
|
287
|
+
Yajl::Parser.parse(response)
|
264
288
|
else
|
265
289
|
parse_api_json(response).first
|
266
290
|
end
|
@@ -5,6 +5,5 @@ module Mailjet
|
|
5
5
|
self.public_operations = [:get, :put, :post]
|
6
6
|
self.filters = []
|
7
7
|
self.resourceprop = [:alive_at, :contacts_list, :count, :current, :data_id, :errcount, :err_treshold, :id, :import_options, :job_end, :job_start, :method, :request_at, :status]
|
8
|
-
|
9
8
|
end
|
10
9
|
end
|
data/lib/mailjet/version.rb
CHANGED
data/lib/mailjet.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'json/ext'
|
2
|
-
require '
|
3
|
-
require 'mailjet/core_extensions/ostruct'
|
2
|
+
require 'yajl'
|
4
3
|
require 'mailjet/configuration'
|
5
|
-
require 'mailjet/api_error'
|
6
4
|
|
7
5
|
require 'mailjet/resource'
|
8
6
|
require 'mailjet/message_delivery'
|
9
7
|
|
10
|
-
Dir[File.expand_path("../mailjet/resources/*.rb", __FILE__)].each do |file|
|
8
|
+
Dir[File.expand_path("../mailjet/{resources,exception}/*.rb", __FILE__)].each do |file|
|
11
9
|
require file
|
12
10
|
end
|
13
11
|
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mailjet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Nappy
|
8
8
|
- Jean-Baptiste Escoyez
|
9
9
|
- Aurélien AMILIN
|
10
10
|
- Benoit Bénézech
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2024-04-16 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -19,14 +19,14 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 5.0.0
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 5.0.0
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: rack
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -47,44 +47,44 @@ dependencies:
|
|
47
47
|
requirements:
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 2.
|
50
|
+
version: 2.1.0
|
51
51
|
type: :runtime
|
52
52
|
prerelease: false
|
53
53
|
version_requirements: !ruby/object:Gem::Requirement
|
54
54
|
requirements:
|
55
55
|
- - ">="
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 2.
|
57
|
+
version: 2.1.0
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
59
|
+
name: yajl-ruby
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
62
|
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version:
|
65
|
-
type: :
|
64
|
+
version: '0'
|
65
|
+
type: :runtime
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
71
|
+
version: '0'
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
|
-
name:
|
73
|
+
name: actionmailer
|
74
74
|
requirement: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
78
|
+
version: 5.0.0
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
83
|
- - ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
85
|
+
version: 5.0.0
|
86
86
|
- !ruby/object:Gem::Dependency
|
87
|
-
name:
|
87
|
+
name: rake
|
88
88
|
requirement: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
90
|
- - ">="
|
@@ -168,12 +168,10 @@ files:
|
|
168
168
|
- lib/generators/mailjet/initializer_generator.rb
|
169
169
|
- lib/generators/mailjet/templates/mailjet.rb.erb
|
170
170
|
- lib/mailjet.rb
|
171
|
-
- lib/mailjet/api_error.rb
|
172
171
|
- lib/mailjet/collection_proxy.rb
|
173
172
|
- lib/mailjet/configuration.rb
|
174
173
|
- lib/mailjet/connection.rb
|
175
|
-
- lib/mailjet/
|
176
|
-
- lib/mailjet/gem_extensions/rest_client.rb
|
174
|
+
- lib/mailjet/exception/errors.rb
|
177
175
|
- lib/mailjet/mailer.rb
|
178
176
|
- lib/mailjet/message_delivery.rb
|
179
177
|
- lib/mailjet/rack/endpoint.rb
|
@@ -203,11 +201,13 @@ files:
|
|
203
201
|
- lib/mailjet/resources/contact_getcontactslists.rb
|
204
202
|
- lib/mailjet/resources/contact_managecontactslists.rb
|
205
203
|
- lib/mailjet/resources/contact_managemanycontacts.rb
|
204
|
+
- lib/mailjet/resources/contact_pii.rb
|
206
205
|
- lib/mailjet/resources/contactdata.rb
|
207
206
|
- lib/mailjet/resources/contactfilter.rb
|
208
207
|
- lib/mailjet/resources/contacthistorydata.rb
|
209
208
|
- lib/mailjet/resources/contactmetadata.rb
|
210
209
|
- lib/mailjet/resources/contactslist.rb
|
210
|
+
- lib/mailjet/resources/contactslist_csv.rb
|
211
211
|
- lib/mailjet/resources/contactslist_managecontact.rb
|
212
212
|
- lib/mailjet/resources/contactslist_managemanycontacts.rb
|
213
213
|
- lib/mailjet/resources/contactslistsignup.rb
|
@@ -248,6 +248,7 @@ files:
|
|
248
248
|
- lib/mailjet/resources/openstatistics.rb
|
249
249
|
- lib/mailjet/resources/parseroute.rb
|
250
250
|
- lib/mailjet/resources/preferences.rb
|
251
|
+
- lib/mailjet/resources/retrieve_errors_csv.rb
|
251
252
|
- lib/mailjet/resources/send.rb
|
252
253
|
- lib/mailjet/resources/sender.rb
|
253
254
|
- lib/mailjet/resources/sender_validate.rb
|
@@ -291,11 +292,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
291
292
|
- !ruby/object:Gem::Version
|
292
293
|
version: '0'
|
293
294
|
requirements: []
|
294
|
-
rubygems_version: 3.
|
295
|
-
signing_key:
|
295
|
+
rubygems_version: 3.4.21
|
296
|
+
signing_key:
|
296
297
|
specification_version: 4
|
297
298
|
summary: Mailjet a powerful all-in-one email service provider clients can use to get
|
298
299
|
maximum insight and deliverability results from both their marketing and transactional
|
299
300
|
emails. Our analytics tools and intelligent APIs give senders the best understanding
|
300
301
|
of how to maximize benefits for each individual contact, with each email sent.
|
301
302
|
test_files: []
|
303
|
+
...
|
data/lib/mailjet/api_error.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require "json"
|
2
|
-
|
3
|
-
module Mailjet
|
4
|
-
class ApiError < StandardError
|
5
|
-
attr_reader :code, :reason
|
6
|
-
|
7
|
-
# @param code [Integer] HTTP response status code
|
8
|
-
# @param body [String] JSON response body
|
9
|
-
# @param request [Object] any request object
|
10
|
-
# @param url [String] request URL
|
11
|
-
# @param params [Hash] request headers and parameters
|
12
|
-
def initialize(code, body, request, url, params)
|
13
|
-
@code = code
|
14
|
-
@reason = begin
|
15
|
-
resdec = JSON.parse(body)
|
16
|
-
resdec['ErrorMessage']
|
17
|
-
rescue JSON::ParserError
|
18
|
-
body
|
19
|
-
end
|
20
|
-
|
21
|
-
message = "error #{code} while sending #{request.inspect} to #{url} with #{params.inspect}"
|
22
|
-
error_details = body.inspect
|
23
|
-
hint = "Please see https://dev.mailjet.com/guides/#status-codes for more informations on error numbers."
|
24
|
-
|
25
|
-
super("#{message}\n\n#{error_details}\n\n#{hint}\n\n")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,9 +0,0 @@
|
|
1
|
-
class OpenStruct
|
2
|
-
|
3
|
-
# when asked for id, ruby 1.8.7's implementation of OpenStruct returns object's inner id instead of table's value if present. Evilishish infamous Monkey-Patch.
|
4
|
-
if RUBY_VERSION =~ /1\.8\./
|
5
|
-
def id
|
6
|
-
send(:eval, "@table[:id]")
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module RestClient
|
2
|
-
module Payload
|
3
|
-
class Base
|
4
|
-
def flatten_params_array value, calculated_key
|
5
|
-
result = []
|
6
|
-
value.each do |elem|
|
7
|
-
if elem.is_a? Hash
|
8
|
-
result += flatten_params(elem, calculated_key)
|
9
|
-
elsif elem.is_a? Array
|
10
|
-
result += flatten_params_array(elem, calculated_key)
|
11
|
-
else
|
12
|
-
result << ["#{calculated_key}", elem]
|
13
|
-
end
|
14
|
-
end
|
15
|
-
result
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|