designer-news
Designer News API client
Last updated 6 years ago by meltingice .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install designer-news 
SYNC missed versions from official npm registry.

Designer News API

NodeJS client for accessing the Designer News API.

Installation

The library is available on npm:

npm install designer-news

Configuration

var DN = require('designer-news');

// Configure
var config = new DN.Configuration(function () {
  this.oauthKey = 'abc123'
  this.oauthSecret = 'foobar'

  // optional, if you have it
  this.accessToken = 'jfosdf9sud98fds0f8snd0fs8dnf'
});

// Create the client
var client = new DN.Client(config);

Usage

Authentication

// If configured without an access token, you will need
// to authenticate and retrieve one. Here's the password flow:
client.auth.withPassword('username', 'password', function (err, tokens) {
  // We are now logged in. The configuration is automatically updated
  // with the access token. We can store them somewhere persistent
  // if needed.
});

Retrieving Data

The JS function names roughly follow the same convention as the API URLs.

client.me(callback);

client.stories.get(id, callback);
client.stories.frontPage({page: 2}, callback);
client.stories.recent({page: 2}, callback);
client.stories.search(query, callback);
client.stories.upvote(id, callback);
client.stories.reply(id, comment, callback);

client.comments.get(id, callback);
client.comments.upvote(id, callback);
client.comments.reply(id, comment, callback);

client.motd.get(callback);
client.motd.upvote(callback);
client.motd.downvote(callback);

Promises

All asynchronous calls return a promise, which can be used as an alternative to providing a callback.

client.auth.withPassword('username', 'password').then(function (resp) {
  console.log(resp.accessToken);
  return client.stories.frontPage();
}).then(function (resp) {
  return client.stories.upvote(resp.stories[0].id);
}).then(function (story) {
  console.log(story);
});

Links

Author

Ryan LeFevre - GitHub, Twitter, Email

License

Available under the MIT license. See the LICENSE file for more info.

Current Tags

  • 0.1.1                                ...           latest (6 years ago)

4 Versions

  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (3)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |