Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Note

This is an incomplete conversion of https://github.com/duerig/appnet.js. Places, and App stream references are not valid (not implemented by the Pnut.io API yet).

pnut.js

A library for interacting with pnut.io written in JavaScript. Exported as both a jQuery and a Node.js module.

In jQuery, every method is invoked from the object found at $.pnut. Using Node.js, that object is the sole export. See the examples below.

Most function map one-to-one onto the HTTP endpoints of the pnut.io API. The exceptions are a few utility functions at the top level for setting and checking authorization tokens, and the all.* functions which are a convenient way to get an entire stream.

Download

When using this package with jQuery, the latest development version can be obtained at:

JQuery Example

$.pnut.authorize("MY_USER_TOKEN");
var promise = $.pnut.post.getGlobal({ include_raw: 1 });
promise.then(function (response) {
// On success, response is the json object returned by the pnut.io server.
// See: http://developers.pnut.io/docs/basics/responses/#response-envelope
console.dir(response.data);
console.dir(response.meta);
return $.pnut.post.getThread('1000', { count: 10 });
}).then(function (response) {
console.dir(response);
}, function (response) {
// On failure, response is the jQuery response object.
// See: http://api.jquery.com/Types/#jqXHR
console.log('Error!');
});

Node.js Example

var pnut = require('pnut');
pnut.authorize("MY_USER_TOKEN");
var promise = pnut.post.getGlobal({ include_raw: 1 });
promise.then(function (response) {
// On success, response is the json object returned by the pnut.io server.
// ~~See: http://pnut.io/docs/basics/responses/#response-envelope~~
console.dir(response.data);
console.dir(response.meta);
return pnut.post.getThread('1000', { count: 10 });
}).then(function (response) {
console.dir(response);
}, function (response) {
// On failure, response is the q-io response object.
// See: https://github.com/kriskowal/q-io#response
console.dir(response.status);
console.log('Error!');
});

Reference

Utility Functions

MethodParametersDescription
authorize( userToken, appToken )Sets the user and/or app tokens. Required for various calls as noted below.
deauthorize( )Clears all tokens.
isLogged( )Returns true if either a user or an app token has been previously provided.
isApp( )Return true if an app token was previously provided.
isUser( )Returns true if a user token was previously provided.

'all' endpoints

$.pnut.all provides some convenience functions for fetching the contents of an entire stream, automatically using pagination parameters to make multiple calls to the API when necessary.

Caution These functions will keep calling and not callback until the entire stream is fetched. If the stream is big, this can be a long wait. Only use these when you are confident that the stream can be fetched with a few calls.

These functions all return a mock response envelope with a 'data' field containing an array of the entire set of objects fetched. If they fail part of the way through, your rejection method will be called with the failed response object.

MethodParametersMethod Used
getSubscriptions( args )channel.getUserSubscribed
getMessages( channel_id, args )message.getChannel
getUserPosts( user_id, args )post.getUser
getFollowing( user_id, args )user.getFollowing
getChannelList( channel_ids, args )channel.getList
getUserList( user_ids, args )user.getList

pnut.io endpoints

These endpoints all return the result of invoking $.ajax() which is a jQuery promise. You are then free to attach your own callbacks to it etc. Typically the response you receive will be a response envelope with a 'data' field containing the results of your operation on success and a 'meta' field with the response code and any other information associated with your query.

MethodParametersDescriptionToken
user.get( user_id, args )Retrieve a UserNone
user.update( user, args )Update a UserUser
user.partialUpdate( user, args )Partially Update a UserUser
user.getAvatar( user_id, args )Retrieve a User's avatar imageNone
user.updateAvatar( avatar, args )Update a User's avatar imageUser
user.getCover( user_id, args )Retrieve a User's cover imageNone
user.updateCover( cover, args )Update a User's cover imageUser
user.follow( user_id, args )Follow a UserUser
user.unfollow( user_id, args )Unfollow a UserUser
user.mute( user_id, args )Mute a UserUser
user.unmute( user_id, args )Unmute a UserUser
user.block( user_id, args )Block a UserUser
user.unblock( user_id, args )Unblock a UserUser
user.getList( user_ids, args )Retrieve multiple UsersAny
user.search( args )Search for UsersAny
user.getFollowing( user_id, args )Retrieve Users a User is followingAny
user.getFollowers( user_id, args )Retrieve Users following a UserAny
user.getFollowingIds( user_id, args )Retrieve IDs of Users a User is followingAny
user.getFollowerIds( user_id, args )Retrieve IDs of Users following a UserAny
user.getMuted( user_id, args )Retrieve muted UsersAny
user.getMutedList( user_ids, args )Retrieve muted User IDs for multiple UsersApp
user.getBlocked( user_id, args )Retrieve blocked UsersAny
user.getBlockedList( user_ids, args )Retrieve blocked User IDs for multiple UsersApp
user.getReposters( post_id, args )Retrieve Users who reposted a PostAny
user.getStars( post_id, args )Retrieve Users who starred a PostAny
post.create( post, args )Create a PostUser
post.get( post_id, args )Retrieve a PostNone
post.destroy( post_id, args )Delete a PostUser
post.repost( post_id, args )Repost a PostUser
post.unrepost( post_id, args )Unrepost a PostUser
post.bookmark( post_id, args )Star a PostUser
post.unbookmark( post_id, args )Unstar a PostUser
post.getList( post_ids, args )Retrieve multiple PostsAny
post.getUser( user_id, args )Retrieve a User's postsNone
post.getUserBookmarked( user_id, args )Retrieve a User's starred postsNone
post.getUserMentions( user_id, args )Retrieve Posts mentioning a UserAny
post.getHashtag( hashtag, args )Retrieve Posts containing a hashtagNone
post.getThread( post_id, args )Retrieve replies to a PostAny
post.getUserStream( args )Retrieve a User's personalized streamUser
post.getUnifiedStream( args )Retrieve a User's unified streamUser
post.getGlobal( args )Retrieve the Global streamUser
post.report( post_id, args )Report a PostUser
post.search( args )Search for PostsAny
channel.getUserSubscribed( args )Get current user's subscribed channelsUser
channel.create( channel, args )Create a ChannelUser
channel.get( channel_id, args )Retrieve a ChannelVaries
channel.getList( channel_ids, args )Retrieve multiple ChannelsVaries
channel.getCreated( args )Retrieve my ChannelsUser
channel.getUnreadCount( args )Retrieve number of unread PM ChannelsUser
channel.getUnreadBroadcastCount( args )Retrieve number of unread Broadcast ChannelsUser
channel.markBroadcastChannelsRead( args )Mark all Broadcast Channels as readUser
channel.update( channel_id, channel, args )Update a ChannelUser
channel.deactivate( channel_id, channel, args )Deactivate a ChannelUser
channel.subscribe( channel_id, args )Subscribe to a ChannelUser
channel.unsubscribe( channel_id, args )Unsubscribe from a ChannelUser
channel.getSubscribers( channel_id, args )Retrieve users subscribed to a ChannelNone
channel.getSubscriberIds( channel_id, args )Retrieve user ids subscribed to a ChannelNone
channel.getSubscriberIdList( channel_ids, args )Retrieve user ids subscribed to multiple ChannelsAny
channel.mute( channel_id, args )Mute a ChannelUser
channel.unmute( channel_id, args )Unmute a ChannelUser
channel.getMuted( args )Get current user's muted ChannelsUser
channel.search( args )Search for ChannelsUser
message.getChannel( channel_id, args )Retrieve the Messages in a ChannelNone
message.create( channel_id, message, args )Create a MessageUser
message.get( channel_id, message_id, args )Retrieve a MessageNone
message.getList( message_ids, args )Retrieve multiple MessagesNone
message.getUser( args )Retrieve my MessagesUser
message.destroy( channel_id, message_id, args )Delete a MessageUser
file.create( file, args )Create a FileUser
file.createPlaceholder( file, args )Create a File PlaceholderUser
file.get( file_id, args )Retrieve a FileUser
file.getList( file_ids, args )Retrieve multiple FilesUser
file.destroy( file_id, args )Delete a FileUser
file.getUser( args )Retrieve my FilesUser
file.update( file_id, file, args )Update a FileUser
file.getContent( file_id, args )Get File contentUser
file.setContent( file_id, content, args )Set File contentUser
AppStream.create( stream, args )Create a StreamApp
AppStream.get( stream_id, args )Retrieve a StreamApp
AppStream.update( stream_id, stream, args )Update a StreamApp
AppStream.destroy( stream_id, args )Delete a StreamApp
AppStream.getAll( args )Retrieve all Streams for the current TokenApp
AppStream.destroyAll( args )Delete all Streams for the current TokenApp
UserStream.destroy( connection_id, args )Delete a User Streamuser
UserStream.destroySubscription( connection_id, subscription_id, args )Delete a User Stream Subscriptionuser
filter.create( filter, args )Create a FilterUser
filter.get( filter_id, args )Retrieve a FilterUser
filter.update( filter_id, filter, args )Update a FilterUser
filter.destroy( filter_id, args )Delete a FilterUser
filter.getUser( args )Get the current User's FiltersUser
filter.destroyUser( args )Delete the current User's FiltersUser
interaction.get( args )Retrieve Interactions with the current UserUser
marker.update( marker, args )Update a Stream MarkerUser
text.process( post_or_message, args )Process textAny
token.get( args )Retrieve the current tokenAny
token.getAuthorizedIds( args )Retrieve authorized User IDs for an appApp
token.getAuthorized( args )Retrieve authorized User tokens for an appApp
place.get( factual_id, args )Retrieve a PlaceAny
place.search( args )Search for PlacesUser
explore.show( args )Retrieve all Explore StreamsNone
explore.get( slug, args )Retrieve an Explore StreamNone
config.get( args )Retrieve the Configuration ObjectNone

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages