Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Badi authored and Guillaume Badi committed Aug 19, 2015
0 parents commit e21ba68
Show file tree
Hide file tree
Showing 863 changed files with 141,004 additions and 0 deletions.
77 changes: 77 additions & 0 deletions README.md
@@ -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
5 changes: 5 additions & 0 deletions config.json
@@ -0,0 +1,5 @@
{
"url": "api.mailjet.com",
"version": "/v3/",
"output": "json"
}
47 changes: 47 additions & 0 deletions example.js
@@ -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));
});

0 comments on commit e21ba68

Please sign in to comment.