appdotnet

Wrapper for the App.net HTTP Stream API, following node idioms.

appdotnet v0.2.0

A wrapper for the app.net http stream api, following node idioms.

app.net's api is not yet stable and is incomplete. Right now, this module supports all working parts of the official api (auth, user and post).

See https://github.com/appdotnet/api-spec for the state of the official api.

Please make sure to include unit tests, if you want to contribute to this project.

To run the unit tests, there are several steps to do:

  1. get an app.net access token with scope=stream%20email%20write_post%20follow%20messages%20export
  2. move config.example.json to config.json and insert access token
  3. just type npm test

All tests run against the official app.net api, so be sure to have an internet connection. When tests are timing out, try to increase the scripts.test -> --timeout value in package.json.

Running this tests will result in automatic post creation, operation and deletion. If you dislike this, be sure to remove the unit tests for object.createPost() and object.deletePost(). Those tests will mute and unmute one user as well, but you remove this line as well (object.muteUser() and object.unmuteUser()).

The following examples are generated from the unit testing code. Be sure to checkout the complete api description at the bottom.

There are some applications already using this library, checkout https://npmjs.org/package/appdotcouch and https://npmjs.org/package/appdotauth.

returns an uriencoded string.

var params = {
  client_id: '9ah9has9hsaf9hasf9hfsa9hfsa9hsafhhasoh',
  redirect_uri: 'http://localhost:3000/cb',
  scope: 'export write_post'
};
 
var expectedUri = AppDotNet.authHost
                + '/oauth/authenticate'
                + '?client_id=9ah9has9hsaf9hasf9hfsa9hfsa9hsafhhasoh'
                + '&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcb'
                + '&scope=export%20write_post'
                + '&response_type=code';
 
AppDotNet.createAuthenticationUri(params).should.equal(expectedUri);

returns a user object.

client.getUser(config.user_id, function (erruser) {
  should.exist(user);
  should.not.exist(err);
  done();
});

returns a user object.

client.followUser(config.user_id, function (erruser) {
  should.exist(user);
  should.not.exist(err);
  done();
});

returns a user object.

client.unfollowUser(config.user_id, function (erruser) {
  should.exist(user);
  should.not.exist(err);
  done();
});

returns an error when not authorized.

errorClient.listFollowing(config.user_id, function (errusers) {
  should.not.exist(users);
  should.exist(err);
  done();
});

returns an error when not authorized.

errorClient.listFollowers(config.user_id, function (errusers) {
  should.not.exist(users);
  should.exist(err);
  done();
});

returns a user object.

client.muteUser(config.user_id, function (erruser) {
  should.exist(user);
  should.not.exist(err);
  done();
});

returns a user object.

client.unmuteUser(config.user_id, function (erruser) {
  should.exist(user);
  should.not.exist(err);
  done();
});

returns user objects.

client.listMutedUsers(config.user_id, function (errusers) {
  should.exist(users);
  should.not.exist(err);
  done();
});

returns an auth object.

client.checkToken(function (errauth) {
  should.exist(auth);
  should.not.exist(err);
  done();
});

returns a post object.

client.createPost(config.post_data, function (errpost) {
  // save this for later use 
  savedPostId = post.id;
 
  should.exist(post);
  should.not.exist(err);
  done();
});

returns a post object.

client.retrievePost(savedPostId, function (errpost) {
  should.exist(post);
  should.not.exist(err);
  done();
});

returns post objects.

client.retrievePostReplies(savedPostId, {}, function (errposts) {
  should.exist(posts);
  should.not.exist(err);
  done();
});

returns a post object.

client.deletePost(savedPostId, function (errpost) {
  should.exist(post);
  should.not.exist(err);
  done();
});

returns post objects.

client.retrieveCreatedPosts(config.user_id, {}, function (errposts) {
  should.exist(posts);
  should.not.exist(err);
  done();
});

returns post objects.

client.retrieveMentions(config.user_id, {}, function (errposts) {
  should.exist(posts);
  should.not.exist(err);
  done();
});

returns post objects.

client.retrievePersonalStream({}, function (errposts) {
  should.exist(posts);
  should.not.exist(err);
  done();
});

returns post objects.

client.retrieveGlobalStream({}, function (errposts) {
  should.exist(posts);
  should.not.exist(err);
  done();
});

returns post objects.

client.retrieveTaggedPosts(config.tag, {}, function (errposts) {
  should.exist(posts);
  should.not.exist(err);
  done();
});

Create a new AppDotNet object with token.

  • String token valid app.net access token
  • Object new object

Host against which all request are made.

Host against which auth request are made.

Convenience construtor for AppDotNet.

  • String token valid app.net access token
  • Object new object

Create a valid authentication uri with params.

  • Object params for the get parameters
  • String uri

Request an access token with params and callback cb(err, auth).

  • Object params for the get parameters

  • Function cb

Retrieve the user with the given id and callback cb(err, user).

  • String id

  • Function cb

Follow a user with the given id and callback cb(err, user).

  • String id

  • Function cb

Unfollow a user with the given id and callback cb(err, user).

  • String id

  • Function cb

List users a user is following with the given id and callback cb(err, users).

  • String id

  • Function cb

List users following a user with the given id and callback cb(err, users).

  • String id

  • Function cb

Mute a user with the given id and callback cb(err, user).

  • String id of the user

  • Function cb

Unmute a user with the given id and callback cb(err, user).

  • String id of the user

  • Function cb

List muted users and callback cb(err, user).

  • Function cb

Check current access token and callback cb(err, auth).

  • Function cb

Create a post with data and callback cb(err, post).

  • Object data for the post

  • Function cb

Retrieve a post with id and callback cb(err, post).

  • String id of the post

  • Function cb

Retrieve the replies to a post with id using filters and callback cb(err, posts).

  • String id of a post

  • Object filters

  • Function cb

Delete a post with id and callback cb(err, post).

  • String id of the post

  • Function cb

Retrieve posts created by a user with id using filters and callback cb(err, posts).

  • String id of a user

  • Object filters

  • Function cb

Retrieve posts mentioning a user with id using filters and callback cb(err, posts).

  • String id of a user

  • Object filters

  • Function cb

Retrieve logged in user's personalized stream using filters and callback cb(err, posts).

  • Object filters

  • Function cb

Retrieve the global stream using filters and callback cb(err, posts).

  • Object filters

  • Function cb

Retrieve tagged posts with tag using filters and callback cb(err, posts).

  • String tag

  • Object filters

  • Function cb