New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ncoinbase

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ncoinbase

Coinbase API consumer

latest
npmnpm
Version
0.1.0
Version published
Maintainers
1
Created
Source

NCoinbase

An OAuth2 compliant NodeJS Coinbase API library

Build Status

Quick Overview

  • Implements all the v1 API methods
  • Every API method allows callbacks or returns promises
  • Automatically refreshes expired tokens (and fires an event)

Installation

npm install ncoinbase

Usage

Setting up the client

var Coinbase = require('ncoinbase').Coinbase,
    api = new Coinbase({
      "id": "api_id",
      "secret": "api_secret",
      "redirect_uri": "http://localhost:4000/callback",
      "scope": "balance request"
    });

Creating and API consumer (user)

// Assuming we pulled the users credentials
// from the database and assigned them to 'user'
credentials = new Credentials(user);
consumer = api.createConsumer(credentials);

Accessing the API

req.coinbase.account_balance(function (err, resp) {
  console.log("My Account balance is: " + resp.amount );
});

Using Promises

req.coinbase.account_balance()
  .then(function (resp) {
    console.log("Resp", resp);
    res.send(resp);
  })
  .catch(function (err) {
    console.log("Err", err);
    res.send("API Request failed: " + err.message);
  });

Refreshing expired tokens

Expired tokens will be automatically refreshed when you attempt an API call. You can, and should, listen for this for the 'updatedCredentials' event and save the new credentials.

consumer.on('updatedCredentials', function (credentials) {
  user.credentials = credentials;
  user.save();
});
// Let's assume the users credentials are expired
// and we need to use the refresh token.
consumer.account_balance(function (err, resp) {
  // This will still work, but before the 'account_balance'
  // request is made, the credentials will be refreshed,
  // and the 'updatedCredentials' event will be fired.
  console.log("I have " + resp.amount + " many bitcoins!!!");
});

Example web application

Clone the repo and 'npm install'

git clone https://github.com/mdp/NCoinbase.git
cd NCoinbase
npm install

node example/server.js

Authenticate with Coinbase

Now visit http://localhost:4000 to authenticate

Exercise the API

After authenticating you should see your account details on the index page. You can also try http://localhost:4000/my_balance for your account balance.

The nitty gritty

The example app show several library features

Testing

git clone https://github.com/mdp/NCoinbase.git
cd NCoinbase
npm install
npm test

Keywords

coinbase

FAQs

Package last updated on 09 Oct 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts