From d2a9fcb368aaad35cb71309e9b6398681bb43199 Mon Sep 17 00:00:00 2001 From: Aridjar Date: Mon, 23 Jan 2017 19:21:41 +0100 Subject: [PATCH 01/11] v3.1 ready --- config.json | 8 +++--- mailjet-client.js | 67 +++++++++++++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/config.json b/config.json index e467879..beb4a2f 100755 --- a/config.json +++ b/config.json @@ -1,5 +1,7 @@ { - "url": "api.mailjet.com", - "version": "/v3/", - "output": "json" + "url": "api.mailjet.com", + "version": "v3", + "output": "json", + "call": true, + "secured": "https" } diff --git a/mailjet-client.js b/mailjet-client.js index 75c35e5..2beab4d 100755 --- a/mailjet-client.js +++ b/mailjet-client.js @@ -23,7 +23,7 @@ * */ -const DEBUG_MODE = false +const DEBUG_MODE = true const RESOURCE = 0 const ID = 1 const ACTION = 2 @@ -44,7 +44,7 @@ const request = require('superagent') const Promise = require('bluebird') const _path = require('path') const JSONb = require('json-bigint')({ storeAsString: true }) -const version = require('./package.json').version +const version = "3.0.6" /* Extend superagent request with proxy method */ require('superagent-proxy')(request); @@ -60,7 +60,7 @@ require('superagent-proxy')(request); * https://www.mailjet.com/ */ function MailjetClient (api_key, api_secret, options, testMode) { - this.config = require('./config') + this.config = this.setConfig(options); this.testMode = testMode || false // To be updated according to the npm repo version this.version = version @@ -106,9 +106,24 @@ MailjetClient.prototype.connect = function (apiKey, apiSecret, options) { this.apiKey = apiKey this.apiSecret = apiSecret this.options = options || {} + if (options) { + this.config = this.setConfig(options); + } return this } +MailjetClient.prototype.setConfig = function (options) { + config = require('./config') + if (typeof options === 'object') { + if ('url' in options) config['url'] = options['url'] + if ('version' in options) config['version'] = options['version'] + if ('secured' in options && options['secured'] === "http") config['secured'] = "http" + if ('call' in options && options['call'] === false) config['call'] = false + } + + return config +}; + /* * path. * @@ -120,19 +135,24 @@ MailjetClient.prototype.connect = function (apiKey, apiSecret, options) { * @params {Object literal} {name: value} * */ -MailjetClient.prototype.path = function (resource, sub, params) { +MailjetClient.prototype.path = function (resource, sub, params, opts) { if (DEBUG_MODE) { console.log('resource =', resource) console.log('subPath =', sub) console.log('filters =', params) } - var base = _path.join(this.config.version, sub) + + is_object = typeof opts === 'object' ? true : false + url = (is_object && 'url' in opts ? opts['url'] : this.config.url) + api_version = (is_object && 'version' in opts ? opts['version'] : this.config.version) + + var base = _path.join(api_version, sub) if (Object.keys(params).length === 0) { - return base + '/' + resource + return _path.join(url, base + '/' + resource) } var q = qs.stringify(params).replace(/%2B/g, '+') - return base + '/' + resource + '/?' + q + return _path.join(url, base + '/' + resource + '/?' + q) } /* @@ -147,8 +167,7 @@ MailjetClient.prototype.path = function (resource, sub, params) { * and error on error */ -MailjetClient.prototype.httpRequest = function (method, url, data, callback) { - +MailjetClient.prototype.httpRequest = function (method, url, data, callback, call){ var req = request[method](url) .set('user-agent', 'mailjet-api-v3-nodejs/' + this.version) @@ -171,8 +190,8 @@ MailjetClient.prototype.httpRequest = function (method, url, data, callback) { console.log('Final url: ' + url) console.log('body: ' + payload) } - - if (this.testMode) { + + if (call === false || (this.testMode && typeof call !== "boolean")) { return [url, payload] } @@ -224,9 +243,10 @@ MailjetClient.prototype.httpRequest = function (method, url, data, callback) { * @func {String} resource/path to be sent * @context {MailjetClient[instance]} parent client */ -function MailjetResource (method, func, context) { +function MailjetResource (method, func, opts = {}, context) { this.base = func this.callUrl = func + this.opts = opts this.resource = func.toLowerCase() @@ -272,11 +292,14 @@ function MailjetResource (method, func, context) { } else { return {} } - })()) + })(), that.opts) + + secured = ('secured' in that.opts && that.opts['secured'] === "http" ? "http" : self.config.secured) + call = ('call' in that.opts && that.opts['call'] === false ? false : self.config.call) that.callUrl = that.base self.lastAdded = RESOURCE - return self.httpRequest(method, 'https://' + _path.join(self.config.url, path), params, callback) + return self.httpRequest(method, secured + '://' + path, params, callback, call) } } @@ -359,8 +382,8 @@ MailjetResource.prototype.request = function (params, callback) { * * @returns a function that make an httpRequest for each call */ -MailjetClient.prototype.post = function (func) { - return new MailjetResource('post', func, this) +MailjetClient.prototype.post = function (func, opts) { + return new MailjetResource('post', func, opts, this) } /* @@ -370,8 +393,8 @@ MailjetClient.prototype.post = function (func) { * * @returns a function that make an httpRequest for each call */ -MailjetClient.prototype.get = function (func) { - return new MailjetResource('get', func, this) +MailjetClient.prototype.get = function (func, opts) { + return new MailjetResource('get', func, opts, this) } /* @@ -381,8 +404,8 @@ MailjetClient.prototype.get = function (func) { * * @returns a function that make an httpRequest for each call */ -MailjetClient.prototype.delete = function (func) { - return new MailjetResource('delete', func, this) +MailjetClient.prototype.delete = function (func, opts) { + return new MailjetResource('delete', func, opts, this) } /* @@ -392,8 +415,8 @@ MailjetClient.prototype.delete = function (func) { * * @returns a function that make an httpRequest for each call */ -MailjetClient.prototype.put = function (func) { - return new MailjetResource('put', func, this) +MailjetClient.prototype.put = function (func, opts) { + return new MailjetResource('put', func, opts, this) } /* From 1fcd9a91b01fd846e1def67cfaade8cffef1909e Mon Sep 17 00:00:00 2001 From: Aridjar Date: Tue, 24 Jan 2017 11:25:18 +0100 Subject: [PATCH 02/11] working tests --- mailjet-client.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/mailjet-client.js b/mailjet-client.js index 2beab4d..3adcf2d 100755 --- a/mailjet-client.js +++ b/mailjet-client.js @@ -23,7 +23,7 @@ * */ -const DEBUG_MODE = true +const DEBUG_MODE = false const RESOURCE = 0 const ID = 1 const ACTION = 2 @@ -44,7 +44,7 @@ const request = require('superagent') const Promise = require('bluebird') const _path = require('path') const JSONb = require('json-bigint')({ storeAsString: true }) -const version = "3.0.6" +const version = require('./package.json').version /* Extend superagent request with proxy method */ require('superagent-proxy')(request); @@ -112,9 +112,9 @@ MailjetClient.prototype.connect = function (apiKey, apiSecret, options) { return this } -MailjetClient.prototype.setConfig = function (options) { +MailjetClient.prototype.setConfig = function (options = {}) { config = require('./config') - if (typeof options === 'object') { + if (typeof options === 'object' && options != null && options.length != 0) { if ('url' in options) config['url'] = options['url'] if ('version' in options) config['version'] = options['version'] if ('secured' in options && options['secured'] === "http") config['secured'] = "http" @@ -190,10 +190,13 @@ MailjetClient.prototype.httpRequest = function (method, url, data, callback, cal console.log('Final url: ' + url) console.log('body: ' + payload) } + console.log(typeof call) - if (call === false || (this.testMode && typeof call !== "boolean")) { + if (call === false || this.testMode) { return [url, payload] } + + console.log("failed !!") if (method === 'delete') { method = 'del' } if (method === 'post' || method === 'put') { req = req.send(data) } From 3edbab89c35a59730ee402b5f349288204fa181a Mon Sep 17 00:00:00 2001 From: Aridjar Date: Wed, 1 Feb 2017 14:37:56 +0100 Subject: [PATCH 03/11] add readme --- README.md | 33 ++++++++++++++++++++++++++++++++- config.json | 2 +- mailjet-client.js | 5 +---- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5cf2b22..4a1102e 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,7 @@ function newContact (email) { function testEmail (text) { email = {}; email['FromName'] = 'Your Name'; - email['FromEmail'] = 'Your Sender Adress'; + email['FromEmail'] = 'Your Sender Address'; email['Subject'] = 'Test Email'; email['Recipients'] = [{Email: 'Your email'}]; email['Text-Part'] = text; @@ -261,6 +261,37 @@ testEmail('Hello World!'); npm test ``` +## Use the version 3.1 of the send api + +``` javascript + +// The third argument (the object) is not mandatory, as each of its 4 keys. +const mailjet = require ('apiv3') + .connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE, { + 'url': 'api.mailjet.com', // default is the API url + 'version': 'v3', // default is '/v3' + 'secured': "https", // default is 'https' + 'call': true // used for tests. default is true + }) + +// the second argument (the object) is not mandatory, as each of its 4 keys +const request = mailjet + .post("send", { + 'url': 'api.mailjet.com', 'version': 'v3.1', 'secured': 'https', 'call': false + }) + .request({ + "Messages": [{ + "From":{"Email":"pilote@mailjet.com", "Name": "mailjet pilot"}, + "Subject":"Test from NodeJS wrapper", + "TextPart":"Dear passenger, welcome to Mailjet! May the delivery force be with you!", + "HTMLPart":"

