npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jobians/bloggerjs

v1.0.1

Published

A Node.js client for the Blogger API

Downloads

11

Readme

BloggerJS

BloggerJS is a Node.js wrapper for the Google Blogger API v3, allowing you to interact with blogs, posts, pages, comments, and users programmatically.

Features

  • Retrieve blog details by ID or URL
  • Manage blog posts: create, update, delete, and list
  • Manage pages: create, update, delete, and list
  • Manage comments: list, approve, and delete
  • Retrieve user information and blogs
  • Supports custom requests via sendRequest

Installation

Install via npm:

npm install @jobians/bloggerjs

Getting Started

Using Provided credentials.json

This library comes with a working credentials.json file to help you get started quickly. You can either:

  • Use the provided credentials.json as-is for testing.
  • Replace it with your own credentials if you have an existing Google Cloud project.

To replace the credentials, simply download your credentials.json file from your Google Cloud Console and overwrite the existing credentials.json file in the root directory.

Usage Example

const BloggerJS = require('@jobians/bloggerjs');

const blogId = 'your-blog-id';
const blogger = new BloggerJS(blogId);

(async () => {
  try {
    // Get Blog Details
    const blog = await blogger.getBlog();
    console.log(blog);

    // Get Blog by URL
    const blogByUrl = await blogger.getBlogByUrl('http://username.blogspot.com');
    console.log(blogByUrl);

    // List Posts
    const posts = await blogger.getPosts({ maxResults: 5 });
    console.log(posts);

    // Get a Specific Post by ID
    const postId = 'your-post-id';
    const post = await blogger.getPost(postId);
    console.log(post);

    // Add a New Post
    const newPost = await blogger.addPost({
      title: 'My New Post',
      content: 'This is the content of my new post!',
    });
    console.log(newPost);

    // Update a Post
    const updatedPost = await blogger.updatePost(postId, {
      title: 'Updated Post Title',
      content: 'Updated content of the post',
    });
    console.log(updatedPost);

    // Delete a Post
    await blogger.deletePost(postId);
    console.log(`Post ${postId} deleted`);

  } catch (error) {
    console.error('Error:', error.message);
  }
})();

API Documentation

1. getBlog()

Retrieve blog details using the blog ID provided during instantiation.

const blog = await blogger.getBlog();
console.log(blog);

2. getBlogByUrl(blogUrl)

Retrieve a blog's details using its URL.

Parameters:

  • blogUrl (string) – The URL of the blog.
const blogByUrl = await blogger.getBlogByUrl('http://username.blogspot.com');
console.log(blogByUrl);

3. getPosts(params = {})

Retrieve a list of posts for the blog.

Optional Parameters:

  • maxResults (number) – The maximum number of posts to return.
const posts = await blogger.getPosts({ maxResults: 10 });
console.log(posts);

4. getPost(postId)

Retrieve details of a specific post by its ID.

Parameters:

  • postId (string) – The ID of the post.
const post = await blogger.getPost('your-post-id');
console.log(post);

5. addPost(params)

Create a new post on the blog.

Parameters:

  • params (object) – An object containing the post properties, such as title, content, etc.
const newPost = await blogger.addPost({
  title: 'New Post Title',
  content: 'The content of the new post.',
});
console.log(newPost);

6. deletePost(postId)

Delete a post by its ID.

Parameters:

  • postId (string) – The ID of the post to delete.
await blogger.deletePost('your-post-id');
console.log('Post deleted');

7. updatePost(postId, params)

Update an existing post.

Parameters:

  • postId (string) – The ID of the post to update.
  • params (object) – An object containing the new post properties (e.g., title, content).
const updatedPost = await blogger.updatePost('your-post-id', {
  title: 'Updated Title',
  content: 'Updated post content',
});
console.log(updatedPost);

8. patchPost(postId, params)

Partially update a post using patch semantics.

Parameters:

  • postId (string) – The ID of the post to update.
  • params (object) – An object containing the fields to update.
