appdotnet v0.2.0
A wrapper for the app.net http stream api, following node idioms.
Current State
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.
Developers
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:
- get an app.net access token with
scope=stream%20email%20write_post%20follow%20messages%20export
- move
config.example.json
toconfig.json
and insert access token - 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()).
Examples
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.
AppDotNet
AppDotNet.createAuthenticationUri()
returns an uriencoded string.
var params = client_id: '9ah9has9hsaf9hasf9hfsa9hfsa9hsafhhasoh' redirect_uri: 'http://localhost:3000/cb' scope: 'export write_post'; var expectedUri = AppDotNetauthHost + '/oauth/authenticate' + '?client_id=9ah9has9hsaf9hasf9hfsa9hfsa9hsafhhasoh' + '&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcb' + '&scope=export%20write_post' + '&response_type=code'; AppDotNetshould;
object.getUser()
returns a user object.
client;
object.followUser()
returns a user object.
client;
object.unfollowUser()
returns a user object.
client;
object.listFollowing()
returns an error when not authorized.
errorClient;
object.listFollowers()
returns an error when not authorized.
errorClient;
object.muteUser()
returns a user object.
client;
object.unmuteUser()
returns a user object.
client;
object.listMutedUsers()
returns user objects.
client;
object.checkToken()
returns an auth object.
client;
object.createPost()
returns a post object.
client;
object.retrievePost()
returns a post object.
client;
object.retrievePostReplies()
returns post objects.
client;
object.deletePost()
returns a post object.
client;
object.retrieveCreatedPosts()
returns post objects.
client;
object.retrieveMentions()
returns post objects.
client;
object.retrievePersonalStream()
returns post objects.
client;
object.retrieveGlobalStream()
returns post objects.
client;
object.retrieveTaggedPosts()
returns post objects.
client;
API
AppDotNet()
Create a new AppDotNet object with token
.
Params:
- String token valid app.net access token
Return:
- Object new object
AppDotNet.host
Host against which all request are made.
AppDotNet.authHost
Host against which auth request are made.
AppDotNet.create(token)
Convenience construtor for AppDotNet
.
Params:
- String token valid app.net access token
Return:
- Object new object
AppDotNet.createAuthenticationUri(params)
Create a valid authentication uri with params
.
Params:
- Object params for the get parameters
Return:
- String uri
AppDotNet.requestAccessToken(params, cb)
Request an access token with params
and callback cb(err, auth)
.
Params:
-
Object params for the get parameters
-
Function cb
object.getUser(id, cb)
Retrieve the user with the given id
and callback cb(err, user)
.
Params:
-
String id
-
Function cb
object.followUser(id, cb)
Follow a user with the given id
and callback cb(err, user)
.
Params:
-
String id
-
Function cb
object.unfollowUser(id, cb)
Unfollow a user with the given id
and callback cb(err, user)
.
Params:
-
String id
-
Function cb
object.listFollowing(id, cb)
List users a user is following with the given id
and callback cb(err, users)
.
Params:
-
String id
-
Function cb
object.listFollowers(id, cb)
List users following a user with the given id
and callback cb(err, users)
.
Params:
-
String id
-
Function cb
muteUser(id, cb)
Mute a user with the given id
and callback cb(err, user)
.
Params:
-
String id of the user
-
Function cb
unmuteUser(id, cb)
Unmute a user with the given id
and callback cb(err, user)
.
Params:
-
String id of the user
-
Function cb
listMutedUsers(cb)
List muted users and callback cb(err, user)
.
Params:
- Function cb
object.checkToken(cb)
Check current access token and callback cb(err, auth)
.
Params:
- Function cb
object.createPost(data, cb)
Create a post with data
and callback cb(err, post)
.
Params:
-
Object data for the post
-
Function cb
object.retrievePost(id, cb)
Retrieve a post with id
and callback cb(err, post)
.
Params:
-
String id of the post
-
Function cb
object.retrievePostReplies(id, filters, cb)
Retrieve the replies to a post with id
using filters
and callback cb(err, posts)
.
Params:
-
String id of a post
-
Object filters
-
Function cb
object.deletePost(id, cb)
Delete a post with id
and callback cb(err, post)
.
Params:
-
String id of the post
-
Function cb
object.retrieveCreatedPosts(id, filters, cb)
Retrieve posts created by a user with id
using filters
and callback cb(err, posts)
.
Params:
-
String id of a user
-
Object filters
-
Function cb
object.retrieveMentions(id, filters, cb)
Retrieve posts mentioning a user with id
using filters
and callback cb(err, posts)
.
Params:
-
String id of a user
-
Object filters
-
Function cb
object.retrievePersonalStream(filters, cb)
Retrieve logged in user's personalized stream using filters
and callback cb(err, posts)
.
Params:
-
Object filters
-
Function cb
object.retrieveGlobalStream(filters, cb)
Retrieve the global stream using filters
and callback cb(err, posts)
.
Params:
-
Object filters
-
Function cb
object.retrieveTaggedPosts(tag, filters, cb)
Retrieve tagged posts with tag
using filters
and callback cb(err, posts)
.
Params:
-
String tag
-
Object filters
-
Function cb