Skip to content

Commit

Permalink
use jsonString
Browse files Browse the repository at this point in the history
  • Loading branch information
motdotla committed Dec 30, 2013
1 parent 9f8a81b commit f5ac354
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -11,7 +11,7 @@ var header = smtpapi.Header();
header.addTo('you@youremail.com');
header.setUniqueArgs({cow: 'chicken'});

var smtpapi_header_string = header.toJsonString();
var smtpapi_header_string = header.jsonString();
```

See [this](http://sendgrid.com/docs/API_Reference/SMTP_API/) for more information on the available X-SMTPAPI custom handling instructions.
Expand Down Expand Up @@ -47,14 +47,14 @@ var smtpapi = require('smtpapi');
var header = new smtpapi.Header();
```

### toJsonString
### jsonString

This gives you back the stringified json formatted X-SMTPAPI header. Use this with your [smtp client](https://github.com/andris9/simplesmtp) of choice.

```javascript
var smtpapi = require('smtpapi');
var header = new smtpapi.Header();
header.toJsonString();
header.jsonString();
```

### addTo
Expand Down Expand Up @@ -172,7 +172,7 @@ header.addTo('you@youremail.com');
header.setUniqueArgs({cow: 'chicken'});

// Add the smtpapi header to the general headers
var headers = { 'x-smtpapi': header.toJsonString() };
var headers = { 'x-smtpapi': header.jsonString() };

// Use nodemailer to send the email
var settings = {
Expand Down
6 changes: 3 additions & 3 deletions lib/main.js
Expand Up @@ -20,8 +20,8 @@ Header.prototype.addTo = function(to) {
}
};

Header.prototype.setTos = function(to) {
this.to = to;
Header.prototype.setTos = function(tos) {
this.to = tos;
};

Header.prototype.addSubstitution = function(key, val) {
Expand Down Expand Up @@ -104,7 +104,7 @@ Header.prototype.toJson = function() {
return data;
};

Header.prototype.toJsonString = function() {
Header.prototype.jsonString = function() {
var json = JSON.stringify(this.toJson());

return json;
Expand Down
24 changes: 12 additions & 12 deletions test/main.js
Expand Up @@ -14,69 +14,69 @@ describe('smtapi', function() {
});

describe('.Header', function() {
it('has a toJsonString method', function() {
it('has a jsonString method', function() {
var header = new smtpapi.Header();

header.toJsonString().should.eql('{}');
header.jsonString().should.eql('{}');
});

it('addTo', function() {
var header = new smtpapi.Header();

header.addTo('addTo@mailinator.com');
header.toJsonString().should.eql('{"to":["addTo@mailinator.com"]}');
header.jsonString().should.eql('{"to":["addTo@mailinator.com"]}');
});

it('addSubstitution', function() {
var header = new smtpapi.Header();

header.addSubstitution('sub', 'val');
header.toJsonString().should.eql('{"sub":{"sub":["val"]}}');
header.jsonString().should.eql('{"sub":{"sub":["val"]}}');
});

it('setUniqueArgs', function() {
var header = new smtpapi.Header();

header.setUniqueArgs({set_unique_argument_key: 'set_unique_argument_value'});
header.toJsonString().should.eql('{"unique_args":{"set_unique_argument_key":"set_unique_argument_value"}}');
header.jsonString().should.eql('{"unique_args":{"set_unique_argument_key":"set_unique_argument_value"}}');
});

it('addUniqueArg', function() {
var header = new smtpapi.Header();

header.addUniqueArg({add_unique_argument_key: 'add_unique_argument_value'});
header.addUniqueArg({add_unique_argument_key_2: 'add_unique_argument_value_2'});
header.toJsonString().should.eql('{"unique_args":{"add_unique_argument_key":"add_unique_argument_value","add_unique_argument_key_2":"add_unique_argument_value_2"}}');
header.jsonString().should.eql('{"unique_args":{"add_unique_argument_key":"add_unique_argument_value","add_unique_argument_key_2":"add_unique_argument_value_2"}}');
});

it('setCategories', function() {
var header = new smtpapi.Header();

header.setCategories(['setCategory']);
header.toJsonString().should.eql('{"category":["setCategory"]}');
header.jsonString().should.eql('{"category":["setCategory"]}');
});

it('addCategory', function() {
var header = new smtpapi.Header();

header.addCategory('addCategory');
header.addCategory('addCategory2');
header.toJsonString().should.eql('{"category":["addCategory","addCategory2"]}');
header.jsonString().should.eql('{"category":["addCategory","addCategory2"]}');
});

it('setSections', function() {
var header = new smtpapi.Header();

header.setSections({'set_section_key': 'set_section_value'});
header.toJsonString().should.eql('{"section":{"set_section_key":"set_section_value"}}');
header.jsonString().should.eql('{"section":{"set_section_key":"set_section_value"}}');
});

it('addSection', function() {
var header = new smtpapi.Header();

header.addSection({'set_section_key': 'set_section_value'});
header.addSection({'set_section_key_2': 'set_section_value_2'});
header.toJsonString().should.eql('{"section":{"set_section_key":"set_section_value","set_section_key_2":"set_section_value_2"}}');
header.jsonString().should.eql('{"section":{"set_section_key":"set_section_value","set_section_key_2":"set_section_value_2"}}');
});

it('setFilters', function() {
Expand All @@ -92,14 +92,14 @@ describe('smtapi', function() {
}

header.setFilters(filter);
header.toJsonString().should.eql('{"filters":{"footer":{"setting":{"enable":1,"text/plain":"You can haz footers!"}}}}');
header.jsonString().should.eql('{"filters":{"footer":{"setting":{"enable":1,"text/plain":"You can haz footers!"}}}}');
});

it('addFilter', function() {
var header = new smtpapi.Header();

header.addFilter('footer', 'text/html', '<strong>boo</strong>');
header.toJsonString().should.eql('{"filters":{"footer":{"settings":{"text/html":"<strong>boo</strong>"}}}}');
header.jsonString().should.eql('{"filters":{"footer":{"settings":{"text/html":"<strong>boo</strong>"}}}}');
});

});
Expand Down

0 comments on commit f5ac354

Please sign in to comment.