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 2.0.0 and greater.
Table of Contents
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.
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::Client.new(api_key: "your-api-key") # To initialize a Lob object with an older API version lob = Lob::Client.new(api_key: "your-api-key", api_version: "2014-12-18")
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 interprets a number with a leading zero as an octal (i.e., base-8) number and converts it to a base-10 number. Thus
01000 is converted to the base-10 value
8*8*8=512). So not quoting 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 objects (checks, letters, postcards. etc.) as well as more complex examples that utilize other libraries and external files.
- Rate Limiting
- Cancellation Windows
- Scheduled Mailings
- HTML Templates
- Asset URLs
- US Verification API
- Int'l Verification API
- Postcards API
- Letters API
- Checks API
To contribute, please see the CONTRIBUTING.md file.
Tests are written using MiniTest, a testing library that comes with Ruby stdlib.
Here's how you can run the tests:
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