Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Guillaume Badi
authored and
Guillaume Badi
committed
Aug 19, 2015
0 parents
commit e21ba68
Showing
863 changed files
with
141,004 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
|
||
|
||
![alt text](http://cdn.appstorm.net/web.appstorm.net/files/2012/02/mailjet_logo_200x200.png "Mailjet") | ||
|
||
# Mailjet NodeJs Wrapper | ||
for more information about Mailjet, visit http://www.mailjet.com/ | ||
|
||
This is the NodeJs wrapper form Mailjet, it's MIT licenced. | ||
|
||
## Getting Started ! | ||
|
||
``` javascript | ||
|
||
// test.js | ||
// to run this example add your API key and Secret to your env | ||
// and run 'node test.js' | ||
|
||
var env = process.env | ||
, Mailjet = require ('./mailjet-client') | ||
.connect(env.MAILJET_API_KEY, env.MAILJET_API_SECRET); | ||
|
||
// you can store ressources | ||
var contact = Mailjet.get('contact'); | ||
var sender = Mailjet.post('sender'); | ||
var user = Mailjet.get('user'); | ||
var sendMessage = Mailjet.post('send'); | ||
|
||
// and call them easily | ||
contact.request({Limit: 2}, function (error, response, body) { | ||
console.log (error || body) | ||
}); | ||
|
||
// you can specify an id | ||
contact.id(3).request(function (error, response, body) { | ||
console.log (error || body); | ||
}); | ||
|
||
// you can add an action to it | ||
contact.id(3).action('managemanycontacts').id(3) | ||
.request(function (error, response, body) { | ||
console.log (error || body); | ||
}); | ||
|
||
// if you don't like callbacks | ||
contact.id(2).request() | ||
.on('success', function (response, body) { | ||
console.log (body); | ||
}) | ||
.on('error', function (error, response) { | ||
console.log ("you shiouldn't get here anyway"); | ||
}); | ||
|
||
user.request().on('success', function (response, body) { | ||
console.log (response.statusCode); | ||
}); | ||
|
||
// Send an Email | ||
sendMessage.request({ | ||
'FromEmail': 'stan@smith.com', | ||
'FromName': 'Stan Smith', | ||
'Subject': 'Test nodejs mailjet wrapper', | ||
'Text-part': 'Hello NodeJs!', | ||
'Recipients': [{'Email': 'roger@smith.com'}], | ||
}).on('success', function (response, body) { | ||
console.log (body); | ||
}) | ||
.on('error', function (e) { | ||
console.log (e); | ||
}); | ||
|
||
``` | ||
|
||
## TODO | ||
- Add the documentation in test.js | ||
- Implement a couple more examples | ||
- Add tests relative to the action chaining | ||
- Implement a small external project featuring the Wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"url": "api.mailjet.com", | ||
"version": "/v3/", | ||
"output": "json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
// to run this example add your API key and Secret to your env | ||
|
||
var env = process.env; | ||
var Mailjet = require ('./mailjet-client') | ||
.connect(env.MAILJET_API_KEY, env.MAILJET_API_SECRET); | ||
|
||
var getContact = Mailjet.get('contact'); | ||
var postContact = Mailjet.post('contact'); | ||
var getContact2 = Mailjet.get('contact/2'); | ||
var myProfile = Mailjet.get('myprofile'); | ||
var sendMessage = Mailjet.post('send'); | ||
var sender = Mailjet.post('sender'); | ||
|
||
sender.request({Email: 'gbadi@student.42.fr'}) | ||
.on('sucess', function (response, body) { | ||
console.log (body); | ||
}); | ||
|
||
// Send an Email | ||
sendMessage.request({ | ||
'FromEmail': 'stan@smith.com', | ||
'FromName': 'Stan Smith', | ||
'Subject': 'Test nodejs mailjet wrapper', | ||
'Text-part': 'Hello NodeJs!', | ||
'Recipients': [{'Email': 'roger@smith.com'}], | ||
}).on('success', function (response, body) { | ||
console.log (body); | ||
}); | ||
|
||
postContact.request({Name: 'Mister Mailjet', Email: 'misters@mailjet.com'}, function (err, response, body) { | ||
console.log (Mailjet.formatJSON(err || body)); | ||
}); | ||
|
||
getContact2.request(function (err, response, body) { | ||
console.log (err || body); | ||
}); | ||
|
||
myProfile.request(function (err, response, body) { | ||
console.log (err || body); | ||
}); | ||
|
||
getContact.id(3).request() | ||
.on('success', function (response, body) { | ||
console.log (Mailjet.formatJSON(body)); | ||
}); | ||
|
Oops, something went wrong.