Dear passenger, welcome to Mailjet!


May the delivery force be with you!", + "To":[{"Email":"passenger@mailjet.com"}] + }] + }) + + +``` + ## Contribute Mailjet loves developers. You can be part of this project! diff --git a/config.json b/config.json index beb4a2f..161a231 100755 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "url": "api.mailjet.com", - "version": "v3", + "version": "/v3/", "output": "json", "call": true, "secured": "https" diff --git a/mailjet-client.js b/mailjet-client.js index 3adcf2d..3891408 100755 --- a/mailjet-client.js +++ b/mailjet-client.js @@ -112,7 +112,7 @@ MailjetClient.prototype.connect = function (apiKey, apiSecret, options) { return this } -MailjetClient.prototype.setConfig = function (options = {}) { +MailjetClient.prototype.setConfig = function (options) { config = require('./config') if (typeof options === 'object' && options != null && options.length != 0) { if ('url' in options) config['url'] = options['url'] @@ -190,14 +190,11 @@ MailjetClient.prototype.httpRequest = function (method, url, data, callback, cal console.log('Final url: ' + url) console.log('body: ' + payload) } - console.log(typeof call) if (call === false || this.testMode) { return [url, payload] } - console.log("failed !!") - if (method === 'delete') { method = 'del' } if (method === 'post' || method === 'put') { req = req.send(data) } From 0100d1b0b8e33f0875afdd91929e4e1d7c505cf8 Mon Sep 17 00:00:00 2001 From: Aridjar Date: Wed, 15 Feb 2017 19:04:17 +0100 Subject: [PATCH 04/11] modification done, need to be tested --- README.md | 8 ++++---- config.json | 4 ++-- mailjet-client.js | 34 +++++++++++++++++----------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 4a1102e..aef5cc0 100644 --- a/README.md +++ b/README.md @@ -261,7 +261,7 @@ testEmail('Hello World!'); npm test ``` -## Use the version 3.1 of the send api +## Use the version 3.1 of the send API ``` javascript @@ -270,14 +270,14 @@ const mailjet = require ('apiv3') .connect(process.env.MJ_APIKEY_PUBLIC, process.env.MJ_APIKEY_PRIVATE, { 'url': 'api.mailjet.com', // default is the API url 'version': 'v3', // default is '/v3' - 'secured': "https", // default is 'https' - 'call': true // used for tests. default is true + 'secured': true, // default is a boolean true + 'perform_api_call': true // used for tests. default is true }) // the second argument (the object) is not mandatory, as each of its 4 keys const request = mailjet .post("send", { - 'url': 'api.mailjet.com', 'version': 'v3.1', 'secured': 'https', 'call': false + 'url': 'api.mailjet.com', 'version': 'v3.1', 'secured': 'https', 'perform_api_call': false }) .request({ "Messages": [{ diff --git a/config.json b/config.json index 161a231..e6be632 100755 --- a/config.json +++ b/config.json @@ -2,6 +2,6 @@ "url": "api.mailjet.com", "version": "/v3/", "output": "json", - "call": true, - "secured": "https" + "perform_api_call": true, + "secured": true } diff --git a/mailjet-client.js b/mailjet-client.js index 3891408..b6276ff 100755 --- a/mailjet-client.js +++ b/mailjet-client.js @@ -117,8 +117,8 @@ MailjetClient.prototype.setConfig = function (options) { if (typeof options === 'object' && options != null && options.length != 0) { if ('url' in options) config['url'] = options['url'] if ('version' in options) config['version'] = options['version'] - if ('secured' in options && options['secured'] === "http") config['secured'] = "http" - if ('call' in options && options['call'] === false) config['call'] = false + if ('secured' in options && options['secured'] === false) config['secured'] = false + if ('perform_api_call' in options && options['perform_api_call'] === false) config['perform_api_call'] = false } return config @@ -167,7 +167,7 @@ MailjetClient.prototype.path = function (resource, sub, params, opts) { * and error on error */ -MailjetClient.prototype.httpRequest = function (method, url, data, callback, call){ +MailjetClient.prototype.httpRequest = function (method, url, data, callback, perform_api_call){ var req = request[method](url) .set('user-agent', 'mailjet-api-v3-nodejs/' + this.version) @@ -191,7 +191,7 @@ MailjetClient.prototype.httpRequest = function (method, url, data, callback, cal console.log('body: ' + payload) } - if (call === false || this.testMode) { + if (perform_api_call === false || this.testMode) { return [url, payload] } @@ -243,10 +243,10 @@ MailjetClient.prototype.httpRequest = function (method, url, data, callback, cal * @func {String} resource/path to be sent * @context {MailjetClient[instance]} parent client */ -function MailjetResource (method, func, opts = {}, context) { +function MailjetResource (method, func, options = {}, context) { this.base = func this.callUrl = func - this.opts = opts + this.opts = options this.resource = func.toLowerCase() @@ -294,12 +294,12 @@ function MailjetResource (method, func, opts = {}, context) { } })(), that.opts) - secured = ('secured' in that.opts && that.opts['secured'] === "http" ? "http" : self.config.secured) - call = ('call' in that.opts && that.opts['call'] === false ? false : self.config.call) + secured = ('secured' in that.opts && that.opts['secured'] === true ? "https" : "http") + perform_api_call = ('perform_api_call' in that.opts && that.opts['perform_api_call'] === false ? false : self.config.perform_api_call) that.callUrl = that.base self.lastAdded = RESOURCE - return self.httpRequest(method, secured + '://' + path, params, callback, call) + return self.httpRequest(method, secured + '://' + path, params, callback, perform_api_call) } } @@ -382,8 +382,8 @@ MailjetResource.prototype.request = function (params, callback) { * * @returns a function that make an httpRequest for each call */ -MailjetClient.prototype.post = function (func, opts) { - return new MailjetResource('post', func, opts, this) +MailjetClient.prototype.post = function (func, options) { + return new MailjetResource('post', func, options, this) } /* @@ -393,8 +393,8 @@ MailjetClient.prototype.post = function (func, opts) { * * @returns a function that make an httpRequest for each call */ -MailjetClient.prototype.get = function (func, opts) { - return new MailjetResource('get', func, opts, this) +MailjetClient.prototype.get = function (func, options) { + return new MailjetResource('get', func, options, this) } /* @@ -404,8 +404,8 @@ MailjetClient.prototype.get = function (func, opts) { * * @returns a function that make an httpRequest for each call */ -MailjetClient.prototype.delete = function (func, opts) { - return new MailjetResource('delete', func, opts, this) +MailjetClient.prototype.delete = function (func, options) { + return new MailjetResource('delete', func, options, this) } /* @@ -415,8 +415,8 @@ MailjetClient.prototype.delete = function (func, opts) { * * @returns a function that make an httpRequest for each call */ -MailjetClient.prototype.put = function (func, opts) { - return new MailjetResource('put', func, opts, this) +MailjetClient.prototype.put = function (func, options) { + return new MailjetResource('put', func, options, this) } /* From 2d5b835581c0e72a27414193e460b8ba6aea4674 Mon Sep 17 00:00:00 2001 From: Aridjar Date: Mon, 20 Feb 2017 15:58:56 +0100 Subject: [PATCH 05/11] make test working, but v3.1 has some troubles --- config.json | 2 +- mailjet-client.js | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/config.json b/config.json index e6be632..6770767 100755 --- a/config.json +++ b/config.json @@ -1,6 +1,6 @@ { "url": "api.mailjet.com", - "version": "/v3/", + "version": "v3", "output": "json", "perform_api_call": true, "secured": true diff --git a/mailjet-client.js b/mailjet-client.js index b6276ff..657a39c 100755 --- a/mailjet-client.js +++ b/mailjet-client.js @@ -167,7 +167,7 @@ MailjetClient.prototype.path = function (resource, sub, params, opts) { * and error on error */ -MailjetClient.prototype.httpRequest = function (method, url, data, callback, perform_api_call){ +MailjetClient.prototype.httpRequest = function (method, url, data, callback, perform_api_call){ var req = request[method](url) .set('user-agent', 'mailjet-api-v3-nodejs/' + this.version) @@ -294,12 +294,21 @@ function MailjetResource (method, func, options = {}, context) { } })(), that.opts) - secured = ('secured' in that.opts && that.opts['secured'] === true ? "https" : "http") - perform_api_call = ('perform_api_call' in that.opts && that.opts['perform_api_call'] === false ? false : self.config.perform_api_call) + if (that.opts && that.opts.hasOwnProperty("secured")) { + secured = that.opts['secured']; + } else { + secured = self.config.secured; + } + + if (that.opts && that.opts.hasOwnProperty("perfom_api_call")) { + perform_api_call = that.opts['perform_api_call']; + } else { + perform_api_call = self.config.perform_api_call; + } that.callUrl = that.base self.lastAdded = RESOURCE - return self.httpRequest(method, secured + '://' + path, params, callback, perform_api_call) + return self.httpRequest(method, (secured ? 'https' : 'http') + '://' + path, params, callback, perform_api_call) } } From 48713cb455a08896e8450ca52991b4c2b2f56824 Mon Sep 17 00:00:00 2001 From: Aridjar Date: Mon, 20 Feb 2017 16:29:46 +0100 Subject: [PATCH 06/11] test with travis work --- mailjet-client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailjet-client.js b/mailjet-client.js index 657a39c..8578abb 100755 --- a/mailjet-client.js +++ b/mailjet-client.js @@ -243,7 +243,7 @@ MailjetClient.prototype.httpRequest = function (method, url, data, callback, per * @func {String} resource/path to be sent * @context {MailjetClient[instance]} parent client */ -function MailjetResource (method, func, options = {}, context) { +function MailjetResource (method, func, options, context) { this.base = func this.callUrl = func this.opts = options From 50866b56bd7ae668f8440324c0ec2aca4e3360ec Mon Sep 17 00:00:00 2001 From: Aridjar Date: Wed, 22 Feb 2017 11:58:41 +0100 Subject: [PATCH 07/11] asked modifications done --- mailjet-client.js | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/mailjet-client.js b/mailjet-client.js index 8578abb..ba56bdc 100755 --- a/mailjet-client.js +++ b/mailjet-client.js @@ -23,7 +23,7 @@ * */ -const DEBUG_MODE = false +const DEBUG_MODE = true const RESOURCE = 0 const ID = 1 const ACTION = 2 @@ -59,9 +59,9 @@ require('superagent-proxy')(request); * If you don't know what this is about, sign up to Mailjet at: * https://www.mailjet.com/ */ -function MailjetClient (api_key, api_secret, options, testMode) { +function MailjetClient (api_key, api_secret, options, perform_api_call) { this.config = this.setConfig(options); - this.testMode = testMode || false + this.perform_api_call = perform_api_call || false // To be updated according to the npm repo version this.version = version if (api_key && api_secret) { @@ -115,10 +115,12 @@ MailjetClient.prototype.connect = function (apiKey, apiSecret, options) { MailjetClient.prototype.setConfig = function (options) { config = require('./config') if (typeof options === 'object' && options != null && options.length != 0) { - if ('url' in options) config['url'] = options['url'] - if ('version' in options) config['version'] = options['version'] - if ('secured' in options && options['secured'] === false) config['secured'] = false - if ('perform_api_call' in options && options['perform_api_call'] === false) config['perform_api_call'] = false + if (options.url) config.url = options.url + if (options.version) config.version = options.version + if (options.secured) config.secured = options.secured + if (options.perform_api_call) config.perform_api_call = options.perform_api_call + } else if (options != undefined) { + throw "warning, your options variable is not a valid object." } return config @@ -135,16 +137,15 @@ MailjetClient.prototype.setConfig = function (options) { * @params {Object literal} {name: value} * */ -MailjetClient.prototype.path = function (resource, sub, params, opts) { +MailjetClient.prototype.path = function (resource, sub, params, options) { if (DEBUG_MODE) { console.log('resource =', resource) console.log('subPath =', sub) console.log('filters =', params) } - is_object = typeof opts === 'object' ? true : false - url = (is_object && 'url' in opts ? opts['url'] : this.config.url) - api_version = (is_object && 'version' in opts ? opts['version'] : this.config.version) + url = (options && 'url' in options ? options.url : this.config.url) + api_version = (options && 'version' in options ? options.version : this.config.version) var base = _path.join(api_version, sub) if (Object.keys(params).length === 0) { @@ -191,7 +192,7 @@ MailjetClient.prototype.httpRequest = function (method, url, data, callback, per console.log('body: ' + payload) } - if (perform_api_call === false || this.testMode) { + if (perform_api_call === false || this.perform_api_call) { return [url, payload] } @@ -246,7 +247,7 @@ MailjetClient.prototype.httpRequest = function (method, url, data, callback, per function MailjetResource (method, func, options, context) { this.base = func this.callUrl = func - this.opts = options + this.options = options this.resource = func.toLowerCase() @@ -283,25 +284,25 @@ function MailjetResource (method, func, options, context) { a filters property, we pass it to the url */ var path = self.path(that.callUrl, that.subPath, (function () { - if (params['filters']) { - var ret = params['filters'] - delete params['filters'] + if (params.filters) { + var ret = params.filters + delete params.filters return ret } else if (method === 'get') { return params } else { return {} } - })(), that.opts) - - if (that.opts && that.opts.hasOwnProperty("secured")) { - secured = that.opts['secured']; + })(), that.options) + + if (that.options && 'secured' in that.options) { + secured = that.options.secured; } else { secured = self.config.secured; } - if (that.opts && that.opts.hasOwnProperty("perfom_api_call")) { - perform_api_call = that.opts['perform_api_call']; + if (that.options && 'perform_api_call' in that.options) { + perform_api_call = that.options.perform_api_call; } else { perform_api_call = self.config.perform_api_call; } From 86fb59771b2505d6cbadc09890a472c5d2cef445 Mon Sep 17 00:00:00 2001 From: Emmanuel Boisgontier Date: Mon, 22 May 2017 16:02:32 +0300 Subject: [PATCH 08/11] turn off debug --- mailjet-client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailjet-client.js b/mailjet-client.js index ba56bdc..576e498 100755 --- a/mailjet-client.js +++ b/mailjet-client.js @@ -23,7 +23,7 @@ * */ -const DEBUG_MODE = true +const DEBUG_MODE = false const RESOURCE = 0 const ID = 1 const ACTION = 2 From a428da920dd36ea6baa985c7cc7090268d84ba18 Mon Sep 17 00:00:00 2001 From: Emmanuel Boisgontier Date: Mon, 22 May 2017 16:35:21 +0300 Subject: [PATCH 09/11] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0c779ae..3b9e0f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-mailjet", - "version": "3.0.6", + "version": "3.1.0", "description": "Mailjet NodeJS API client", "main": "index.js", "directories": { From ab21bbd8023476486dc58ca00ac2dc6ecbd43f2a Mon Sep 17 00:00:00 2001 From: Emmanuel Boisgontier Date: Mon, 22 May 2017 16:35:45 +0300 Subject: [PATCH 10/11] add v3.1 description --- README.md | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index aef5cc0..bde08f0 100644 --- a/README.md +++ b/README.md @@ -197,19 +197,19 @@ sendEmail ``` javascript var emailData = { - 'FromEmail': 'gbadi@student.42.fr', + 'FromEmail': 'pilot@mailjet.com', 'FromName': 'Guillaume badi', 'Subject': 'Coucou Mailjet2', 'Text-part': 'Hello World2', - 'Recipients': [{'Email': 'gbadi@mailjet.com'}], + 'Recipients': [{'Email': 'passenger@mailjet.com'}], }; var emailData2 = { - 'FromEmail': 'gbadi@student.42.fr', + 'FromEmail': 'pilot@mailjet.com', 'FromName': 'Guillaume badi', 'Subject': 'Coucou Mailjet2', 'Text-part': 'This is another Email', - 'Recipients': [{'Email': 'gbadi@mailjet.com'}], + 'Recipients': [{'Email': 'passenger@mailjet.com'}], }; sendEmail @@ -261,7 +261,18 @@ testEmail('Hello World!'); npm test ``` -## Use the version 3.1 of the send API +## New !! Version 3.1.0 of the Nodejs wrapper ! + +This version modifies the way to construct the Client or the calls. We add the possibility to add an array with parameters on both Client creation and API call (please, note that each of these parameters are preset and are not mandatory in the creation or the call) : + +Properties of the $settings (Client constructor) and $options (API call function) + +url (Default: api.mailjet.com) : domain name of the API +version (Default: v3) : API version (only working for Mailjet API V3 +) +perform_api_call (Default: true) : turns on(true) / off the call to the API +secured (Default: true) : turns on(true) / off the use of 'https' + + ``` javascript @@ -277,18 +288,14 @@ const mailjet = require ('apiv3') // the second argument (the object) is not mandatory, as each of its 4 keys const request = mailjet .post("send", { - 'url': 'api.mailjet.com', 'version': 'v3.1', 'secured': 'https', 'perform_api_call': false + 'url': 'api.mailjet.com', 'version': 'v3', 'secured': 'https', 'perform_api_call': false }) .request({ - "Messages": [{ - "From":{"Email":"pilote@mailjet.com", "Name": "mailjet pilot"}, - "Subject":"Test from NodeJS wrapper", - "TextPart":"Dear passenger, welcome to Mailjet! May the delivery force be with you!", - "HTMLPart":"

Dear passenger, welcome to Mailjet!


May the delivery force be with you!", - "To":[{"Email":"passenger@mailjet.com"}] - }] - }) - + 'FromEmail': 'pilot@mailjet.com', + 'FromName': 'Pilot', + 'Subject': 'Coucou Mailjet2', + 'Text-part': 'Hello World2', + 'Recipients': [{'Email': 'passenger@mailjet.com'}]}) ``` From 8e32ec18676866488a58676f656708eb96a30104 Mon Sep 17 00:00:00 2001 From: Emmanuel Boisgontier Date: Mon, 22 May 2017 16:37:02 +0300 Subject: [PATCH 11/11] clean emails --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bde08f0..5170857 100644 --- a/README.md +++ b/README.md @@ -198,7 +198,7 @@ sendEmail var emailData = { 'FromEmail': 'pilot@mailjet.com', - 'FromName': 'Guillaume badi', + 'FromName': 'Pilot', 'Subject': 'Coucou Mailjet2', 'Text-part': 'Hello World2', 'Recipients': [{'Email': 'passenger@mailjet.com'}], @@ -206,7 +206,7 @@ var emailData = { var emailData2 = { 'FromEmail': 'pilot@mailjet.com', - 'FromName': 'Guillaume badi', + 'FromName': 'Pilot', 'Subject': 'Coucou Mailjet2', 'Text-part': 'This is another Email', 'Recipients': [{'Email': 'passenger@mailjet.com'}],