Skip to content

Commit

Permalink
example: Support verbs and get endpoints
Browse files Browse the repository at this point in the history
Previous behaviour is preserved

Relate-to: #3
Change-Id: If495364c7d592f616428512e4733cd57f95bf1bd
Signed-off-by: Philippe Coval <[email protected]>
  • Loading branch information
rzr committed Mar 2, 2019
1 parent 62d69e5 commit 1039c9b
Showing 1 changed file with 47 additions and 7 deletions.
54 changes: 47 additions & 7 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,51 @@ try {
process.exit(0);
}

var mastodon = Mastodon(config);
var message;
if (process.argv.length > 2) {
message = process.argv[2];
mastodon.post(message);
} else {
mastodon.get('timelines/home');
module.exports = function(argv, callback) {
var mastodon = Mastodon(config);
var verb = 'get';
var token = null;
var idx = 2;

if (argv.length > idx && (token = argv[idx])) {
if (token === 'get' || token === 'post' ||
token === 'put' || token === 'delete') {
verb = token;
idx += 1;
} else {
verb = 'post';
}
}

switch (verb) {

case 'post':
if (argv.length > idx) {
var message = null;
message = argv[idx];
mastodon.post(message, function(data) {
callback(null, data);
});
}
break;

case 'get':
var endpoint = 'timelines/home';
if (argv.length > idx) endpoint = argv[idx];
mastodon.get(endpoint, function(data) {
callback(null, data);
});
break;

default:
if (callback) return callback('Error: Must be implemented', null);
break;
}
};


if (module.parent === null) {
module.exports(process.argv, function(err, data) {
console.log(err, data);
});
}

0 comments on commit 1039c9b

Please sign in to comment.