mailjet 1.5.3 → 1.5.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ce7a69f28969e1a632cc70e07a8a04b973576f5f
4
- data.tar.gz: 3a7bf17b3fd83efeb88427b6bc09f184d41b9996
3
+ metadata.gz: 7240913ecc6542f14a4c9cc7078347f4c55032a3
4
+ data.tar.gz: 70d23c920e3b4d1e45d843eab8034fff9e2086bf
5
5
  SHA512:
6
- metadata.gz: 3043cf5a15c67cb008677ea98b439ef656e5ce5f6bcad3f3fba3497ea1dae6f8f99e637d7a27cb07c11ee1f12d46e4e30b573ea01258e1901f32cdc6a4c7a5c2
7
- data.tar.gz: 672355e584024830232f12dcbea25e1d6e5ac543ddf56476cd2a64b55e45b9a920eb4f667a7e08ae6f9ca5f0a7bf6f0d22812013705ecf49bac69ad70e344e5d
6
+ metadata.gz: 2bf10f5fd0dd62f207b1d84ee7bb178c31a2501a291b2983cfa391707e10e95b73d4e087fdf66713cf99cfd05f5863f51748eb1f11b8964339ad38073132f031
7
+ data.tar.gz: 1db8b006b9c5393fa185ba0dd36964e4bbb2395e9294a35d8ca76a2a170a2a8f397e623c1a9838c02e219a30b43f1214929058ea1ca9a0706d52d4150be809b1
data/README.md CHANGED
@@ -103,6 +103,13 @@ end
103
103
 
104
104
  `default_from` is optional if you send emails with `:mailjet`'s SMTP (below)
105
105
 
106
+ But if you are using Mailjet with Rails, you can simply generate it:
107
+
108
+ ```shell
109
+ $ rails generate mailjet:initializer
110
+ ```
111
+
112
+
106
113
  ### Send emails via the Send API
107
114
 
