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

3scale-cm

v0.7.2

Published

Client for 3Scale Networks API

Downloads

11

Readme

3scale integration plugin for JavaScript/CoffeeScript/Node.js applications Build Status

3scale is an API Infrastructure service which handles API Keys, Rate Limiting, Analytics, Billing Payments and Developer Management. Includes a configurable API dashboard and developer portal CMS. More product stuff at http://www.3scale.net/, support information at http://support.3scale.net/.

Installation

The module is delivered through the package manager npm, so that the installation should be easy as: npm install 3scale

Requirements

Starting at version 0.6.0, this plugin requires using Node.js versions 0.10.x or higher.

Synopsis

This plugin supports the 3 main calls to the 3scale backend:

  • authrep grants access to your API and reports the traffic on it in one call.
  • authorize grants access to your API.
  • report reports traffic on your API.

3scale supports 3 authentication modes: App Id, User Key and OAuth. The first two are similar on their calls to the backend, they support authrep. OAuth differs in its usage two calls are required: first authorize then report.

Usage

Authrep

Authrep is a 'one-shot' operation to authorize an application and report the associated transaction at the same time. The main difference between this call and the regular authorize call is that usage will be reported if the authorization is successful. Read more about authrep at the active docs page on the 3scale's support site.

Here is an example assuming that you are using the app_id/app_key authentication mode:

var Client = require('3scale').Client;

client = new Client("your provider key",["3Scale URL(default : su1.3scale.net)"],["proxy URL"]);

client.authrep({"app_id": "your application id", "app_key": "your application key", "usage": { "hits": 1 } }, function(response){
  console.log(response);
});

In case you have your API authentication configured in 3scale to use the user_key mode, this would be the equivalent to the example above:

var Client = require('3scale').Client;

client = new Client("your provider key");

client.authrep_with_user_key({ "user_key": "your key", "usage": { "hits": 1 } }, function(response){
  console.log(response);
});

Authorize and Report

You can alternatively use the authorize and report methods to do the same in two separate calls. Note that the report method supports sending the usage for multiple transactions in a single call.

var Client = require('3scale').Client;

client = new Client("your provider key");

client.authorize({ "app_id": "your application id", "app_key": "your application key" }, function(response){
  if (response.is_success()) {
    var trans = [{ "app_id": "your application id", "usage": { "hits": 3 } }];
    client.report(trans, function (response) {
      console.log(response);
    });
  } 
  else {
    console.log("Error: " + response.error_code + " msg: " + response.error_msg);
  }
});

Here is the same example for the user_key authentication pattern:

var Client = require('3scale').Client;

client = new Client("your provider key");

client.authorize_with_user_key({ "user_key": "your key" }, function(response){
  if (response.is_success()) {
    var trans = [{ "user_key": "your key", "usage": { "hits": 3 }}];
    client.report(trans, function (response) {
      console.log(response);
    });
  } 
  else {
    console.log("Error: " + response.error_code + " msg: " + response.error_msg);
  }
});

Note that the report method supports sending the usage for multiple transactions in a single call.

var trans = [
              { "app_id": "your application id", "usage": {"hits": 1}},
              { "app_id": "your application id", "usage": {"hits": 1000}}
             ]

client.report(trans, function(response){
  console.log(response);
});

OAuth

If you set OAuth as the authentication pattern for your API in 3scale, you will need to take the separate authorize and report approach (i.e. there is no authrep for OAuth).

var Client = require('3scale').Client;

client = new Client("your provider key");

client.oauth_authorize({"app_id": "your application id"}, function(response){
  if (response.is_success()) {
    var trans = [{"app_id": "your application id", "usage": {"hits": 3}}];
    client.report(trans, function (response) {
      console.log(response);
    });
  } 
  else {
    console.log("Error: " + response.error_code + " msg: " + response.error_msg);
  }
});

To test

To run tests: npm test or vows test/* --spec from the root directory of the project. Please note that you will first need to set the following environment variables using your own 3scale keys:

  • TEST_3SCALE_PROVIDER_KEY
  • TEST_3SCALE_APP_KEY
  • TEST_3SCALE_APP_ID