Ruby Wrapper for Lob API
Latest commit 145a474 Aug 29, 2016 @ami ami committed on GitHub update README


Build Status Gem Version Dependency Status Coverage Status Downloads

Ruby wrapper for the API. See the full API Documentation. For best results, be sure that you're using the latest version of the Lob API and the latest version of the ruby wrapper. This gem gives you an ActiveRecord-style syntax to use the API.

Supports Ruby 1.9.3 and greater.

Table of Contents

Getting Started

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


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

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


Add this line to your application's Gemfile:

gem 'lob'

And then execute:

$ bundle

Or manually install it yourself:

$ gem install lob


The library uses an ActiveRecord-style interface. You'll feel right at home.

For optional parameters and other details, refer to the docs here.

Initialization and Configuration

# To initialize a Lob object
@lob = Lob.load(api_key: "your-api-key")

# Alternatively, to set the API key for all calls in the future
Lob.api_key = "your-api-key"
@lob = Lob.load

Or if you want some detailed configuration

Lob.configure do |config|
  config.api_key = "your-api-key"    # get your own at :)
  config.api_version = "2014-12-18"  # override the API version

Caution: Pass zero-prefixed zip codes as strings

When using zip codes with zero-prefixes, always quote them. For example when specifying 02125, pass it as a string "02125", instead of an integer.

The Ruby interpreter assumes it's not of base-10 and tries to convert it to base-10 number. So that might result in an entirely different zip-code than intended.

Accessing Response Headers

You can access response headers via a hidden headers method on the response hash.

addresses = @lob.addresses.list

# => "application/json; charset=utf-8"

# => "60"

# => "1234"

You can also access headers from Lob::InvalidRequestErrors.

  @lob.objects.create(name: "Test", file: "", bad_param: "bad_value")
rescue Lob::InvalidRequestError => e
  # => "application/json; charset=utf-8"


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

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

API Documentation


To contribute, please see the file.


Tests are written using MiniTest, a testing library that comes with Ruby stdlib.

You'll need to pass in your API as the environment variable LOB_API_KEY, to run the tests. Be sure to use your Test API key, and not the Live one.

Here's how you can run the tests:

LOB_API_KEY=your_test_api_key bundle exec rake test

You can also configure, TravisCI for your fork of the repository and it'll run the tests for you, when you push.

Copyright © 2016

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