diff --git a/api/v1.0.0/topics.js b/api/v1.0.0/topics.js new file mode 100644 index 0000000..b7b0360 --- /dev/null +++ b/api/v1.0.0/topics.js @@ -0,0 +1,18 @@ +var request = require('request'); +/** @namespace */ +var topics = {}; + +module.exports = function (client) { + /** + * @summary List of all topics + * @memberof topics + * @param {done} done - Callback + * + * @see https://api.producthunt.com/v1/docs/topics/topics_index_list_topics + */ + topics.index = function (done) { + client.httpGet('/topics', {}, done); + }; + + return topics; +}; diff --git a/index.js b/index.js index c2ba413..9414eb7 100644 --- a/index.js +++ b/index.js @@ -34,6 +34,7 @@ Client.prototype.setupAPI = function () { this.currentUser = require(`./api/v${this.version}/current_user`)(this); this.categories = require(`./api/v${this.version}/categories`)(this); this.live = require(`./api/v${this.version}/live`)(this); + this.topics = require(`./api/v${this.version}/topics`)(this); }; Client.prototype.getEndpoint = function(path) { diff --git a/test/v1.0.0/topics_test.js b/test/v1.0.0/topics_test.js new file mode 100644 index 0000000..e274037 --- /dev/null +++ b/test/v1.0.0/topics_test.js @@ -0,0 +1,35 @@ +var expect = require('chai').expect; +var nock = require('nock'); +var sinon = require('sinon'); + +var Client = require('../../index'); +var c = new Client(); +var topics = require('../../api/v1.0.0/topics')(c); + +describe("topics", function() { + beforeEach(function() { + // Stub authenticate to be always successful + sinon.stub(Client.prototype, 'authenticate', function (done) { + done(null, 'test_access_token'); + }); + }); + + afterEach(function() { + // Remove the stub + Client.prototype.authenticate.restore(); + }); + + describe("#index", function() { + it("is successful", function(done) { + nock('https://api.producthunt.com/v1') + .get('/topics') + .reply(200); + + topics.index(function (err, res) { + expect(err).to.equal(null); + expect(res.statusCode).to.equal(200); + done(); + }); + }); + }); +});