mailjet 1.7.10 → 1.8.0
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/lib/mailjet/connection.rb +33 -45
- data/lib/mailjet/exception/errors.rb +3 -3
- data/lib/mailjet/resource.rb +24 -24
- data/lib/mailjet/resources/campaigndraft_detailcontent.rb +1 -1
- data/lib/mailjet/resources/contact.rb +0 -5
- data/lib/mailjet/resources/contact_getcontactslists.rb +1 -1
- data/lib/mailjet/resources/listrecipient.rb +2 -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/template_detailcontent.rb +1 -1
- data/lib/mailjet/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9c74309f3d5e557d27fe01548e0998a987c90a9bd1e5e52c187c23d33fb5475
|
4
|
+
data.tar.gz: 3c44b00a89c535c6143d0011fa6e11ca1d6bcdbc82ed984eea4b5f23b0483b89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a35a75e7a661f72c28fda90a8403f363252f36cf9573786e512f1721b807b6f450d51dafdc6d8ae8c816b4bd0f32b4abe008f67b6189647a0caa70f0ebbc929d
|
7
|
+
data.tar.gz: 513f1178e1f7e625b177faa7220d60fbb4208a5d38f91642d173ee7a63d39fa3758d189f04e9a4a3e928d84e8d4921a17c22d281bb9fca2b8cf47c7f9f7348ca
|
data/lib/mailjet/connection.rb
CHANGED
@@ -1,40 +1,32 @@
|
|
1
|
-
require '
|
1
|
+
require 'faraday'
|
2
2
|
require 'yajl'
|
3
3
|
|
4
4
|
module Mailjet
|
5
5
|
class Connection
|
6
6
|
|
7
|
-
attr_accessor :adapter, :public_operations, :read_only, :perform_api_call, :
|
7
|
+
attr_accessor :adapter, :public_operations, :read_only, :perform_api_call, :api_key, :secret_key, :options
|
8
8
|
alias :read_only? :read_only
|
9
9
|
|
10
10
|
def [](suburl, &new_block)
|
11
|
-
broken_url =
|
11
|
+
broken_url = uri.path.split("/")
|
12
12
|
if broken_url.include?("contactslist") && broken_url.include?("managemanycontacts") && broken_url.last.to_i > 0
|
13
|
-
self.class.new(
|
13
|
+
self.class.new(uri, api_key, secret_key, options)
|
14
14
|
else
|
15
|
-
self.class.new(concat_urls(
|
15
|
+
self.class.new(concat_urls(suburl), api_key, secret_key, options)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
def initialize(end_point, api_key, secret_key, options = {})
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
# #Output for debugging
|
24
|
-
# RestClient.log =
|
25
|
-
# Object.new.tap do |proxy|
|
26
|
-
# def proxy.<<(message)
|
27
|
-
# Rails.logger.info message
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# #
|
31
|
-
adapter_class = options[:adapter_class] || RestClient::Resource
|
20
|
+
self.options = options
|
21
|
+
self.api_key = api_key
|
22
|
+
self.secret_key = secret_key
|
32
23
|
self.public_operations = options[:public_operations] || []
|
33
24
|
self.read_only = options[:read_only]
|
34
|
-
self.
|
35
|
-
|
36
|
-
|
37
|
-
|
25
|
+
self.adapter = Faraday.new(end_point, ssl: { verify: false }) do |conn|
|
26
|
+
conn.response :raise_error, include_request: true
|
27
|
+
conn.request :authorization, :basic, api_key, secret_key
|
28
|
+
conn.headers['Content-Type'] = 'application/json'
|
29
|
+
end
|
38
30
|
self.perform_api_call = options.key?(:perform_api_call) ? options[:perform_api_call] : true
|
39
31
|
end
|
40
32
|
|
@@ -54,34 +46,31 @@ module Mailjet
|
|
54
46
|
handle_api_call(:delete, additional_headers, &block)
|
55
47
|
end
|
56
48
|
|
57
|
-
def
|
58
|
-
self.adapter.
|
59
|
-
end
|
60
|
-
|
61
|
-
def concat_urls(*options)
|
62
|
-
self.adapter.concat_urls(*options)
|
49
|
+
def concat_urls(suburl)
|
50
|
+
self.adapter.build_url(suburl.to_s)
|
63
51
|
end
|
64
52
|
|
65
|
-
def
|
66
|
-
self.adapter.
|
53
|
+
def uri
|
54
|
+
self.adapter.build_url
|
67
55
|
end
|
68
56
|
|
69
57
|
private
|
70
58
|
|
71
59
|
def handle_api_call(method, additional_headers = {}, payload = {}, &block)
|
72
|
-
formatted_payload = (additional_headers[
|
60
|
+
formatted_payload = (additional_headers["Content-Type"] == 'application/json') ? Yajl::Encoder.encode(payload) : payload
|
73
61
|
raise Mailjet::MethodNotAllowed unless method_allowed(method)
|
74
62
|
|
75
63
|
if self.perform_api_call
|
76
64
|
if [:get, :delete].include?(method)
|
77
|
-
@adapter.send(method, additional_headers, &block)
|
65
|
+
@adapter.send(method, nil, additional_headers[:params], &block)
|
78
66
|
else
|
79
|
-
@adapter.send(method, formatted_payload, additional_headers, &block)
|
67
|
+
@adapter.send(method, nil, formatted_payload, additional_headers, &block)
|
80
68
|
end
|
81
69
|
else
|
82
70
|
return Yajl::Encoder.encode({'Count' => 0, 'Data' => [mock_api_call: true], 'Total' => 0})
|
83
71
|
end
|
84
|
-
|
72
|
+
|
73
|
+
rescue Faraday::Error => e
|
85
74
|
handle_exception(e, additional_headers, formatted_payload)
|
86
75
|
end
|
87
76
|
|
@@ -91,20 +80,20 @@ module Mailjet
|
|
91
80
|
end
|
92
81
|
|
93
82
|
def handle_exception(e, additional_headers, payload = {})
|
94
|
-
return e.
|
83
|
+
return e.response_body if e.response_headers[:content_type].include?("text/plain")
|
95
84
|
|
96
85
|
params = additional_headers[:params] || {}
|
97
86
|
formatted_payload = (additional_headers[:content_type] == :json) ? Yajl::Parser.parse(payload) : payload
|
98
87
|
params = params.merge!(formatted_payload) if formatted_payload.is_a?(Hash)
|
99
88
|
|
100
|
-
|
101
|
-
e.
|
89
|
+
response_body = if e.response_headers[:content_type].include?("application/json")
|
90
|
+
e.response_body
|
102
91
|
else
|
103
92
|
"{}"
|
104
93
|
end
|
105
94
|
|
106
|
-
if sent_invalid_email?(e.
|
107
|
-
return e.
|
95
|
+
if sent_invalid_email?(e.response_body, @adapter.build_url)
|
96
|
+
return e.response_body
|
108
97
|
else
|
109
98
|
raise communication_error(e)
|
110
99
|
end
|
@@ -112,20 +101,20 @@ module Mailjet
|
|
112
101
|
|
113
102
|
def communication_error(e)
|
114
103
|
if e.respond_to?(:response) && e.response
|
115
|
-
return case e.
|
104
|
+
return case e.response_status
|
116
105
|
when Unauthorized::CODE
|
117
|
-
Unauthorized.new(e.message, e
|
106
|
+
Unauthorized.new(e.message, e)
|
118
107
|
when BadRequest::CODE
|
119
|
-
BadRequest.new(e.message, e
|
108
|
+
BadRequest.new(e.message, e)
|
120
109
|
else
|
121
|
-
CommunicationError.new(e.message, e
|
110
|
+
CommunicationError.new(e.message, e)
|
122
111
|
end
|
123
112
|
end
|
124
113
|
CommunicationError.new(e.message)
|
125
114
|
end
|
126
115
|
|
127
|
-
def sent_invalid_email?(error_http_body,
|
128
|
-
return false unless
|
116
|
+
def sent_invalid_email?(error_http_body, uri)
|
117
|
+
return false unless uri.path.include?('v3.1/send')
|
129
118
|
return unless error_http_body
|
130
119
|
|
131
120
|
parsed_body = Yajl::Parser.parse(error_http_body)
|
@@ -138,6 +127,5 @@ module Mailjet
|
|
138
127
|
end
|
139
128
|
|
140
129
|
class MethodNotAllowed < StandardError
|
141
|
-
|
142
130
|
end
|
143
131
|
end
|
@@ -51,13 +51,13 @@ module Mailjet
|
|
51
51
|
@code = if response.nil?
|
52
52
|
NOCODE
|
53
53
|
else
|
54
|
-
response.
|
54
|
+
response.response_status
|
55
55
|
end
|
56
56
|
|
57
57
|
api_message = begin
|
58
|
-
Yajl::Parser.parse(response.
|
58
|
+
Yajl::Parser.parse(response.response_body)['ErrorMessage']
|
59
59
|
rescue Yajl::ParseError
|
60
|
-
response.
|
60
|
+
response.response_body
|
61
61
|
rescue NoMethodError
|
62
62
|
"Unknown API error"
|
63
63
|
rescue
|
data/lib/mailjet/resource.rb
CHANGED
@@ -15,7 +15,7 @@ require 'active_support/core_ext/hash/indifferent_access'
|
|
15
15
|
module Mailjet
|
16
16
|
module Resource
|
17
17
|
# define here available options for filtering
|
18
|
-
OPTIONS = [:version, :url, :perform_api_call, :api_key, :secret_key
|
18
|
+
OPTIONS = [:version, :url, :perform_api_call, :api_key, :secret_key]
|
19
19
|
|
20
20
|
NON_JSON_URLS = ['v3/send/message'] # urls that don't accept JSON input
|
21
21
|
DATA_URLS = ['plain', 'csv'] # url for send binary data , 'CSVError/text:csv'
|
@@ -39,21 +39,20 @@ module Mailjet
|
|
39
39
|
options[:secret_key] || Mailjet.config.secret_key,
|
40
40
|
public_operations: public_operations,
|
41
41
|
read_only: read_only,
|
42
|
-
perform_api_call: options[:perform_api_call]
|
43
|
-
open_timeout: options[:open_timeout],
|
44
|
-
read_timeout: options[:read_timeout])
|
42
|
+
perform_api_call: options[:perform_api_call])
|
45
43
|
end
|
46
44
|
|
47
45
|
def self.default_headers
|
48
46
|
if NON_JSON_URLS.include?(self.resource_path) # don't use JSON if Send API
|
49
|
-
default_headers = {
|
50
|
-
elsif DATA_URLS.any?
|
51
|
-
|
52
|
-
|
47
|
+
default_headers = { 'Accept' =>'application/json', 'Accept-Encoding' => 'deflate' }
|
48
|
+
elsif DATA_URLS.any? do |data_type|
|
49
|
+
default_headers = { 'Content-Type' => "text/#{data_type}" } if self.resource_path.include?(data_type)
|
50
|
+
end
|
53
51
|
else
|
54
|
-
|
52
|
+
# use JSON if *not* Send API
|
53
|
+
default_headers = {'Content-Type' =>'application/json', 'Accept' =>'application/json', 'Accept-Encoding' => 'deflate'}
|
55
54
|
end
|
56
|
-
return default_headers.merge!(
|
55
|
+
return default_headers.merge!('User-Agent' => "mailjet-api-v3-ruby/#{Gem.loaded_specs["mailjet"].version}")
|
57
56
|
end
|
58
57
|
end
|
59
58
|
end
|
@@ -69,7 +68,7 @@ module Mailjet
|
|
69
68
|
opts = define_options(options)
|
70
69
|
params = format_params(params)
|
71
70
|
response = connection(opts).get(default_headers.merge!(params: params))
|
72
|
-
attribute_array = parse_api_json(response)
|
71
|
+
attribute_array = parse_api_json(response.body)
|
73
72
|
attribute_array.map{ |attributes| instanciate_from_api(attributes) }
|
74
73
|
rescue Mailjet::ApiError => error
|
75
74
|
raise error
|
@@ -78,7 +77,7 @@ module Mailjet
|
|
78
77
|
def count(options = {})
|
79
78
|
opts = define_options(options)
|
80
79
|
response_json = connection(opts).get(default_headers.merge!(params: {limit: 1, countrecords: 1}))
|
81
|
-
response_hash = Yajl::Parser.parse(response_json)
|
80
|
+
response_hash = Yajl::Parser.parse(response_json.body)
|
82
81
|
response_hash['Total']
|
83
82
|
rescue Mailjet::ApiError => error
|
84
83
|
raise error
|
@@ -95,7 +94,7 @@ module Mailjet
|
|
95
94
|
opts = define_options(options)
|
96
95
|
self.resource_path = create_action_resource_path(normalized_id, job_id) if self.action
|
97
96
|
|
98
|
-
attributes = parse_api_json(connection(opts)[normalized_id].get(default_headers)).first
|
97
|
+
attributes = parse_api_json(connection(opts)[normalized_id].get(default_headers).body).first
|
99
98
|
instanciate_from_api(attributes)
|
100
99
|
|
101
100
|
rescue Mailjet::CommunicationError => e
|
@@ -106,6 +105,14 @@ module Mailjet
|
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
108
|
+
|
109
|
+
def find_by_id(id, options = {})
|
110
|
+
# if action method, ammend url to appropriate id
|
111
|
+
opts = define_options(options)
|
112
|
+
self.resource_path = create_action_resource_path(id) if self.action
|
113
|
+
connection(opts).get(default_headers)
|
114
|
+
end
|
115
|
+
|
109
116
|
def create(attributes = {}, options = {})
|
110
117
|
# if action method, ammend url to appropriate id
|
111
118
|
opts = define_options(options)
|
@@ -139,19 +146,12 @@ module Mailjet
|
|
139
146
|
def send_data(id, binary_data = nil, options = {})
|
140
147
|
opts = define_options(options)
|
141
148
|
self.resource_path = create_action_resource_path(id) if self.action
|
149
|
+
response = connection(opts).post(binary_data, default_headers.merge({'Content-Length' => "#{binary_data.size}", 'Transfer-Encoding' => 'chunked'}))
|
142
150
|
|
143
|
-
response_hash = Yajl::Parser.parse(
|
151
|
+
response_hash = response.respond_to?(:body) ? Yajl::Parser.parse(response.body) : Yajl::Parser.parse(response)
|
144
152
|
response_hash['ID'] ? response_hash['ID'] : response_hash
|
145
153
|
end
|
146
154
|
|
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)
|
153
|
-
end
|
154
|
-
|
155
155
|
def instanciate_from_api(attributes = {})
|
156
156
|
self.new(attributes.merge!(persisted: true))
|
157
157
|
end
|
@@ -284,9 +284,9 @@ module Mailjet
|
|
284
284
|
if opts[:perform_api_call] && !persisted?
|
285
285
|
# get attributes only for entity creation
|
286
286
|
self.attributes = if self.resource_path == 'send'
|
287
|
-
Yajl::Parser.parse(response)
|
287
|
+
Yajl::Parser.parse(response.body)
|
288
288
|
else
|
289
|
-
parse_api_json(response).first
|
289
|
+
parse_api_json(response.body).first
|
290
290
|
end
|
291
291
|
end
|
292
292
|
|
@@ -11,7 +11,7 @@ module Mailjet
|
|
11
11
|
opts = define_options(options)
|
12
12
|
self.resource_path = create_action_resource_path(id, job_id) if self.action
|
13
13
|
|
14
|
-
raw_data = parse_api_json(connection(opts)[id].get(default_headers))
|
14
|
+
raw_data = parse_api_json(connection(opts)[id].get(default_headers).body)
|
15
15
|
|
16
16
|
raw_data.map do |entity|
|
17
17
|
instanciate_from_api(entity)
|
@@ -5,20 +5,15 @@ module Mailjet
|
|
5
5
|
self.public_operations = [:get, :put, :post]
|
6
6
|
self.filters = [:campaign, :contacts_list, :is_unsubscribed, :last_activity_at, :recipient, :status]
|
7
7
|
self.resourceprop = [
|
8
|
-
:created_at,
|
9
8
|
:delivered_count,
|
10
9
|
:email,
|
11
10
|
:id,
|
12
11
|
:is_opt_in_pending,
|
13
12
|
:is_spam_complaining,
|
14
|
-
:last_activity_at,
|
15
|
-
:last_update_at,
|
16
13
|
:name,
|
17
|
-
:unsubscribed_at,
|
18
14
|
:unsubscribed_by,
|
19
15
|
:is_excluded_from_campaigns
|
20
16
|
]
|
21
17
|
self.read_only_attributes = [:created_at, :last_activity_at, :last_update_at, :unsubscribed_at]
|
22
|
-
|
23
18
|
end
|
24
19
|
end
|
@@ -11,7 +11,7 @@ module Mailjet
|
|
11
11
|
opts = define_options(options)
|
12
12
|
self.resource_path = create_action_resource_path(id, job_id) if self.action
|
13
13
|
|
14
|
-
raw_data = parse_api_json(connection(opts).get(default_headers))
|
14
|
+
raw_data = parse_api_json(connection(opts).get(default_headers).body)
|
15
15
|
|
16
16
|
raw_data.map do |entity|
|
17
17
|
instanciate_from_api(entity)
|
@@ -4,7 +4,8 @@ module Mailjet
|
|
4
4
|
self.resource_path = 'REST/listrecipient'
|
5
5
|
self.public_operations = [:get, :put, :post, :delete]
|
6
6
|
self.filters = [:active, :blocked, :contact, :contact_email, :contacts_list, :last_activity_at, :list_name, :opened, :status, :unsub]
|
7
|
-
self.resourceprop = [:contact, :id, :is_active, :is_unsubscribed, :list, :
|
7
|
+
self.resourceprop = [:contact, :id, :is_active, :is_unsubscribed, :list, :contact_id, :list_id, 'ContactID', 'ListID', 'ContactALT', 'ListALT']
|
8
8
|
|
9
|
+
self.read_only_attributes = [:subscribed_at, :unsubscribed_at]
|
9
10
|
end
|
10
11
|
end
|
@@ -12,7 +12,7 @@ module Mailjet
|
|
12
12
|
opts = define_options(options)
|
13
13
|
self.resource_path = create_action_resource_path(id, job_id) if self.action
|
14
14
|
|
15
|
-
raw_data = parse_api_json(connection(opts)[id].get(default_headers))
|
15
|
+
raw_data = parse_api_json(connection(opts)[id].get(default_headers).body)
|
16
16
|
|
17
17
|
raw_data.map do |entity|
|
18
18
|
instanciate_from_api(entity)
|
@@ -12,7 +12,7 @@ module Mailjet
|
|
12
12
|
opts = define_options(options)
|
13
13
|
self.resource_path = create_action_resource_path(id, job_id) if self.action
|
14
14
|
|
15
|
-
raw_data = parse_api_json(connection(opts)[id].get(default_headers))
|
15
|
+
raw_data = parse_api_json(connection(opts)[id].get(default_headers).body)
|
16
16
|
|
17
17
|
raw_data.map do |entity|
|
18
18
|
instanciate_from_api(entity)
|
@@ -12,7 +12,7 @@ module Mailjet
|
|
12
12
|
opts = define_options(options)
|
13
13
|
self.resource_path = create_action_resource_path(id, job_id) if self.action
|
14
14
|
|
15
|
-
raw_data = parse_api_json(connection(opts)[id].get(default_headers))
|
15
|
+
raw_data = parse_api_json(connection(opts)[id].get(default_headers).body)
|
16
16
|
|
17
17
|
raw_data.map do |entity|
|
18
18
|
instanciate_from_api(entity)
|
@@ -12,7 +12,7 @@ module Mailjet
|
|
12
12
|
|
13
13
|
opts = define_options(options)
|
14
14
|
response = connection(opts).get(default_headers)
|
15
|
-
attributes = parse_api_json(response).first
|
15
|
+
attributes = parse_api_json(response.body).first
|
16
16
|
|
17
17
|
instanciate_from_api(attributes)
|
18
18
|
rescue Mailjet::CommunicationError => e
|
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.
|
4
|
+
version: 1.8.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: 2024-
|
14
|
+
date: 2024-08-30 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -42,19 +42,19 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: 1.4.0
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
|
-
name:
|
45
|
+
name: faraday
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
|
-
- - "
|
48
|
+
- - "~>"
|
49
49
|
- !ruby/object:Gem::Version
|
50
|
-
version: 2.1
|
50
|
+
version: '2.1'
|
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.1
|
57
|
+
version: '2.1'
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: yajl-ruby
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
@@ -306,7 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
306
306
|
- !ruby/object:Gem::Version
|
307
307
|
version: '0'
|
308
308
|
requirements: []
|
309
|
-
rubygems_version: 3.
|
309
|
+
rubygems_version: 3.1.6
|
310
310
|
signing_key:
|
311
311
|
specification_version: 4
|
312
312
|
summary: Mailjet a powerful all-in-one email service provider clients can use to get
|