Node.js DeviantArt API client
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);
});
});
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.
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.
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 :
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.
All these methods are asynchronous.
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.
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.
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.
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.
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 optionalfolderId
andoffset
keys.callback
: called with two parameters : error (null
if none) and an array containing the folder's deviations.
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 requiredusername
key and an optionaloffset
key.callback
: called with two parameters : error (null
if none) and an array containing the specified user folders.
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.
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.
- 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