108
115
  Find more about the Mailjet Send API in the [official guides](http://dev.mailjet.com/guides/?ruby#choose-sending-method)
@@ -229,7 +236,7 @@ class UserMailer < ApplicationMailer
229
236
  end
230
237
  end
231
238
  ```
232
- For sending email, you can call the method with a variety of `MessageDelivery` priorities:
239
+ For sending email, you can call the method:
233
240
  ```ruby
234
241
  # In this example, we are sending the email immediately
235
242
  UserMailer.welcome_email.deliver_now!
@@ -360,15 +367,15 @@ Mailjet::Contact_managemanycontacts.find(nil, 34062)
360
367
 
361
368
  ## Send emails through API
362
369
 
363
- In order to send emails through the API, you just have to `create` a new `MessageDelivery` resource.
370
+ In order to send emails through the API, you just have to `create` a new `Send` resource.
364
371
 
365
372
  ``` ruby
366
- Mailjet::MessageDelivery.create(from: "me@example.com", to: "you@example.com", subject: "Mailjet is awesome", text: "Yes, it is!")
373
+ Mailjet::Send.create(from_email: "me@example.com", to: "you@example.com", subject: "Mailjet is awesome", text_part: "Yes, it is!")
367
374
  ```
368
375
 
369
376
  If you want to send it to multiple recipients, just use an array:
370
377
  ``` ruby
371
- Mailjet::MessageDelivery.create(from: "me@example.com", to: ["you@example.com", "someone-else@example.com"], subject: "Mailjet is awesome", text: "Yes, it is!")
378
+ Mailjet::Send.create(from_email: "me@example.com", to: "you@example.com, someone-else@example.com", subject: "Mailjet is awesome", text_part: "Yes, it is!")
372
379
  ```
373
380
 
374
381
  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`.
@@ -0,0 +1,35 @@
1
+ module Mailjet
2
+ class InitializerGenerator < Rails::Generators::Base
3
+ desc 'This generator creates an initializer file mailjet.rb at config/initializers'
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def generate_initializer_file
8
+ config_file_path = 'config/initializers/mailjet.rb'
9
+
10
+ say('Hey! We’re about to configure your Mailjet credentials for your application.')
11
+ say('You can find them on your account (https://app.mailjet.com/account/api_keys).')
12
+ say('Please help yourself by providing some intel:')
13
+
14
+ @api_key = ask('API key: ')
15
+ @secret_key = ask('Secret key: ')
16
+ @default_from = ask('Sender address:')
17
+
18
+ say("Don't forget that your sender address '#{@default_from}' has to be validated first on https://app.mailjet.com/account/sender.")
19
+
20
+ if @api_v3_1 = yes?('Do you want to use Mailjet API v3.1 for sending your emails? (y/n)')
21
+ @api_v3_1_notice = %{
22
+ Mailjet API v3.1 is at the moment limited to Send API.
23
+ We’ve not set the version to it directly since there is no other endpoint in that version.
24
+ We recommend you create a dedicated instance of the wrapper set with it to send your emails.
25
+ If you're only using the gem to send emails, then you can safely set it to this version.
26
+ Otherwise, you can remove the dedicated line into #{config_file_path}.
27
+
28
+ }
29
+ say(@api_v3_1_notice)
30
+ end
31
+
32
+ template 'mailjet.rb.erb', config_file_path
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,8 @@
1
+ # kindly generated by appropriated Rails generator
2
+ Mailjet.configure do |config|
3
+ config.api_key = '<%= @api_key %>'
4
+ config.secret_key = '<%= @secret_key %>'
5
+ config.default_from = '<%= @default_from %>'
6
+ <% if @api_v3_1 %><%= @api_v3_1_notice.split("\n").reject(&:empty?).map{ |l| ' # ' + l }.join("\n") %>
7
+ config.api_version = 'v3.1'<% end %>
8
+ end
@@ -26,46 +26,48 @@ ActionMailer::Base.add_delivery_method :mailjet, Mailjet::Mailer
26
26
  # Mailjet sends API expects a JSON payload as the input.
27
27
  # The deliver methods maps the Mail::Message attributes to the MailjetSend API JSON expected structure
28
28
  class Mailjet::APIMailer
29
- def initialize(options = {})
30
- # send = Mailjet.Send.new
31
- # if send.version.exists
32
- # version = send.version
33
- # else
34
- @version = Mailjet.config.api_version
35
- # end
36
- @delivery_method_options_v3_0 = options.slice(
37
- :api_key, :secret_key,
38
- :recipients, :'mj-prio', :'mj-campaign', :'mj-deduplicatecampaign',
39
- :'mj-templatelanguage', :'mj-templateerrorreporting', :'mj-templateerrordeliver', :'mj-templateid',
40
- :'mj-trackopen', :'mj-trackclick',
41
- :'mj-customid', :'mj-eventpayload', :vars, :headers,
42
- )
43
- @delivery_method_options_v3_1 = options.slice(
44
- :api_key, :secret_key,
45
- :'Priority', :'CustomCampaign', :'DeduplicateCampaign',
46
- :'TemplateLanguage', :'TemplateErrorReporting', :'TemplateErrorDeliver', :'TemplateID',
47
- :'TrackOpens', :'TrackClicks',
48
- :'CustomID', :'EventPayload', :'Variables', :'Headers',
49
- )
29
+ V3_0_PERMITTED_OPTIONS = [
30
+ :recipients, :'mj-prio', :'mj-campaign', :'mj-deduplicatecampaign',
31
+ :'mj-templatelanguage', :'mj-templateerrorreporting', :'mj-templateerrordeliver', :'mj-templateid',
32
+ :'mj-trackopen', :'mj-trackclick',
33
+ :'mj-customid', :'mj-eventpayload', :vars, :headers,
34
+ ]
35
+
36
+ V3_1_PERMITTED_OPTIONS = [
37
+ :'Priority', :'CustomCampaign', :'DeduplicateCampaign',
38
+ :'TemplateLanguage', :'TemplateErrorReporting', :'TemplateErrorDeliver', :'TemplateID',
39
+ :'TrackOpens', :'TrackClicks',
40
+ :'CustomID', :'EventPayload', :'Variables', :'Headers',
41
+ ]
42
+
43
+ CONNECTION_PERMITTED_OPTIONS = [:api_key, :secret_key]
44
+
45
+ def initialize(opts = {})
46
+ options = HashWithIndifferentAccess.new(opts)
47
+
48
+ @version = options[:version]
49
+ @delivery_method_options_v3_0 = options.slice(*V3_0_PERMITTED_OPTIONS)
50
+ @delivery_method_options_v3_1 = options.slice(*V3_1_PERMITTED_OPTIONS)
51
+ @connection_options = options.slice(*CONNECTION_PERMITTED_OPTIONS)
50
52
  end
51
53
 
52
- def deliver!(mail, options = {})
54
+ def deliver!(mail, opts = {})
55
+ options = HashWithIndifferentAccess.new(opts)
53
56
 
54
- if (options && options.kind_of?(Object) && options['version'].present?)
55
- @version = options['version']
56
- end
57
+ # Mailjet Send API does not support full from. Splitting the from field into two: name and email address
58
+ mail[:from] ||= Mailjet.config.default_from if Mailjet.config.default_from
57
59
 
58
- if (!options.kind_of?(Object))
59
- options = []
60
- end
60
+ # add `@connection_options` in `options` only if not exist yet (values in `options` prime)
61
+ options.reverse_merge!(@connection_options)
61
62
 
62
- # Mailjet Send API does not support full from. Splitting the from field into two: name and email address
63
- if mail[:from].nil? && Mailjet.config.default_from.present?
64
- mail[:from] = Mailjet.config.default_from
65
- end
63
+ # add `@version` in options if set
64
+ options[:version] = @version if @version
65
+
66
+ # `options[:version]` primes on global config
67
+ version = options[:version] || Mailjet.config.api_version
66
68
 
67
- if (@version == 'v3.1')
68
- Mailjet::Send.create({:Messages => [setContentV3_1(mail)]}, options)
69
+ if (version == 'v3.1')
70
+ Mailjet::Send.create({ :Messages => [setContentV3_1(mail)] }, options)
69
71
  else
70
72
  Mailjet::Send.create(setContentV3_0(mail), options)
71
73
  end
@@ -20,6 +20,9 @@ module Mailjet
20
20
  module Resource
21
21
  extend ActiveSupport::Concern
22
22
 
23
+ # define here available options for filtering
24
+ OPTIONS = [:version, :url, :perform_api_call, :api_key, :secret_key]
25
+
23
26
  NON_JSON_URLS = ['v3/send/message'] # urls that don't accept JSON input
24
27
 
25
28
  included do
@@ -56,7 +59,7 @@ module Mailjet
56
59
  end
57
60
 
58
61
  def all(params = {}, options = {})
59
- opts = change_resource_path(options)
62
+ opts = define_options(options)
60
63
  params = format_params(params)
61
64
  response = connection(opts).get(default_headers.merge(params: params))
62
65
  attribute_array = parse_api_json(response)
@@ -64,7 +67,7 @@ module Mailjet
64
67
  end
65
68
 
66
69
  def count(options = {})
67
- opts = change_resource_path(options)
70
+ opts = define_options(options)
68
71
  response_json = connection(opts).get(default_headers.merge(params: {limit: 1, countrecords: 1}))
69
72
  response_hash = ActiveSupport::JSON.decode(response_json)
70
73
  response_hash['Total']
@@ -72,7 +75,7 @@ module Mailjet
72
75
 
73
76
  def find(id, job_id = nil, options = {})
74
77
  # if action method, ammend url to appropriate id
75
- opts = change_resource_path(options)
78
+ opts = define_options(options)
76
79
  self.resource_path = create_action_resource_path(id, job_id) if self.action
77
80
  #
78
81
  attributes = parse_api_json(connection(opts)[id].get(default_headers)).first
@@ -88,7 +91,7 @@ module Mailjet
88
91
 
89
92
  def create(attributes = {}, options = {})
90
93
  # if action method, ammend url to appropriate id
91
- opts = change_resource_path(options)
94
+ opts = define_options(options)
92
95
  self.resource_path = create_action_resource_path(attributes[:id]) if self.action
93
96
  attributes.tap { |hs| hs.delete(:id) }
94
97
 
@@ -110,7 +113,7 @@ module Mailjet
110
113
 
111
114
  def delete(id, options = {})
112
115
  # if action method, ammend url to appropriate id
113
- opts = change_resource_path(options)
116
+ opts = define_options(options)
114
117
  self.resource_path = create_action_resource_path(id) if self.action
115
118
  connection(opts)[id].delete(default_headers)
116
119
  end
@@ -211,26 +214,14 @@ module Mailjet
211
214
  end
212
215
  end
213
216
 
214
- def change_resource_path(options = {})
215
- ver = choose_version(options)
216
- url = Mailjet.config.end_point
217
- perform_api_call = Mailjet.config.perform_api_call
218
- if options.any?
219
- if options.key?(:perform_api_call)
220
- perform_api_call = options[:perform_api_call]
221
- end
222
- if options.key?(:url)
223
- url = options[:url]
224
- end
225
- end
226
- ret = {version: ver, url: url, perform_api_call: perform_api_call}
227
- ret
228
- end
229
-
230
- def choose_version(options = {})
231
- ver = options['version'] || Mailjet.config.api_version || version
232
-
233
- ver
217
+ def define_options(options = {})
218
+ # merge default options with given ones on-the-fly
219
+ {
220
+ version: version || Mailjet.config.api_version,
221
+ url: Mailjet.config.end_point,
222
+ perform_api_call: Mailjet.config.perform_api_call
223
+ }
224
+ .merge(options.symbolize_keys.slice(*OPTIONS))
234
225
  end
235
226
 
236
227
  end
@@ -246,7 +237,7 @@ module Mailjet
246
237
  end
247
238
 
248
239
  def save(options = {})
249
- opts = self.class.change_resource_path(options)
240
+ opts = self.class.define_options(options)
250
241
 
251
242
  if persisted?
252
243
  # case where the entity is updated
@@ -297,7 +288,7 @@ module Mailjet
297
288
  end
298
289
  end
299
290
 
300
- opts = self.class.change_resource_path(options)
291
+ opts = self.class.define_options(options)
301
292
  save(opts)
302
293
  end
303
294
 
@@ -1,3 +1,3 @@
1
1
  module Mailjet
2
- VERSION = "1.5.3"
2
+ VERSION = "1.5.4"
3
3
  end
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.5.3
4
+ version: 1.5.4
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: 2017-06-30 00:00:00.000000000 Z
14
+ date: 2017-07-03 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: activesupport
@@ -277,6 +277,8 @@ files:
277
277
  - MIT-LICENSE
278
278
  - README.md
279
279
  - Rakefile
280
+ - lib/generators/mailjet/initializer_generator.rb
281
+ - lib/generators/mailjet/templates/mailjet.rb.erb
280
282
  - lib/mailjet.rb
281
283
  - lib/mailjet/api_error.rb
282
284
  - lib/mailjet/collection_proxy.rb
@@ -374,7 +376,17 @@ files:
374
376
  homepage: http://www.mailjet.com
375
377
  licenses: []
376
378
  metadata: {}
377
- post_install_message:
379
+ post_install_message: |2+
380
+
381
+ The Ruby wrapper for Mailjet has just been installed successfully, congrats!
382
+ Maybe you want to configure your credentials to use your account.
383
+ All informations available on https://github.com/mailjet/mailjet-gem.
384
+ But if you are using Rails, you'll be glad to generate it easily using:
385
+
386
+ $ rails generate mailjet:initializer
387
+
388
+ We hope you will enjoy Mailjet!
389
+
378
390
  rdoc_options: []
379
391
  require_paths:
380
392
  - lib
@@ -390,7 +402,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
390
402
  version: '0'
391
403
  requirements: []
392
404
  rubyforge_project:
393
- rubygems_version: 2.4.8
405
+ rubygems_version: 2.5.1
394
406
  signing_key:
395
407
  specification_version: 4
396
408
  summary: Mailjet a powerful all-in-one email service provider clients can use to get