Giter Club home page Giter Club logo

lob-node's Introduction

lob-node

NPM version Downloads Build Status Dependency Status Coverage Status

Node.js wrapper for the Lob.com API. See full Lob.com documentation here. For best results, be sure that you're using the latest version of the Lob API and the latest version of the Node wrapper.

Table of Contents

Getting Started

Here's a general overview of the Lob services available, click through to read more.

Please read through the official API Documentation to get a complete sense of what to expect from each endpoint.

Registration

First, you will need to first create an account at Lob.com and obtain your Test and Live API Keys.

Once you have created an account, you can access your API Keys from the Settings Panel.

Installation

lob-node can be installed through the npm:

$ npm install lob

To build and install from the latest source:

$ git clone [email protected]:lob/lob-node.git
$ npm install

Usage

var Lob = require('lob')('YOUR API KEY');

// change api version
var Lob = require('lob')('YOUR API KEY', { apiVersion: 'API-VERSION' });

// change internal defaults (e.g. host)
var options = {/* see options below */};
var Lob = require('lob')('YOUR API KEY', options);

// you can also just pass options
var options = { apiKey: 'foo', host: 'bar' };
var Lob = require('lob')(options);

// callback pattern
Lob.addresses.list(function (err, body) {
  if (err) return callback(err);
  return callback(null, body.data);
});

Additionally, every resource method returns a promise, so you don't have to use the regular callback. E.g.

var Lob = require('lob')('YOUR API KEY');

Lob.addresses.list()
.then(function (res) {
  console.log(res.data);
})
.catch(function (e) {
  console.log(e);
});

Options

The Lob constructor accepts an options object which may contain one or more of the following options:

  • apiVersion - Optionally set the version of the Lob API to use. Defaults to latest.
  • host - Override the default host API calls are issued to.
  • userAgent - Override the default userAgent.
  • headers - Edit the headers sent in all API calls.

Examples

We've provided various examples for you to try out here.

There are simple scripts to demonstrate how to create all the core Lob objects (checks, letters, postcards. etc.) as well as more complex examples that utilize other libraries and external files.

Accessing Response Headers

You can access response headers via a hidden _response property.

Lob.addresses.list()
.then(function (res) {
  res._response.headers['content-type'];
  // => "application/json; charset=utf-8"
});

You can also access headers from errors.

Lob.addresses.retrieve('adr_bad_id')
.catch(function (err) {
  err._response.headers['content-type'];
  // => "application/json; charset=utf-8"
});

API Documentation

Contributing

To contribute, please see the CONTRIBUTING.md file.

Testing

To run the tests with coverage:

npm test

To run the tests without coverage:

npm run test-no-cover

=======================

Copyright © 2013 Lob.com

Released under the MIT License, which can be found in the repository in LICENSE.txt.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.