-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added template endpoints * updated NPM version Co-authored-by: Julie Lin <[email protected]>
- Loading branch information
Shariq Torres
and
Julie Lin
authored
Jan 4, 2022
1 parent
a010609
commit f32413a
Showing
7 changed files
with
154 additions
and
2 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
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
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,40 @@ | ||
'use strict'; | ||
|
||
/* | ||
* This script shows how to save an HTML template for later use | ||
* as a postcard. | ||
*/ | ||
|
||
const fs = require('fs'); | ||
const lobFactory = require('../lib/index'); | ||
const Lob = new lobFactory('<YOUR_API_KEY>'); | ||
const file = fs.readFileSync(`${__dirname}/html/card.html`).toString(); | ||
const ADDRESS = { | ||
name: 'Robin Joseph', | ||
email: '[email protected]', | ||
phone: '123456789', | ||
address_line1: '123 Test Street', | ||
address_line2: 'Unit 199', | ||
address_city: 'Chicago', | ||
address_state: 'IL', | ||
address_zip: '60012', | ||
address_country: 'US' | ||
} | ||
Lob.templates.create({html: file, description: 'TestTemplate'}) | ||
.then((template) => { | ||
Lob.addresses.create(ADDRESS).then((address) => { | ||
Lob.postcards.create({ | ||
description: 'Template-backed Postcard', | ||
to: address.id, | ||
front: template.id, | ||
back: template.id, | ||
merge_variables: { | ||
name: 'Robin' | ||
} | ||
}).then((postcard) => { | ||
console.log("The LOB API responded with the following postcard object", postcard) | ||
}); | ||
}); | ||
}).catch((err) => { | ||
console.log(err) | ||
}); |
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
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,32 @@ | ||
'use strict'; | ||
|
||
const ResourceBase = require('./resourceBase'); | ||
|
||
class Template extends ResourceBase { | ||
constructor (config) { | ||
super('templates', config); | ||
} | ||
|
||
list (options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
|
||
return this._transmit('GET', null, options, null, callback); | ||
} | ||
|
||
create (options, callback) { | ||
return this._transmit('POST', null, null, options, callback); | ||
} | ||
|
||
retrieve (id, callback) { | ||
return this._transmit('GET', id, null, null, callback); | ||
} | ||
|
||
delete (id, callback) { | ||
return this._transmit('DELETE', id, null, null, callback); | ||
} | ||
} | ||
|
||
module.exports = Template; |
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
"Lob.com", | ||
"printing" | ||
], | ||
"version": "6.5.2", | ||
"version": "6.5.3", | ||
"homepage": "https://github.com/lob/lob-node", | ||
"author": "Lob <[email protected]> (https://lob.com/)", | ||
"dependencies": { | ||
|
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,68 @@ | ||
'use strict'; | ||
|
||
const { expect } = require("chai"); | ||
|
||
const EXAMPLE_TEMPLATE = { | ||
html: "<html><body><h1>Hello World</h1></body></html>", | ||
description: "My New Template" | ||
} | ||
describe('templates', () => { | ||
|
||
describe('list', () => { | ||
it('returns a list of saved templates', (done) => { | ||
Lob.templates.list((err, res) => { | ||
expect(res.object).to.eql('list'); | ||
expect(res.data).to.be.instanceof(Array); | ||
expect(res.data.length).to.be.at.most(10); | ||
expect(res.count).to.be.at.most(10); | ||
return done(); | ||
}); | ||
}); | ||
|
||
it('filters templates', (done) => { | ||
Lob.templates.list({limit: 1}, (err, res) => { | ||
expect(res.data).to.be.instanceof(Array); | ||
expect(res.data.length).to.eql(1); | ||
expect(res.count).to.eql(1); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('create', () => { | ||
it('creates a new template', (done) => { | ||
Lob.templates.create(EXAMPLE_TEMPLATE, (err, res) => { | ||
expect(res.object).to.eql('template'); | ||
expect(res.description).to.eql(EXAMPLE_TEMPLATE.description); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('retrieve', () => { | ||
it('retrieves a template', (done) => { | ||
Lob.templates.create(EXAMPLE_TEMPLATE, (err, res) => { | ||
Lob.templates.retrieve(res.id, (err, res2) => { | ||
expect(res2.description).to.eql(EXAMPLE_TEMPLATE.description); | ||
expect(res2.id).to.eql(res.id); | ||
expect(res2.object).to.eql('template'); | ||
expect(res2.published_version).to.be.instanceof(Object); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('delete', () => { | ||
it('deletes a template', (done) => { | ||
Lob.templates.create(EXAMPLE_TEMPLATE, (err, res) => { | ||
Lob.templates.delete(res.id, (err, res2) => { | ||
expect(res2.deleted).to.eql(true); | ||
expect(res2.id).to.eql(res.id); | ||
return done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
}); |