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
1 parent
5f501c5
commit 9b7bcda
Showing
5 changed files
with
175 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
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,63 @@ | ||
import PushBullet from '../pushbullet.js'; | ||
|
||
/** | ||
* Create a new text. | ||
* | ||
* See https://docs.pushbullet.com/#text for additional options that can be set. | ||
* | ||
* @param {String} deviceIden Device IDEN of the device which can send SMS messages. | ||
* @param {Array} addresses String or array of strings of recipient phone numbers. | ||
* @param {String} message Message text to be sent. | ||
* @param {Object} textOptions Additional text options. | ||
* @returns {Promise} | ||
*/ | ||
PushBullet.prototype.createText = async function createText(deviceIden, addresses, message, textOptions) { | ||
const options = { | ||
data : { | ||
target_device_iden : deviceIden, | ||
addresses : Array.isArray(addresses) ? addresses : [ addresses ], | ||
message : message | ||
} | ||
}; | ||
|
||
if (textOptions.guid) { | ||
options.data.guid = textOptions.guid; | ||
} | ||
if (textOptions.status) { | ||
options.data.status = textOptions.status; | ||
} | ||
if (textOptions.file_type) { | ||
options.data.file_type = textOptions.file_type; | ||
} | ||
if (textOptions.file_url) { | ||
options.file_url = textOptions.file_url; | ||
} | ||
if (textOptions.skip_file_delete) { | ||
options.skip_file_delete = textOptions.skip_file_delete; | ||
} | ||
|
||
return this.makeRequest('post', PushBullet.TEXTS_END_POINT, { json : options }); | ||
}; | ||
|
||
/** | ||
* Update text. | ||
* | ||
* See https://docs.pushbullet.com/#text for valid attributes. | ||
* | ||
* @param {String} textIden The iden of the text to update. | ||
* @param {Object} textOptions Text attributes to apply updates to. | ||
* @returns {Promise} | ||
*/ | ||
PushBullet.prototype.updateText = async function updateText(textIden, textOptions) { | ||
return this.makeRequest('post', PushBullet.TEXTS_END_POINT + '/' + textIden, { json : textOptions }); | ||
}; | ||
|
||
/** | ||
* Delete a text. | ||
* | ||
* @param {String} textIden The iden of the text to update. | ||
* @returns {Promise} | ||
*/ | ||
PushBullet.prototype.deleteText = async function deleteText(textIden) { | ||
return this.makeRequest('delete', PushBullet.TEXTS_END_POINT + '/' + textIden, {}); | ||
}; |
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,75 @@ | ||
/* global describe,it */ | ||
|
||
import nock from 'nock'; | ||
import PushBullet from '../lib/pushbullet.js'; | ||
import { should } from 'chai'; | ||
should(); | ||
|
||
const accessToken = 'test-access-token'; | ||
const requestHeaders = { | ||
'Access-Token' : accessToken | ||
}; | ||
|
||
describe('PushBullet.createText()', () => { | ||
it('should create a text', async () => { | ||
nock(PushBullet.API_BASE, { reqheaders : requestHeaders }) | ||
.post('/texts', { | ||
data : { | ||
target_device_iden : 'device-iden', | ||
addresses : [ '123-456-789' ], | ||
message : 'text-message', | ||
file_type : 'type-of-file' | ||
}, | ||
file_url : 'url-to-file' | ||
}) | ||
.reply(200, {}); | ||
|
||
const pb = new PushBullet(accessToken); | ||
const response = await pb.createText('device-iden', '123-456-789', 'text-message', { | ||
file_url : 'url-to-file', | ||
file_type : 'type-of-file' | ||
}); | ||
response.status.should.equal(200); | ||
|
||
const j = await response.json(); | ||
j.should.be.an.an('object'); | ||
}); | ||
}); | ||
|
||
describe('PushBullet.updateText()', () => { | ||
it('should update a text', async () => { | ||
nock(PushBullet.API_BASE, { reqheaders : requestHeaders }) | ||
.post('/texts/text-iden', { | ||
data : { | ||
message : 'updated-message' | ||
} | ||
}) | ||
.reply(200, {}); | ||
|
||
const pb = new PushBullet(accessToken); | ||
const response = await pb.updateText('text-iden', { | ||
data : { | ||
message : 'updated-message' | ||
} | ||
}); | ||
response.status.should.equal(200); | ||
|
||
const j = await response.json(); | ||
j.should.be.an.an('object'); | ||
}); | ||
}); | ||
|
||
describe('PushBullet.deleteText()', () => { | ||
it('should delete a chat', async () => { | ||
nock(PushBullet.API_BASE, { reqheaders : requestHeaders }) | ||
.delete('/texts/text-iden') | ||
.reply(200, {}); | ||
|
||
const pb = new PushBullet(accessToken); | ||
const response = await pb.deleteText('text-iden'); | ||
response.status.should.equal(200); | ||
|
||
const j = await response.json(); | ||
j.should.be.an.an('object'); | ||
}); | ||
}); |