### Installing tumblr.js via npm Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This snippet demonstrates how to install the tumblr.js client library using npm. The `--save` flag adds the package as a dependency in your project's `package.json` file. ```Bash npm install --save tumblr.js ``` -------------------------------- ### Running Unit Tests for tumblr.js (Shell) Source: https://github.com/tumblr/tumblr.js/blob/main/CONTRIBUTING.md This command executes the unit tests for the tumblr.js project. Unit tests are located in the 'test/' directory and verify individual components of the library without external API calls. Dependencies must be installed first using 'npm ci'. ```Shell npm run test ``` -------------------------------- ### Retrieving and Displaying User Blog Names (Callback) Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This example demonstrates how to fetch information about the authenticating user using `client.userInfo()` and then iterate through their blogs to log each blog's name to the console. Note that this uses a callback pattern, which is considered deprecated; promises are the preferred approach. ```JavaScript // Show user's blog names client.userInfo(function (err, data) { data.user.blogs.forEach(function (blog) { console.log(blog.name); }); }); ``` -------------------------------- ### Making Arbitrary HTTP Requests with Tumblr.js Client (JavaScript) Source: https://github.com/tumblr/tumblr.js/blob/main/README.md These snippets show how to make arbitrary GET, POST, and PUT requests using the Tumblr.js client's generic request methods. These methods are useful for interacting with API endpoints not explicitly covered by the client's specific functions. Each method takes an `apiPath` and an optional `params` object for query parameters or request body. ```JavaScript // GET requests client.getRequest(apiPath, params); ``` ```JavaScript // POST requests client.postRequest(apiPath, params); ``` ```JavaScript // PUT requests client.putRequest(apiPath, params); ``` -------------------------------- ### Creating a New Post on a Blog Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This snippet demonstrates how to create a new post on a specified `blogName` using the `client.createPost()` method. The `options` object contains the post's content and other properties, and the method returns a promise. ```JavaScript await client.createPost(blogName, options); ``` -------------------------------- ### Alternative Tumblr Client Initialization in Node.js Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This snippet provides an alternative way to initialize the Tumblr API client in Node.js using the `new tumblr.Client()` constructor. It serves the same purpose as `tumblr.createClient()` but uses a different instantiation pattern. ```JavaScript const tumblr = require('tumblr.js'); const client = new tumblr.Client({ // ... }); ``` -------------------------------- ### Running Integration Tests with Consumer Key (Shell) Source: https://github.com/tumblr/tumblr.js/blob/main/CONTRIBUTING.md This command initiates a partial suite of integration tests for tumblr.js, requiring only a valid Tumblr OAuth consumer key. The tests query the Tumblr API to read data and do not make any modifications. Ensure the consumer key is securely provided as an environment variable. ```Shell TUMBLR_OAUTH_CONSUMER_KEY='--- valid consumer_key ---' \ npm run test:integration ``` -------------------------------- ### Running Full Integration Tests with All OAuth Credentials (Shell) Source: https://github.com/tumblr/tumblr.js/blob/main/CONTRIBUTING.md This command runs the complete suite of integration tests for tumblr.js, which requires full OAuth1 credentials (consumer key, consumer secret, token, and token secret). These tests interact with the Tumblr API to read data. It is recommended to use a dedicated test account and set the API Console URL as the default callback. ```Shell TUMBLR_OAUTH_CONSUMER_KEY='--- valid consumer_key ---' \ TUMBLR_OAUTH_CONSUMER_SECRET='--- valid consumer_secret ---' \ TUMBLR_OAUTH_TOKEN='--- valid token ---' \ TUMBLR_OAUTH_TOKEN_SECRET='--- valid token_key ---' \ npm run test:integration ``` -------------------------------- ### Fetching Blog Posts with Options (Promise-based) Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This snippet shows how to retrieve blog posts for a specified `blogName` using `client.blogPosts()`. It demonstrates passing an options object to filter posts by `type` (e.g., 'photo') and `tag`, returning a promise that resolves to the `response` data. ```JavaScript const response = await client.blogPosts('blogName', { type: 'photo', tag: ['multiple', 'tags', 'likethis'], }); ``` -------------------------------- ### Running Development Scripts for Tumblr.js (Bash) Source: https://github.com/tumblr/tumblr.js/blob/main/README.md These Bash commands are used for development and quality assurance of the Tumblr.js project. `npm run test` executes the test suite, `npm run lint` performs code linting to enforce style and catch errors, and `npm run typecheck` runs type checking, likely for TypeScript, to ensure type safety. ```Bash # Run tests npm run test ``` ```Bash # Lint npm run lint ``` ```Bash # Typecheck npm run typecheck ``` -------------------------------- ### Fetching Blog Posts without Options (Promise-based) Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This snippet illustrates how to fetch all blog posts for a given `blogName` when no specific filtering options are required. It highlights that the options argument is optional, simplifying calls when default behavior is desired. ```JavaScript const response = await client.blogPosts('blogName'); ``` -------------------------------- ### Initializing Tumblr Client in Node.js with Full OAuth Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This snippet shows how to initialize the Tumblr API client in a Node.js environment using `tumblr.createClient()`. It requires full OAuth credentials including consumer key, consumer secret, OAuth token, and token secret for making signed requests. ```JavaScript const tumblr = require('tumblr.js'); const client = tumblr.createClient({ consumer_key: '', consumer_secret: '', token: '', token_secret: '', }); ``` -------------------------------- ### Managing Legacy Posts with Tumblr.js Client (JavaScript) Source: https://github.com/tumblr/tumblr.js/blob/main/README.md These snippets illustrate deprecated methods for managing legacy posts using the Tumblr.js client. They include creating a new legacy post, editing an existing one, and reblogging a post. Each method requires the `blogName` and an `options` object containing post-specific parameters. ```JavaScript // Create a legacy post const createdPost = await client.createLegacyPost(blogName, options); ``` ```JavaScript // Edit a legacy post await client.editLegacyPost(blogName, options); ``` ```JavaScript // Reblog a legacy post await client.reblogPost(blogName, options); ``` -------------------------------- ### Calling Various Blog-Related API Methods Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This snippet showcases various API methods for interacting with Tumblr blogs. It covers retrieving blog information, posts, avatar URLs, likes, followers, and content from the queue, drafts, and submissions. Most methods require a `blogName` and can accept an optional `options` object for filtering or pagination. ```JavaScript // Get information about a given blog const blogInfo = await client.blogInfo(blogName); // Get a list of posts for a blog (with optional filtering) const blogPosts = await client.blogPosts(blogName, options); // Get the avatar URL for a blog const blogAvatar = await client.blogAvatar(blogName); // Get the likes for a blog const blogLikes = await client.blogLikes(blogName, options); // Get the followers for a blog const blogFollowers = await client.blogFollowers(blogName, options); // Get the queue for a blog const blogQueue = await client.blogQueue(blogName, options); // Get the drafts for a blog const blogDrafts = await client.blogDrafts(blogName, options); // Get the submissions for a blog const blogSubmissions = await client.blogSubmissions(blogName, options); ``` -------------------------------- ### Calling Various User-Related API Methods Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This comprehensive snippet demonstrates several user-specific API methods available in the tumblr.js client. It includes fetching user info, dashboard data, likes, and followings, as well as actions like following/unfollowing blogs and liking/unliking posts. Most methods return promises and can accept an optional `options` object. ```JavaScript // Get information about the authenticating user & their blogs const userInfo = await client.userInfo(); // Get dashboard for authenticating user const userDashboard = await client.userDashboard(options); // Get likes for authenticating user const userLikes = await client.userLikes(options); // Get followings for authenticating user const userFollowing = await client.userFollowing(options); // Follow or unfollow a given blog await client.followBlog(blogURL); await client.unfollowBlog(blogURL); // Like or unlike a given post await client.likePost(postId, reblogKey); await client.unlikePost(postId, reblogKey); ``` -------------------------------- ### Creating a Post with Image Media Upload Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This snippet illustrates how to create a post that includes an image upload. It uses `client.createPost()` with a `content` array containing an object of `type: 'image'`. The `media` property expects a `ReadStream` (e.g., from Node's `fs` module) for the image file, and `alt_text` can be provided for accessibility. ```JavaScript await client.createPost(blogName, { content: [ { type: 'image', // Node's fs module, e.g. `import fs from 'node:fs';` media: fs.createReadStream(new URL('./image.jpg', import.meta.url)), alt_text: '…', }, ], }); ``` -------------------------------- ### Deleting a Post with Tumblr.js Client (JavaScript) Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This snippet demonstrates how to delete an existing post using the `deletePost` method of the Tumblr.js client. It requires the `blogName` (the name of the blog) and `postId` (the ID of the post to be deleted) as parameters. The method is asynchronous and should be awaited. ```JavaScript await client.deletePost(blogName, postId); ``` -------------------------------- ### Retrieving Tagged Posts with Tumblr.js Client (JavaScript) Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This snippet demonstrates how to retrieve posts associated with a specific tag using the `taggedPosts` method. It can be called with just the `tag` name or with an additional `options` object to refine the query, such as limiting results or specifying an offset. ```JavaScript // View posts tagged with a certain tag client.taggedPosts(tag, options); ``` ```JavaScript client.taggedPosts(tag); ``` -------------------------------- ### Editing an Existing Post on a Blog Source: https://github.com/tumblr/tumblr.js/blob/main/README.md This snippet shows how to modify an existing post on a specified `blogName` using `client.editPost()`. It requires the `postId` of the post to be edited, and the `options` object contains the updated content or properties for the post. ```JavaScript await client.editPost(blogName, postId, options); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.