dAmn
Node.js DeviantArt API client
Quick start
var dAmn = require('damn'),
da = dAmn.public(1234, 'cl13nt_s3cr3t');
da.getDailyDeviations(function(err, data) {
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(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 :
To instanciate a "private" client you may use dAmn.private
method :
dAmn.private('username', 'password', 1234, 'https://www.example.com', function(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.
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