From dd9da008a2515fd0f385f7e691512ac7b7fdfab2 Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 08:35:10 +0200 Subject: [PATCH 01/19] Update Gab.js Added post and feed API calls for Gab. --- lib/Gab.js | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/lib/Gab.js b/lib/Gab.js index e1c4555..9d4c249 100644 --- a/lib/Gab.js +++ b/lib/Gab.js @@ -2,22 +2,47 @@ var rp = require('request-promise'); function Gab(options) { this.options = options; - this._baseRequest = rp.defaults({ baseUrl: 'https://gab.ai/', followRedirect: false, headers: { authorization: 'Bearer ' + this.options.authToken }, - transform2xxOnly: true, - transform: function(content) { return JSON.parse(content) } - }) -} + json: true + }); +}; Gab.prototype.getUser = function (username) { return this._baseRequest('/users/' + username); }; +Gab.prototype.getFeed = function () { + return this._baseRequest('/feed/'); +}; + +Gab.prototype.post = function(message, reply_to = "") { + return this._baseRequest({ + method: 'POST', + uri: '/posts/', + body: { + body: "
"+message+"
", + reply_to: reply_to, + is_quote: "0", + is_html: "1", + nsfw: "0", + is_premium: "0", + _method: "post", + gif: "", + category: null, + topic: null, + share_facebook: null, + share_twitter: null, + media_attachments: [] + }, + json: true + }); +}; + if (!(typeof exports === 'undefined')) { exports.Gab = Gab; } From 074100269cea80857239b36b478e3442f0a93284 Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 08:52:29 +0200 Subject: [PATCH 02/19] Update Gab.js Changed initialization of Gab class to being a simple string, the auth token. --- lib/Gab.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Gab.js b/lib/Gab.js index 9d4c249..5b25260 100644 --- a/lib/Gab.js +++ b/lib/Gab.js @@ -1,12 +1,11 @@ var rp = require('request-promise'); -function Gab(options) { - this.options = options; +function Gab(token) { this._baseRequest = rp.defaults({ baseUrl: 'https://gab.ai/', followRedirect: false, headers: { - authorization: 'Bearer ' + this.options.authToken + authorization: 'Bearer ' + token }, json: true }); From 9d17e41c24c58934183ba6fd3db47ad9d38291f5 Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 08:58:38 +0200 Subject: [PATCH 03/19] Update README.md --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6a43fd4..959dff7 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,7 @@ # gab.ai A wrapper for the gab.ai API - -| Service | Status | -| --- | --- | -| CircleCI | [](https://circleci.com/gh/lyndsysimon/gab) | - -If you find this project useful: [](https://saythanks.io/to/lyndsysimon) +This is a fork from https://saythanks.io/to/lyndsysimon. Please thank him. ## Usage @@ -15,9 +10,7 @@ The API is exposed as a single `Gab` object, which must be initialized with an a ```javascript var Gab = require('gab.ai').Gab; -var api = new Gab({ - authToken: '"+message+"
", - reply_to: reply_to, - is_quote: "0", - is_html: "1", - nsfw: "0", - is_premium: "0", - _method: "post", - gif: "", - category: null, - topic: null, - share_facebook: null, - share_twitter: null, - media_attachments: [] - }, - json: true + body: body }); }; From 865390738701a0a0d346ad436ec1425b477aaa54 Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 17:56:22 +0200 Subject: [PATCH 06/19] Update Gab.js Added API for retrieving an individual post. --- lib/Gab.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Gab.js b/lib/Gab.js index 8cf7194..05ad9c7 100644 --- a/lib/Gab.js +++ b/lib/Gab.js @@ -19,7 +19,11 @@ Gab.prototype.getFeed = function () { return this._baseRequest('/feed/'); }; -Gab.prototype.post = function(options) { +Gab.prototype.getPost = function (postid) { + return this._baseRequest('/posts/' + postid); +}; + +Gab.prototype.putPost = function(options) { let body = { body: "", reply_to: "", @@ -44,5 +48,5 @@ Gab.prototype.post = function(options) { }; if (!(typeof exports === 'undefined')) { - exports.Gab = Gab; + exports.Gab = Gab; } From 3e3500a856da1e26a452845142802fd345ee9af8 Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 18:00:02 +0200 Subject: [PATCH 07/19] Update README.md Updated usage examples. --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d7bd01c..765398b 100644 --- a/README.md +++ b/README.md @@ -17,13 +17,29 @@ var api = new Gab('This is the message of the post
", gif: '3PrOqZRpbmqFa'}) + .then(function(data) { + console.log(data); + }).catch(function() { + console.log('Request failed.'); + }); + +// Get information about a post. +api.getPost('23916771') + .then(function(data) { + console.log(data); + }).catch(function() { + console.log('Request failed.'); + }); ``` For information on Promise objects, see the [documentation for request-promise](https://github.com/request/request-promise). From 6fd6e6aa2b5277a17de167add97a6541d6e112f3 Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 18:12:59 +0200 Subject: [PATCH 08/19] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 765398b..7f29067 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,8 @@ This is a fork from https://saythanks.io/to/lyndsysimon. Please thank him. ## Usage -The API is exposed as a single `Gab` object, which must be initialized with an authorized JWT. +The API is exposed as a single `Gab` object, which must be initialized with an authorized JWT. This is a token that is set as "HttpOnly", so it's generally not visible and queryable through JavaScript. You can display that token either with an extension to display cookies or retrieve it from the requests as they are logged by your browser's debugging tools. + ```javascript var Gab = require('gab.ai').Gab; From 79caafe7a53b84122965c9cab49fb49eff376f41 Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 18:13:48 +0200 Subject: [PATCH 09/19] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 7f29067..bcb180f 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,11 @@ This is a fork from https://saythanks.io/to/lyndsysimon. Please thank him. ## Usage -The API is exposed as a single `Gab` object, which must be initialized with an authorized JWT. This is a token that is set as "HttpOnly", so it's generally not visible and queryable through JavaScript. You can display that token either with an extension to display cookies or retrieve it from the requests as they are logged by your browser's debugging tools. +The API is exposed as a single `Gab` object, which must be initialized with an authorized JWT. This is a token that is set as "HttpOnly", so it's generally not visible and queryable through JavaScript. You can display that token either with an extension to display cookies (for example, http://www.editthiscookie.com/) or retrieve it from the requests as they are logged by your browser's debugging tools. ```javascript var Gab = require('gab.ai').Gab; - var api = new Gab('This is the message of the post
", gif: '3PrOqZRpbmqFa'}) +api.putPost({body: "This is the message of the post
", gif: '3PrOqZRpbmqFa'}) .then(function(data) { console.log(data); }).catch(function() { From 4de3be2adc5c2e66330a4d5ecd312d09c7caeb8b Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 18:39:40 +0200 Subject: [PATCH 12/19] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7fdf80f..2d0a7f1 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ api.getUser('a') }); // Submit a post. +// The ID of the GIF can be copied from the URL used for sharing the GIF you want to +// attach, such as 'nO2ttDiHPqEP6' in 'https://media.giphy.com/media/nO2ttDiHPqEP6/giphy.gif'. api.putPost({body: "This is the message of the post
", gif: '3PrOqZRpbmqFa'}) .then(function(data) { console.log(data); From d3fc9b5f001c7b7bc3bae24a2b34a05249953fa4 Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 18:40:12 +0200 Subject: [PATCH 13/19] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d0a7f1..5b76453 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ api.getUser('a') }); // Submit a post. -// The ID of the GIF can be copied from the URL used for sharing the GIF you want to +// The ID of the GIF can be copied from the URL used for sharing the GIPHY GIF you want to // attach, such as 'nO2ttDiHPqEP6' in 'https://media.giphy.com/media/nO2ttDiHPqEP6/giphy.gif'. api.putPost({body: "This is the message of the post
", gif: '3PrOqZRpbmqFa'}) .then(function(data) { From 1d7785bee8a93be4f54fb54e7e0331f11a88dd6b Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 18:41:08 +0200 Subject: [PATCH 14/19] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5b76453..f50a566 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ api.getUser('a') // Submit a post. // The ID of the GIF can be copied from the URL used for sharing the GIPHY GIF you want to -// attach, such as 'nO2ttDiHPqEP6' in 'https://media.giphy.com/media/nO2ttDiHPqEP6/giphy.gif'. +// attach, such as 'nO2ttDiHPqEP6' in 'https://media.giphy.com/media/nO2ttDiHPqEP6/giphy.gif' +// or queried from their own API. api.putPost({body: "This is the message of the post
", gif: '3PrOqZRpbmqFa'}) .then(function(data) { console.log(data); From 3001d104ba27ee7adb1e1a67a3e79cac8c909353 Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 18:57:15 +0200 Subject: [PATCH 15/19] Update Gab.js Added more API methods: listing comments and conversations. --- lib/Gab.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/Gab.js b/lib/Gab.js index 05ad9c7..f03081c 100644 --- a/lib/Gab.js +++ b/lib/Gab.js @@ -23,6 +23,14 @@ Gab.prototype.getPost = function (postid) { return this._baseRequest('/posts/' + postid); }; +Gab.prototype.getConversation = function (postid) { + return this._baseRequest('/posts/'+postid+'/conversation'); +}; + +Gab.prototype.getComments = function (postid) { + return this._baseRequest('/posts/'+postid+'/comments'); +}; + Gab.prototype.putPost = function(options) { let body = { body: "", @@ -39,6 +47,7 @@ Gab.prototype.putPost = function(options) { share_twitter: null, media_attachments: [] }; + // Override template values with options. for(var key in options) body[key] = options[key]; return this._baseRequest({ method: 'POST', From 3f051ee9999199cd4276e86d04f8d2b7f787930c Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 19:37:00 +0200 Subject: [PATCH 16/19] Update Gab.js --- lib/Gab.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/lib/Gab.js b/lib/Gab.js index f03081c..630c557 100644 --- a/lib/Gab.js +++ b/lib/Gab.js @@ -3,6 +3,7 @@ var rp = require('request-promise'); function Gab(token) { this._baseRequest = rp.defaults({ baseUrl: 'https://gab.ai/', + //baseUrl: 'http://localhost:8888/', followRedirect: false, headers: { authorization: 'Bearer ' + token @@ -31,6 +32,64 @@ Gab.prototype.getComments = function (postid) { return this._baseRequest('/posts/'+postid+'/comments'); }; +Gab.prototype.getTopics = function () { + return this._baseRequest('/api/topics/'); +}; + +Gab.prototype.getTopic = function (topic_id) { + return this._baseRequest('/api/topics/'+topic_id); +} + +Gab.prototype.getTopicsArchive = function () { + return this._baseRequest('/api/topics/archive/'); +}; + +Gab.prototype.getFavoriteFeeds = function () { + return this._baseRequest('/api/favorite-feeds/'); +}; + +Gab.prototype.getFeatured = function () { + return this._baseRequest('/api/tv/featured'); +}; + +Gab.prototype.getBroadcasts = function () { + return this._baseRequest('/api/broadcasts/'); +}; + +Gab.prototype.getUserVideos = function (user) { + return this._baseRequest('/api/users/'+user+'/tv'); +}; + +Gab.prototype.getNotifications = function () { + return this._baseRequest('/api/notifications/'); +}; + +Gab.prototype.addFavoriteFeed = function(feed_id) { + return this._baseRequest({ + method: 'POST', + uri: '/api/favorite-feeds', + body: {}, + qs: { + feed_type: 'topic', + feed_id: feed_id + } + }); +} + +Gab.prototype.removeFavoriteFeed = function(feed_id) { + return this._baseRequest({ + method: 'POST', + uri: '/api/favorite-feeds', + body: { + _method: 'delete' + }, + qs: { + feed_type: 'topic', + feed_id: feed_id + } + }); +} + Gab.prototype.putPost = function(options) { let body = { body: "", From 86399467fd3e82264d95dcc40653c040850f5609 Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 19:37:19 +0200 Subject: [PATCH 17/19] Update Gab.js --- lib/Gab.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Gab.js b/lib/Gab.js index 630c557..aaf8af7 100644 --- a/lib/Gab.js +++ b/lib/Gab.js @@ -3,7 +3,6 @@ var rp = require('request-promise'); function Gab(token) { this._baseRequest = rp.defaults({ baseUrl: 'https://gab.ai/', - //baseUrl: 'http://localhost:8888/', followRedirect: false, headers: { authorization: 'Bearer ' + token From c0d9fe8a3eae77e450fe4b8e244b25224cc2083c Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 19:53:35 +0200 Subject: [PATCH 18/19] Update Gab.js Added more API methods. Minor cleanup to existing functions. Take care that some methods are prefixed with '/api/' and some are not. --- lib/Gab.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Gab.js b/lib/Gab.js index aaf8af7..a3d0235 100644 --- a/lib/Gab.js +++ b/lib/Gab.js @@ -3,6 +3,7 @@ var rp = require('request-promise'); function Gab(token) { this._baseRequest = rp.defaults({ baseUrl: 'https://gab.ai/', + //baseUrl: 'http://localhost:8888/', followRedirect: false, headers: { authorization: 'Bearer ' + token @@ -63,6 +64,20 @@ Gab.prototype.getNotifications = function () { return this._baseRequest('/api/notifications/'); }; +Gab.prototype.getCategory = function (category, sort = 'score', include_replies = 0) { + return this._baseRequest({ + uri: '/api/category/'+category, + qs: { + sort: sort, + include_replies: include_replies + } + }); +}; + +Gab.prototype.getPopularUsers = function () { + return this._baseRequest('/popular/users'); +}; + Gab.prototype.addFavoriteFeed = function(feed_id) { return this._baseRequest({ method: 'POST', From 3cb1871228f293c7d9552c9a6d32aa9e3e28efb3 Mon Sep 17 00:00:00 2001 From: PickledCatBrains <34631439+PickledCatBrains@users.noreply.github.com> Date: Mon, 16 Apr 2018 20:20:43 +0200 Subject: [PATCH 19/19] Update Gab.js Added methods to follow and unfollow users. --- lib/Gab.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/Gab.js b/lib/Gab.js index a3d0235..e906448 100644 --- a/lib/Gab.js +++ b/lib/Gab.js @@ -78,6 +78,24 @@ Gab.prototype.getPopularUsers = function () { return this._baseRequest('/popular/users'); }; +Gab.prototype.followUser = function (user_id) { + return this._baseRequest({ + method: 'POST', + uri: '/users/'+user_id+'/follow', + body: {} + }); +}; + +Gab.prototype.unFollowUser = function (user_id) { + return this._baseRequest({ + method: 'POST', + uri: '/users/'+user_id+'/follow', + body: { + _method: 'delete' + } + }); +}; + Gab.prototype.addFavoriteFeed = function(feed_id) { return this._baseRequest({ method: 'POST',