Giter Club home page Giter Club logo

damn's Introduction

dAmn bitHound Score

Node.js DeviantArt API client

Quick start

var dAmn = require('damn');

dAmn.public(1234, 'cl13nt_s3cr3t', function(err, daClient) {
	// Fetch today's daily deviations
	daClient.getDailyDeviations(function(err, data) {
		// Output one title
		console.log(data[0].title);
	});
});

Client generation

dAmn currently supports two authentication methods : Client Credentials and Implicit. Both of them provide access to public endpoints. The Implicit method however is an user authentication method and also provides access to user-specific APIs.

Both methods require a client_id and a client_secret to be granted an access token. These are obtained by creating an app in DeviantArt's application page.

Public API

The easiest way to access public API is to use the Client Credentials method, which is available via dAmn.public :

dAmn.public(4321, 'cl13nt_s3cr3t', function(err, publicClient) {
	publicClient.getDeviation(...);
});

Where 4321 is your client_id and cl13nt_s3cr3t is your client_secret.

This returns a Client object from which you can call the methods marked public described below.

Logged-in API

Accessing user-specific endpoints can only be done via using the Implicit authentication method. This methods requires you to provide an username, a password, a client_id and redirect_uri for the application you created.

If you're using this method, make sure your "OAuth2 Grant Type" settings is set to "Implicit" in your application parameters : DA application's OAuth Grant Type setting

To instanciate a "private" client you may use dAmn.private method :

dAmn.private('username', 'password', 1234, 'https://www.example.com', function(err, privateClient) {
	privateClient.getWatchFeed(...);
});

Where 1234 is your client_id and https://www.example.com is your redirect_uri.

This returns a Client object from which you can call all the methods described below.

Methods

All these methods are asynchronous.

getDailyDeviations(callback)

Public endpoint

Returns the list of today's daily deviations :

client.getDailyDeviations(function(err, dailyDeviations) {
	console.log(dailyDeviations);
});

Parameters :

  • callback : called with two parameters : error (null if none) and an array containing the daily deviations.

getNotifications(callback)

Private endpoint

Returns the list of current user notifications :

client.getNotifications(function(err, notifications) {
   console.log(notifications);
});

Parameters :

  • callback : called with two parameters : error (null if none) and an array containing the notifications.

getWatchFeed(callback)

Private endpoint

Returns the current user's watch feed :

client.getWatchFeed(function(err, watchFeedItems) {
   console.log(watchFeedItems);
});

Parameters :

  • callback : called with two parameters : error (null if none) and an array containing the watch feed items.

getDeviation(deviationId, callback)

Public endpoint

Returns the details of a specific deviation :

client.getDeviation("deviationId", function(err, data) {
	console.log(data);
});

Parameters :

  • deviationId : the deviation id, as a string.
  • callback : called with two parameters : error (null if none) and an object containing the deviation.

getFolderDeviations(options, callback)

Public endpoint

Returns the list of a folder's deviations (all user's deviations if no folderId is given) :

client.getFolderDeviations({
	folderId: "folderId"
}, function(err, data) {
	console.log(data);
});

Parameters :

  • options : an object with optional folderId and offset keys.
  • callback : called with two parameters : error (null if none) and an array containing the folder's deviations.

getGalleryFolders(options, callback)

Public endpoint

Returns the list of an user's gallery folders :

client.getGalleryFolders({
	username: "username"
}, function(err, folders) {
	console.log(folders);
});

Parameters :

  • options : an object with a required username key and an optional offset key.
  • callback : called with two parameters : error (null if none) and an array containing the specified user folders.

placebo(callback)

Public endpoint

Implementation of DA's placebo route. Use it to check you access token validity. Or better yet, use checkAccessToken() !

client.placebo(function(err, statusData) {
   console.log(statusData);
});

Parameters :

  • callback : called with two parameters : error (null if none) and an the status object.

checkAccessToken(callback)

Check the validity of your access token.

client.checkAccessToken(function(err, isValid) {
   console.log(isValid);
});

Parameters :

  • callback : called with two parameters : error (null if none) and a boolean indicating whether the current access token is still valid.

Todo

  • Use Node.js v4.0.0 and ES6 features
  • Automate token refresh
  • Use code linting tools :
    • jshint
    • jscs
  • Add access to the following routes :
    • /deviation/{deviationid} Fetch a deviation
    • /deviation/content Fetch full data that is not included in the main devaition object
    • /browse/morelikethis Fetch MoreLikeThis result for a seed deviation
    • /browse/newest Browse newest deviations
    • /browse/popular Browse popular deviations
    • /browse/hot Browse whats hot deviations
    • and all others routes ?
  • Revoke access / logout
  • Find a way to implement Authorization Code as an authentication method

damn's People

Contributors

romaindurand avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.