tumblr-promise
v0.0.1
Published
minimal, promise-based tumblr api client
Downloads
3
Readme
tumblr-promise
minimal, promise-based tumblr api client for node.js
:exclamation: This project is in early development. Don't assume all features described here are functional. See this note re: versioning
Why?
It's true that there are plenty of other tumblr clients out there for node, including an official driver. However, I wanted one that:
- doesn't require OAuth tokens to instantiate the client by default
- extends functionality of most-used apis
- isn't bloated with rarely-used apis
- exposes chainable promises rather than callbacks
- is maintained :grin:
This package is designed to be able to fetch posts using several query parameters at once while sorting and transforming the data on the fly. It is very flexible but its overall api coverage is opinionated and selective; ideally it would cover the entire api, so pull requests are welcome, but I don't expect it to ever have 100% coverage. If you're looking for a more generic wrapper I would recommend the official client.
Installation
with npm and node ^6.0.0
:
npm install tumblr-promise --save
Authentication
Depending on the request, tumblr api endpoints require different forms of authentication. Some are unauthenticated, the bulk need an api key, and the most complex require an OAuth token. Check out the docs for details and instructions for generating a token.
Usage
The constructor requires an api_key
since you need one to make any of the requests this library supports. oauth_token
is an optional parameter.
const Tumblr = require('tumblr-promise')
const api = Tumblr.new({
name: 'yoursubdomain', // yoursubdomain.tumblr.com
api_key: 'YOUR_CONSUMER_SECRET'
})
// simplest invocation
let last20Posts = api.get()
// the fun part...
api
.get(5)
.skip(10)
.filter('portfolio, case studies') // filter by #tag
.filter(['array', 'works', 'too'])
.media('photo')
.media('video') // multiple content types in one request!
.transform(p => { // map function to apply to every post
delete p.foo
p.bar = p.baz * 2
return p
})
.then(console.log)
.catch(console.error)
Testing
To run the tests locally, you'll need to add a test/.env
with your blog name and api key values: cp test/.env.sample test/.env