const patchedPost = await blogger.patchPost('your-post-id', {
  content: 'Partially updated content',
});
console.log(patchedPost);

9. getComments(postId, params = {})

Retrieve a list of comments for a specific post.

Parameters:

  • postId (string) – The ID of the post.
  • params (object) – Optional parameters such as maxResults.
const comments = await blogger.getComments('your-post-id', { maxResults: 5 });
console.log(comments);

10. getComment(postId, commentId)

Retrieve details of a specific comment by its ID.

Parameters:

  • postId (string) – The ID of the post.
  • commentId (string) – The ID of the comment.
const comment = await blogger.getComment('your-post-id', 'comment-id');
console.log(comment);

11. deleteComment(postId, commentId)

Delete a specific comment by its ID.

Parameters:

  • postId (string) – The ID of the post.
  • commentId (string) – The ID of the comment.
await blogger.deleteComment('your-post-id', 'comment-id');
console.log('Comment deleted');

12. approveComment(postId, commentId)

Approve a comment that is awaiting moderation.

Parameters:

  • postId (string) – The ID of the post.
  • commentId (string) – The ID of the comment.
await blogger.approveComment('your-post-id', 'comment-id');
console.log('Comment approved');

13. getPages(params = {})

Retrieve a list of pages for the blog.

Optional Parameters:

  • maxResults (number) – The maximum number of pages to return.
const pages = await blogger.getPages({ maxResults: 10 });
console.log(pages);

14. getPage(pageId)

Retrieve details of a specific page by its ID.

Parameters:

  • pageId (string) – The ID of the page.
const page = await blogger.getPage('your-page-id');
console.log(page);

15. addPage(params)

Create a new page on the blog.

Parameters:

  • params (object) – An object containing the page properties, such as title, content, etc.
const newPage = await blogger.addPage({
  title: 'New Page Title',
  content: 'The content of the new page.',
});
console.log(newPage);

16. updatePage(pageId, params)

Update an existing page.

Parameters:

  • pageId (string) – The ID of the page to update.
  • params (object) – An object containing the new page properties (e.g., title, content).
const updatedPage = await blogger.updatePage('your-page-id', {
  title: 'Updated Title',
  content: 'Updated page content',
});
console.log(updatedPage);

17. deletePage(pageId)

Delete a page by its ID.

Parameters:

  • pageId (string) – The ID of the page to delete.
await blogger.deletePage('your-page-id');
console.log('Page deleted');

18. getUserBlogs(userId)

Retrieve a list of blogs for the specified user.

Parameters:

  • userId (string) – The ID of the user. Use 'self' to refer to the authenticated user.
const blogs = await blogger.getUserBlogs('self');
console.log(blogs);

19. getUser()

Retrieve the authenticated user's details.

const user = await blogger.getUser();
console.log(user);

20. logout()

Log out and remove saved authentication credentials. This will delete the token.json file, effectively logging you out of the Blogger API.

await blogger.logout();

Extending with Custom Requests

You can extend this class to make any custom requests that aren't directly covered by the provided methods. The sendRequest method allows you to make API calls by specifying the HTTP method, the endpoint, and any parameters.

sendRequest(method, endpoint, params)

Make a custom request to any Blogger API endpoint.

Parameters:

  • method (string) – The HTTP method (e.g., 'get', 'post', 'delete', etc.).
  • endpoint (string) – The Blogger API endpoint in the format resource.action.
  • params (object) – The parameters to send with the request.

Example:

// Custom request to list posts with a specific label
const customRequest = await blogger.sendRequest('get', 'posts.list', {
  blogId: 'your-blog-id',
  labels: 'Technology',
  maxResults: 5,
});
console.log(customRequest);

The sendRequest method gives you the flexibility to interact with any part of the Blogger API, even those not directly wrapped by this library. You can refer to the official Blogger API v3 documentation for more information on available endpoints.

Support

If you find my work helpful, you can support me by donating:

Donate