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

README.md

lob-ruby

Build Status Gem Version Dependency Status Coverage Status Downloads

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

Getting Started

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

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

Add this line to your application's Gemfile:

gem 'lob'

And then execute:

$ bundle

Or manually install it yourself:

$ gem install lob

Usage

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 Lob::InvalidRequestErrors.

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

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 products (checks, letters, postcards, jobs etc.), as well as more complex examples that utilize other libraries and external files:

API Documentation

Contributing

To contribute, please see the CONTRIBUTING.md file.

Testing

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 LICENSE.txt.