forked from kaiwood/pnut-butter
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Kai Wood
committed
Jul 1, 2017
1 parent
f83f24e
commit 6418f42
Showing
4 changed files
with
113 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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Changelog | ||
|
||
## 0.10.0 | ||
|
||
- Stream marker support | ||
|
||
## 0.9.0 | ||
|
||
- Add "Missed Conversations" stream | ||
|
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,55 @@ | ||
"use strict"; | ||
|
||
/** | ||
* Stream markers | ||
* @module stream_markers | ||
*/ | ||
module.exports = api => { | ||
return { | ||
/** | ||
* Set a single stream marker. | ||
* | ||
* Valid values for the "name" argument are: | ||
* - global | ||
* - personal | ||
* - mentions | ||
* - channel:id | ||
* @example | ||
* pnut.marker("channel:18", 15100).then(res => { | ||
* console.log(res); | ||
* }); | ||
* @param {string} name - Name of the markable stream | ||
* @param {string|number} id - ID of the post / message | ||
* @returns {Promise} | ||
*/ | ||
marker(name, id) { | ||
return api.request(`/markers`, { | ||
httpMethod: "POST", | ||
data: [ | ||
{ | ||
name: name, | ||
id: id | ||
} | ||
] | ||
}); | ||
}, | ||
|
||
/** | ||
* Set up to 10 markers at once, like described in the pnut docs. | ||
* | ||
* @example | ||
* pnut.markers([ | ||
* { name: "channel:18", id: 15100 }, | ||
* { name: "channel:19", id: 15101 } | ||
* ]).then(res => console.log(res)); | ||
* @param {array} markerObjects - An array of marker objects | ||
* @returns {Promise} | ||
*/ | ||
markers(markerObjects = []) { | ||
return api.request(`/markers`, { | ||
httpMethod: "POST", | ||
data: markerObjects | ||
}); | ||
} | ||
}; | ||
}; |
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,52 @@ | ||
const chai = require("chai"); | ||
const chaiAsPromised = require("chai-as-promised"); | ||
const nock = require("nock"); | ||
chai.use(chaiAsPromised); | ||
chai.should(); | ||
|
||
const pnut = require("../lib/pnut"); | ||
|
||
before(function() { | ||
let base = "https://api.pnut.io/v0"; | ||
|
||
nock(base) | ||
.post("/markers", [ | ||
{ | ||
name: "channel:18", | ||
id: 15100 | ||
} | ||
]) | ||
.reply(200, {}); | ||
|
||
nock(base) | ||
.post("/markers", [ | ||
{ | ||
name: "channel:18", | ||
id: 15100 | ||
}, | ||
{ | ||
name: "channel:19", | ||
id: 15101 | ||
} | ||
]) | ||
.reply(200, {}); | ||
}); | ||
|
||
after(function() { | ||
nock.cleanAll(); | ||
}); | ||
|
||
describe("Stream markers", () => { | ||
it("should be able to update a single stream marker", () => { | ||
return pnut.marker("channel:18", 15100).should.become({}); | ||
}); | ||
|
||
it("should be able to update a multiple stream markers", () => { | ||
return pnut | ||
.markers([ | ||
{ name: "channel:18", id: 15100 }, | ||
{ name: "channel:19", id: 15101 } | ||
]) | ||
.should.become({}); | ||
}); | ||
}); |