npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

plurk

v0.5.1

Published

Easy-to-use library for Plurk API 2.0. Parses JSON data automatically and handles comet channel.

Downloads

16

Readme

node-plurk

Easy-to-use library for Plurk API 2.0. Parses JSON data automatically and handles comet channel.

Installation

npm install plurk

Features

  • JSON data returned by Plurk API are parsed automatically
  • Helpers for comet channel API
  • Handle JSONP from comet channel (CometChannel.scriptCallback({});)
  • Instantiate new plurk client from json file
  • Parse limited_to property ("|id1||id2|") of plurk data to array
  • Base36 converter for plurk_id in Plurk URL
  • Extract user_id and plurk_id from Plurk URL

Getting Started

Initialize Client

var PlurkClient = require('plurk').PlurkClient;
var client = new PlurkClient(https, consumerKey, consumerSecret, accessToken, accessTokenSecret);
// https: true or false, for requesting request token and access token
// accessToken and accessTokenSecret are optional and can be set afterward.
client.accessToken = "MY_ACCESS_TOKEN";
client.accessTokenSecret = "MY_ACCESS_TOKEN_SECRET";

Or you can instantiate client from json config file:

var client = require('plurk').fromFileSync('config.json')

config.json:

{
    "https": true
    , "consumerKey": "MY_CONSUMER_KEY"
    , "consumerSecret": "MY_CONSUMER_SECRET"
    , "accessToken": "MY_ACCESS_TOKEN"
    , "accessTokenSecret": "MY_ACCESS_TOKEN_SECRET"
}

Again, accessToken and accessTokenSecret are optional.

Async read method is also available:

require('plurk').fromFile('config.json', function (err, client) {
	if (!err) {
		// ...
	}
});

Obtaining Request Token and Access Token

See examples/getToken.js for example usage.

PlurkClient.prototype.getRequestToken // alias: getOAuthRequestToken
PlurkClient.prototype.getAccessToken // alias: getOAuthAccessToken

These two methods are as same as methods on @ciaranj/node-oauth.

Calling Plurk API

See examples/getPublicProfile.js for example usage.

PlurkClient.prototype.rq = function(api, obj, callback [, accessToken, accessTokenSecret])
// send obj as null if no parameter required.
client.rq('Profile/getPublicProfile', {'user_id': "plurkapi"}, function(err, data) {
	if (!err) console.log(data);
});

API path can be one of following styles:

  • "/APP/Profile/getPublicProfile"
  • "APP/Profile/getPublicProfile"
  • "/Profile/getPublicProfile"
  • "Profile/getPublicProfile"

Note:

  1. For callback: function (err, data) { ... }
  2. Error object (err, data) is returned by node-oauth. This is null if no error occurred.
  3. For data (err, data), if JSON.parse failed internally, data would be null if err was null.
  4. And SyntaxError from JSON.parse would be catched and not being rethrowed.
  5. Instead, this exception (SyntaxError) would be assigned to err if err was null.
  6. However, normally invalid JSON and err (400, 404, 500) are presenting simultaneously.
  7. If so, err is not null and won't be changed by the presence of SyntaxError.

Short Version:

  • If you successfully called API. The function would automatically parse JSON for you.
  • On the other hand, if failed, err would be an object and the error JSON might not be parsed.

Interacting with Comet Channel

Helper functions were created for handling data of comet API.

See examples/getUserChannel.js for example usage.

Parsing Plurk limited_to

var limitedTo = require('plurk').limitedTo;

limitedTo.parse("|1||2|"); // returns [1, 2]

limitedTo.stringify([1, 2]); // returns "|1||2|"

Extract plurk_id and user_id from URL

var urlMatch = require('plurk').urlMatch;

var userId = urlMatch.user('http://www.plurk.com/ChronoPlurk');
// returns "ChronoPlurk"

var plainPlurkId = urlMatch.plurk('http://www.plurk.com/p/foo3ly')
// returns "foo3ly"

var plurkId = urlMatch.plurk('http://www.plurk.com/p/foo3ly', true)
// returns 948427846 (require('plurk').base36.decode)

Mobile version of URL works, too.

var userId = urlMatch.user('http://www.plurk.com/m/u/ChronoPlurk');

var plurkId = urlMatch.plurk('http://www.plurk.com/m/p/foo3ly', true)