Ruby wrapper for the Lob.com API. See the full Lob.com 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 Lob.com API.
Supports Ruby 1.9.3 and greater.
Table of Contents
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 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.
Add this line to your application's
And then execute:
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 http://lob.com :) config.api_version = "2014-12-18" # override the API version end
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 addresses._response.headers[:content_type] # => "application/json; charset=utf-8" addresses._response.headers[:rate_limit_window] # => "60" addresses._response.headers[:rate_limit_remaining] # => "1234"
You can also access headers from
begin @lob.objects.create(name: "Test", file: "https://lob.com/test.pdf", bad_param: "bad_value") rescue Lob::InvalidRequestError => e e._response.headers[:content_type] # => "application/json; charset=utf-8" end
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:
- Rate Limiting
- Asset URLs
- Postcards API
- Letters API
- Checks API
- Area Mail API
To contribute, please see the CONTRIBUTING.md file.
Tests are written using MiniTest, a testing library that comes with Ruby stdlib.
You'll need to pass in your Lob.com 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 Lob.com
Released under the MIT License, which can be found in the repository in