Skip to content

Commit

Permalink
0.7.0 blogInfo command
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Lysenko committed Nov 16, 2018
1 parent 9403f32 commit 3cbc396
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FROM mhart/alpine-node:10

RUN npm i -g tumblr-toolkit

ENTRYPOINT ["tt"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ Optional params (with example)

``` --tags "one, second one"```

### Get blog info

````bash
tt blogInfo -c path/to/keys.json -b blogName
````

### Get post info

````bash
Expand Down
1 change: 1 addition & 0 deletions api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
post: require('./tools/post'),
postInfo: require('./tools/postInfo'),
blogInfo: require('./tools/blogInfo'),
blogPosts: require('./tools/blogPosts'),
blogQueue: require('./tools/blogQueue'),
blogDrafts: require('./tools/blogDrafts'),
Expand Down
6 changes: 6 additions & 0 deletions cli/blogInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = yargs => {

yargs
.describe('b', 'Blog name from where the post')
.usage('Usage: $0 postInfo -c [file] -b [blog]');
}
1 change: 1 addition & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module.exports = {

cli: require('yargs')

.command('blogInfo', 'Get blog info', require('../cli/blogInfo'))
.command('post', 'Create blog post', require('../cli/post'))
.command('postInfo', 'Get post info', require('../cli/postInfo'))
.command('blogPosts', 'Get blog posts', require('../cli/blogPosts'))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tumblr-toolkit",
"version": "0.6.3",
"version": "0.7.0",
"description": "Tumblr API-based toolkit for batch posts processing.",
"main": "api.js",
"dependencies": {
Expand Down
34 changes: 34 additions & 0 deletions tools/blogInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const tumblrJs = require('tumblr.js');

module.exports = async (params) => {
const { blog } = params;

const tumblr = tumblrJs.createClient({
credentials: params.credentials,
returnPromises: true,
});

try {
const response = await tumblr.userInfo();
let result;
if (!response || !response.user || !response.user.blogs) {
result = {
error: 'Failed to get user blogs info',
};
} else {
const info = response.user.blogs.find(({ name }) => name === blog);
if (!info) {
result = {
error: `Blog ${blog} not found`,
};
}
result = ['title', 'name', 'url', 'admin', 'drafts', 'followers', 'posts', 'primary', 'queue', 'total_posts']
.reduce((res, field) => Object.assign(res, {[field]: info[field]}), {});
}
params.isCli && console.log(result);
return result;
} catch (error) {
console.error(error);
return error;
}
}

0 comments on commit 3cbc396

Please sign in to comment.