Skip to content

Commit

Permalink
Update README according to 4.0 changes (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal authored Aug 18, 2023
1 parent 492726a commit 68deae9
Showing 1 changed file with 56 additions and 95 deletions.
151 changes: 56 additions & 95 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,176 +95,137 @@ Below is a list of available methods and their purpose. Available options are do
[API Docs](https://www.tumblr.com/docs/api/v2) and are specified as a JavaScript object.

```js
client.blogPosts(
'blogName',
{ type: 'photo', tag: ['multiple', 'tags', 'likethis'] },
function (err, resp) {
resp.posts; // use them for something
},
);
const response = await client.blogPosts('blogName', {
type: 'photo',
tag: ['multiple', 'tags', 'likethis'],
});
```

In most cases, since options are optional (heh) they are also an optional argument, so there is no
need to pass an empty object when supplying no options, like:

```js
client.blogPosts('blogName', function (err, resp) {
resp.posts; // now we've got all kinds of posts
});
```

If you're using Promises, use `then` and/or `catch` instead of a callback:

```js
client
.blogPosts('blogName')
.then(function (resp) {
resp.posts;
})
.catch(function (err) {
// oops
});
const response = await client.blogPosts('blogName');
```

### User Methods

```js
// Get information about the authenticating user & their blogs
client.userInfo(callback);
const userInfo = await client.userInfo();

// Get dashboard for authenticating user
client.userDashboard(options, callback);
client.userDashboard(callback);
const userDashboard = await client.userDashboard(options);

// Get likes for authenticating user
client.userLikes(options, callback);
client.userLikes(callback);
const userLikes = await client.userLikes(options);

// Get followings for authenticating user
client.userFollowing(options, callback);
client.userFollowing(callback);
const userFollowing = await client.userFollowing(options);

// Follow or unfollow a given blog
client.followBlog(blogURL, callback);
client.unfollowBlog(blogURL, callback);
await client.followBlog(blogURL);
await client.unfollowBlog(blogURL);

// Like or unlike a given post
client.likePost(id, reblogKey, callback);
client.unlikePost(id, reblogKey, callback);
await client.likePost(postId, reblogKey);
await client.unlikePost(postId, reblogKey);
```

### Blog Methods

```js
// Get information about a given blog
client.blogInfo(blogName, callback);
const blogInfo = await client.blogInfo(blogName);

// Get a list of posts for a blog (with optional filtering)
client.blogPosts(blogName, options, callback);
client.blogPosts(blogName, callback);
const blogPosts = await client.blogPosts(blogName, options);

// Get the avatar URL for a blog
client.blogAvatar(blogName, size, callback);
client.blogAvatar(blogName, callback);
const blogAvatar = await client.blogAvatar(blogName);

// Get the likes for a blog
client.blogLikes(blogName, options, callback);
client.blogLikes(blogName, callback);
const blogLikes = await client.blogLikes(blogName, options);

// Get the followers for a blog
client.blogFollowers(blogName, options, callback);
client.blogFollowers(blogName, callback);
const blogFollowers = await client.blogFollowers(blogName, options);

// Get the queue for a blog
client.blogQueue(blogName, options, callback);
client.blogQueue(blogName, callback);
const blogQueue = await client.blogQueue(blogName, options);

// Get the drafts for a blog
client.blogDrafts(blogName, options, callback);
client.blogDrafts(blogName, callback);
const blogDrafts = await client.blogDrafts(blogName, options);

// Get the submissions for a blog
client.blogSubmissions(blogName, options, callback);
client.blogSubmissions(blogName, callback);
const blogSubmissions = await client.blogSubmissions(blogName, options);
```

### Post Methods

```js
// Edit a given post
client.editPost(blogName, options, callback);
// Create or reblog a post
await client.createPost(blogName, options);

// Reblog a given post
client.reblogPost(blogName, options, callback);
// Edit a post
await client.editPost(blogName, postId, options);

// Delete a given post
client.deletePost(blogName, id, callback);

// Convenience methods for creating post types
client.createTextPost(blogName, options, callback);
client.createPhotoPost(blogName, options, callback);
client.createQuotePost(blogName, options, callback);
client.createLinkPost(blogName, options, callback);
client.createChatPost(blogName, options, callback);
client.createAudioPost(blogName, options, callback);
client.createVideoPost(blogName, options, callback);
await client.deletePost(blogName, postId);
```

### Legacy Post Methods (deprecated)

```js
// Create a legacy post
const createdPost = await client.createLegacyPost(blogName, options);

// Edit a legacy post
await client.editLegacyPost(blogName, options);

// Reblog a legacy post
await client.reblogPost(blogName, options);
```

### Tagged Methods

```js
// View posts tagged with a certain tag
client.taggedPosts(tag, options, callback);
client.taggedPosts(tag, callback);
client.taggedPosts(tag, options);
client.taggedPosts(tag);
```

## Unsupported Methods

You can make GET and POST requests to any endpoint directly. These methods are used internally by
the methods listed above:
You can make arbitrary requests via the following methods.

```js
// GET requests
client.getRequest(apiPath, params, callback);
client.getRequest(apiPath, params);

// POST requests
client.postRequest(apiPath, params, callback);
```
client.postRequest(apiPath, params);

In the unlikely event that we add a bunch of methods to the API docs and don't update this client,
you can map new client methods to API endpoints. URL and query parameters are automatically turned
into arguments to these methods. It's a little weird to explain, so just look at these examples:

```js
// GET methods
client.addGetMethods({
// creates client.userInfo(params, callback)
userInfo: '/v2/user/info',
// client.blogInfo(blogIdentifier, params, callback)
blogInfo: '/v2/blog/:blogIdentifier/info',
// Creates client.taggedPosts(tag, params, callback)
taggedPosts: ['/v2/tagged', ['tag']],
});

// POST methods
client.addPostMethods({
// client.deletePost(blogIdentifier, id, params, callback)
deletePost: ['/v2/blog/:blogIdentifier/post/delete', ['id']],
// Creates client.likePost(tag, id, reblog_key, params, callback)
likePost: ['/v2/user/like', ['id', 'reblog_key']],
});
// PUT requests
client.postRequest(apiPath, params);
```

---

## Running Tests

```bash
npm test # linter and tests
npm run lint # linter
npm run mocha # just the tests
# Run tests
npm run test

# Lint
npm run lint

# Typecheck
npm run typecheck
```

See [CONTRIBUTING.md](./CONTRIBUTING.md) for more details including the integration tests.

---

## Copyright and license
Expand Down

0 comments on commit 68deae9

Please sign in to comment.