mailjet 1.6.0 → 1.7.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/Rakefile +4 -0
- data/lib/mailjet/configuration.rb +55 -4
- data/lib/mailjet/connection.rb +12 -3
- data/lib/mailjet/rack/endpoint.rb +2 -3
- data/lib/mailjet/resource.rb +33 -33
- data/lib/mailjet/resources/campaigndraft_detailcontent.rb +16 -0
- data/lib/mailjet/resources/messageinformation.rb +17 -0
- data/lib/mailjet/resources/openinformation.rb +17 -0
- data/lib/mailjet/resources/send.rb +1 -1
- data/lib/mailjet/version.rb +1 -1
- data/lib/mailjet.rb +2 -2
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfee84cc597efea5f25e0a7698c37491da287b01283a45719e6d53a7650714db
|
4
|
+
data.tar.gz: bdc076e42432663e56783b4caef82eb558921f993f12ee681cad59740f217954
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c10c72fd4adf737b4e80c73b1c2c18daf7a0e0490426041abfbcaf3c918c29d72098a1114941d027e2befdcb77297691941a2f11c16e1372dd9037f9a163eab
|
7
|
+
data.tar.gz: ac4d539fcb23e3496d232fc51cfdf24170142b48b87ee0c448bd6457cda985e6f8635c38b6252aea87782fdb93363363030e247c9c24eb2d14a8caf7d64caff0
|
data/Rakefile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require "rspec/core/rake_task"
|
2
|
+
require 'bundler/gem_tasks'
|
2
3
|
|
3
4
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
4
5
|
t.pattern = [
|
6
|
+
"spec/mailjet/rack/endpoint_spec.rb",
|
5
7
|
"spec/mailjet/api_error_spec.rb",
|
6
8
|
"spec/mailjet/apikey_spec.rb",
|
7
9
|
"spec/mailjet/mailer_spec.rb",
|
@@ -16,6 +18,8 @@ RSpec::Core::RakeTask.new(:spec) do |t|
|
|
16
18
|
"spec/resources/integration_spec.rb",
|
17
19
|
"spec/resources/newsletter_spec.rb",
|
18
20
|
"spec/resources/statcounters_spec.rb",
|
21
|
+
"spec/resources/send_spec.rb",
|
22
|
+
"spec/resources/resource_spec.rb",
|
19
23
|
]
|
20
24
|
end
|
21
25
|
|
@@ -1,8 +1,60 @@
|
|
1
|
-
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
-
|
3
1
|
module Mailjet
|
4
2
|
module Configuration
|
5
|
-
|
3
|
+
def self.api_key
|
4
|
+
@api_key
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.api_key=(api_key)
|
8
|
+
@api_key = api_key
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.secret_key
|
12
|
+
@secret_key
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.secret_key=(secret_key)
|
16
|
+
@secret_key = secret_key
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.default_from
|
20
|
+
@default_from
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.default_from=(default_from)
|
24
|
+
@default_from = default_from
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.api_version
|
28
|
+
@api_version
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.api_version=(api_version)
|
32
|
+
@api_version = api_version
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.sandbox_mode
|
36
|
+
@sandbox_mode
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.sandbox_mode=(sandbox_mode)
|
40
|
+
@sandbox_mode = sandbox_mode
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.end_point
|
44
|
+
@end_point
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.end_point=(end_point)
|
48
|
+
@end_point = end_point
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.perform_api_call
|
52
|
+
@perform_api_call
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.perform_api_call=(perform_api_call)
|
56
|
+
@perform_api_call = perform_api_call
|
57
|
+
end
|
6
58
|
|
7
59
|
DEFAULT = {
|
8
60
|
api_version: 'v3',
|
@@ -12,7 +64,6 @@ module Mailjet
|
|
12
64
|
}
|
13
65
|
|
14
66
|
DEFAULT.each do |param, default_value|
|
15
|
-
mattr_accessor param
|
16
67
|
self.send("#{param}=", default_value)
|
17
68
|
end
|
18
69
|
end
|
data/lib/mailjet/connection.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'rest_client'
|
2
2
|
require 'mailjet/gem_extensions/rest_client'
|
3
|
-
require 'active_support/core_ext/module/delegation'
|
4
3
|
require 'json'
|
5
4
|
|
6
5
|
module Mailjet
|
@@ -9,8 +8,6 @@ module Mailjet
|
|
9
8
|
attr_accessor :adapter, :public_operations, :read_only, :perform_api_call, :read_timeout, :open_timeout
|
10
9
|
alias :read_only? :read_only
|
11
10
|
|
12
|
-
delegate :options, :concat_urls, :url, to: :adapter
|
13
|
-
|
14
11
|
def [](suburl, &new_block)
|
15
12
|
broken_url = url.split("/")
|
16
13
|
if broken_url.include?("contactslist") && broken_url.include?("managemanycontacts") && broken_url.last.to_i > 0
|
@@ -58,6 +55,18 @@ module Mailjet
|
|
58
55
|
handle_api_call(:delete, additional_headers, &block)
|
59
56
|
end
|
60
57
|
|
58
|
+
def options
|
59
|
+
self.adapter.options
|
60
|
+
end
|
61
|
+
|
62
|
+
def concat_urls(*options)
|
63
|
+
self.adapter.concat_urls(*options)
|
64
|
+
end
|
65
|
+
|
66
|
+
def url
|
67
|
+
self.adapter.url
|
68
|
+
end
|
69
|
+
|
61
70
|
private
|
62
71
|
|
63
72
|
def handle_api_call(method, additional_headers = {}, payload = {}, &block)
|
@@ -1,6 +1,5 @@
|
|
1
|
-
require 'active_support'
|
2
1
|
require 'rack/request'
|
3
|
-
|
2
|
+
require 'json'
|
4
3
|
|
5
4
|
module Mailjet
|
6
5
|
module Rack
|
@@ -13,7 +12,7 @@ module Mailjet
|
|
13
12
|
|
14
13
|
def call(env)
|
15
14
|
if env['PATH_INFO'] == @path && (content = env['rack.input'].read)
|
16
|
-
@block.call(
|
15
|
+
@block.call(JSON.parse(content))
|
17
16
|
[200, { 'Content-Type' => 'text/html', 'Content-Length' => '0' }, []]
|
18
17
|
else
|
19
18
|
@app.call(env)
|
data/lib/mailjet/resource.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
require 'mailjet/connection'
|
2
|
-
require 'active_support/hash_with_indifferent_access'
|
3
|
-
require 'active_support/core_ext/class'
|
4
|
-
require 'active_support/core_ext/hash'
|
5
2
|
require 'active_support/core_ext/string'
|
6
3
|
require 'active_support/core_ext/module/delegation'
|
7
|
-
require 'active_support/
|
8
|
-
require 'active_support/json/decoding'
|
4
|
+
require 'active_support/hash_with_indifferent_access'
|
9
5
|
#require 'mail'
|
10
6
|
require 'json'
|
11
7
|
|
@@ -18,40 +14,42 @@ require 'json'
|
|
18
14
|
|
19
15
|
module Mailjet
|
20
16
|
module Resource
|
21
|
-
extend ActiveSupport::Concern
|
22
17
|
|
23
18
|
# define here available options for filtering
|
24
19
|
OPTIONS = [:version, :url, :perform_api_call, :api_key, :secret_key, :read_timeout, :open_timeout]
|
25
20
|
|
26
21
|
NON_JSON_URLS = ['v3/send/message'] # urls that don't accept JSON input
|
27
22
|
|
28
|
-
included
|
29
|
-
|
30
|
-
|
23
|
+
def self.included(base)
|
24
|
+
base.extend ClassMethods
|
25
|
+
base.class_eval do
|
26
|
+
cattr_accessor :resource_path, :public_operations, :read_only, :filters, :resourceprop, :action, :non_json_urls, :version
|
27
|
+
cattr_writer :connection
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
def self.connection(options = {})
|
30
|
+
class_variable_get(:@@connection) || default_connection(options)
|
31
|
+
end
|
35
32
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
33
|
+
def self.default_connection(options = {})
|
34
|
+
Mailjet::Connection.new(
|
35
|
+
"#{options[:url]}/#{options[:version]}/#{resource_path}",
|
36
|
+
options[:api_key] || Mailjet.config.api_key,
|
37
|
+
options[:secret_key] || Mailjet.config.secret_key,
|
38
|
+
public_operations: public_operations,
|
39
|
+
read_only: read_only,
|
40
|
+
perform_api_call: options[:perform_api_call],
|
41
|
+
open_timeout: options[:open_timeout],
|
42
|
+
read_timeout: options[:read_timeout])
|
43
|
+
end
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
def self.default_headers
|
46
|
+
if NON_JSON_URLS.include?(self.resource_path) # don't use JSON if Send API
|
47
|
+
default_headers = { accept: :json, accept_encoding: :deflate }
|
48
|
+
else
|
49
|
+
default_headers = { accept: :json, accept_encoding: :deflate, content_type: :json } #use JSON if *not* Send API
|
50
|
+
end
|
51
|
+
return default_headers.merge(user_agent: "mailjet-api-v3-ruby/#{Gem.loaded_specs["mailjet"].version}")
|
53
52
|
end
|
54
|
-
return default_headers.merge(user_agent: "mailjet-api-v3-ruby/#{Gem.loaded_specs["mailjet"].version}")
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
@@ -71,7 +69,7 @@ module Mailjet
|
|
71
69
|
def count(options = {})
|
72
70
|
opts = define_options(options)
|
73
71
|
response_json = connection(opts).get(default_headers.merge(params: {limit: 1, countrecords: 1}))
|
74
|
-
response_hash =
|
72
|
+
response_hash = JSON.parse(response_json)
|
75
73
|
response_hash['Total']
|
76
74
|
end
|
77
75
|
|
@@ -131,7 +129,7 @@ module Mailjet
|
|
131
129
|
end
|
132
130
|
|
133
131
|
def parse_api_json(response_json)
|
134
|
-
response_hash =
|
132
|
+
response_hash = JSON.parse(response_json)
|
135
133
|
|
136
134
|
#Take the response from the API and put it through a method -- taken from the ActiveSupport library -- which converts
|
137
135
|
#the date-time from "2014-05-19T15:31:09Z" to "Mon, 19 May 2014 15:31:09 +0000" format.
|
@@ -258,7 +256,7 @@ module Mailjet
|
|
258
256
|
if opts[:perform_api_call] && !persisted?
|
259
257
|
# get attributes only for entity creation
|
260
258
|
self.attributes = if self.resource_path == 'send'
|
261
|
-
|
259
|
+
JSON.parse(response)
|
262
260
|
else
|
263
261
|
parse_api_json(response).first
|
264
262
|
end
|
@@ -322,7 +320,9 @@ module Mailjet
|
|
322
320
|
payload = camelcase_keys(payload)
|
323
321
|
payload.tap { |hs| hs.delete("Persisted") }
|
324
322
|
payload.inject({}) do |h, (k, v)|
|
325
|
-
|
323
|
+
if v.respond_to? :utc
|
324
|
+
v = v.utc.to_s
|
325
|
+
end
|
326
326
|
h.merge!({k => v})
|
327
327
|
end
|
328
328
|
end
|
@@ -7,5 +7,21 @@ module Mailjet
|
|
7
7
|
self.filters = []
|
8
8
|
self.resourceprop = [:text_part, :html_part, :headers, :mjml_content]
|
9
9
|
|
10
|
+
def self.find(id, job_id = nil, options = {})
|
11
|
+
opts = define_options(options)
|
12
|
+
self.resource_path = create_action_resource_path(id, job_id) if self.action
|
13
|
+
|
14
|
+
raw_data = parse_api_json(connection(opts)[id].get(default_headers))
|
15
|
+
|
16
|
+
raw_data.map do |entity|
|
17
|
+
instanciate_from_api(entity)
|
18
|
+
end
|
19
|
+
rescue Mailjet::ApiError => e
|
20
|
+
if e.code == 404
|
21
|
+
nil
|
22
|
+
else
|
23
|
+
raise e
|
24
|
+
end
|
25
|
+
end
|
10
26
|
end
|
11
27
|
end
|
@@ -8,5 +8,22 @@ module Mailjet
|
|
8
8
|
|
9
9
|
self.read_only = true
|
10
10
|
|
11
|
+
def self.find(id, job_id = nil, options = {})
|
12
|
+
opts = define_options(options)
|
13
|
+
self.resource_path = create_action_resource_path(id, job_id) if self.action
|
14
|
+
|
15
|
+
raw_data = parse_api_json(connection(opts)[id].get(default_headers))
|
16
|
+
|
17
|
+
raw_data.map do |entity|
|
18
|
+
instanciate_from_api(entity)
|
19
|
+
end
|
20
|
+
rescue Mailjet::ApiError => e
|
21
|
+
if e.code == 404
|
22
|
+
nil
|
23
|
+
else
|
24
|
+
raise e
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
11
28
|
end
|
12
29
|
end
|
@@ -8,5 +8,22 @@ module Mailjet
|
|
8
8
|
|
9
9
|
self.read_only = true
|
10
10
|
|
11
|
+
def self.find(id, job_id = nil, options = {})
|
12
|
+
opts = define_options(options)
|
13
|
+
self.resource_path = create_action_resource_path(id, job_id) if self.action
|
14
|
+
|
15
|
+
raw_data = parse_api_json(connection(opts)[id].get(default_headers))
|
16
|
+
|
17
|
+
raw_data.map do |entity|
|
18
|
+
instanciate_from_api(entity)
|
19
|
+
end
|
20
|
+
rescue Mailjet::ApiError => e
|
21
|
+
if e.code == 404
|
22
|
+
nil
|
23
|
+
else
|
24
|
+
raise e
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
11
28
|
end
|
12
29
|
end
|
data/lib/mailjet/version.rb
CHANGED
data/lib/mailjet.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'json/ext'
|
2
2
|
require 'ostruct'
|
3
3
|
require 'mailjet/core_extensions/ostruct'
|
4
4
|
require 'mailjet/configuration'
|
@@ -21,7 +21,7 @@ module Mailjet
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
ActiveSupport.on_load(:action_mailer) do
|
25
25
|
require 'action_mailer/version'
|
26
26
|
require 'mailjet/mailer' if ActionMailer::Base.respond_to?(:add_delivery_method)
|
27
27
|
end
|
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.
|
4
|
+
version: 1.7.0
|
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: 2022-04-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activesupport
|
@@ -290,12 +290,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
290
290
|
- !ruby/object:Gem::Version
|
291
291
|
version: '0'
|
292
292
|
requirements: []
|
293
|
-
rubygems_version: 3.
|
294
|
-
signing_key:
|
293
|
+
rubygems_version: 3.0.3
|
294
|
+
signing_key:
|
295
295
|
specification_version: 4
|
296
296
|
summary: Mailjet a powerful all-in-one email service provider clients can use to get
|
297
297
|
maximum insight and deliverability results from both their marketing and transactional
|
298
298
|
emails. Our analytics tools and intelligent APIs give senders the best understanding
|
299
299
|
of how to maximize benefits for each individual contact, with each email sent.
|
300
300
|
test_files: []
|
301
|
-
...
|