Skip to content

Commit

Permalink
Add stream marker support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai Wood committed Jul 1, 2017
1 parent f83f24e commit 6418f42
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
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
Expand Down
2 changes: 2 additions & 0 deletions lib/pnut.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const users = require("./users");
const posts = require("./posts");
const explore = require("./explore");
const channels = require("./channels");
const streamMarkers = require("./stream_markers");
const messages = require("./messages");
const system = require("./system");
const appStreams = require("./app_streams");
Expand Down Expand Up @@ -120,6 +121,7 @@ const pnut = () => {
posts(api),
explore(api),
channels(api),
streamMarkers(api),
messages(api),
system(api),
appStreams(api)
Expand Down
55 changes: 55 additions & 0 deletions lib/stream_markers.js
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
});
}
};
};
52 changes: 52 additions & 0 deletions test/stream_markers_test.js
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({});
});
});

0 comments on commit 6418f42

Please sign in to comment.