Catalog npm
Back to packageRELEASE DETAILS

0.7.2

npm

3scale-cm

Client for 3Scale Networks API

3scaleapiauthorizationweb
Published3 Aug 2016
Direct dependencies7
Transitive dependenciesNot calculated

README

Current package documentation

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

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 7

Native requirements
7 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
es6-promise
Environment
{
  "local_name": "es6-promise",
  "alias": false,
  "peer_metadata": null
}
^3.1.2runtime
https-proxy-agent
Environment
{
  "local_name": "https-proxy-agent",
  "alias": false,
  "peer_metadata": null
}
^1.0.0runtime
qs
Environment
{
  "local_name": "qs",
  "alias": false,
  "peer_metadata": null
}
^5.2.0runtime
xml2js
Environment
{
  "local_name": "xml2js",
  "alias": false,
  "peer_metadata": null
}
^0.4.16runtime
coffee-script
Environment
{
  "local_name": "coffee-script",
  "alias": false,
  "peer_metadata": null
}
^1.10.0development
mocha
Environment
{
  "local_name": "mocha",
  "alias": false,
  "peer_metadata": null
}
^2.3.4development
nock
Environment
{
  "local_name": "nock",
  "alias": false,
  "peer_metadata": null
}
^3.3.2development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "7798e3613aabb377d6b81821e56995cbfb41d44d",
  "tarball": "https://registry.npmjs.org/3scale-cm/-/3scale-cm-0.7.2.tgz",
  "integrity": "sha512-bF+RQR+tmCAIBbKCNwe52/YDiWZHQ2b95+HHEmzHZBJ59uhkZ80yjCBhkq8DYBoIc7DTaPSjQACbrj1uI80d8g==",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEYCIQCW3TJSr/2gKOuoHdp0bcJ8ejJ4ITUyoz3sHnZTuqYOJwIhALLCy7f5aJ/uF+pnpw1ULg38t09e/5D8bQKJriE10Ukr"
    }
  ]
}

Repository

PENDING
3scale/3scale_ws_api_for_nodejs

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:52 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:8fd4d508f8fd76dd94f64891dfe9a6253602e8bf35bd968adace2ce428b04196

Other collected versions

0.5.13 AugView all collected versions →