Add this line to your application's Gemfile:

gem 'ledger_sync'

And then execute:

$ bundle

Or install it yourself as:

$ gem install ledger_sync


To use LedgerSync, you must create an Operation. The operation will be ledger-specific and will require the following:

  1. Adaptor
  2. Resource(s)

The code may look like the following:

# First we create an adaptor, which is our connection to a ledger.
# Each ledger may require different keys, so check the
# documentation below for specifics.
adaptor =
access_token: access_token, # assuming this is defined
refresh_token: refresh_token, # assuming this is defined

# Create a resource on which to operate.  Some resources have
# relationships with other resources.  You can use
# `Util::ResourcesBuilder` to create resources and relationships from
# a structured hash.
resource =
name: 'Sample Customer',
email: ''

# Create the operation we want to perform.
operation =
adaptor: adaptor,
resource: resource

result = operation.perform # Returns a LedgerSync::OperationResult

if result.success?
resource = result.operation.resource
# Do something with resource
else # result.failure?
raise result.error

# Because QuickBooks Online uses Oauth 2, you must always be sure to
# save the access_token, refresh_token, and expirations as they can
# change with any API call.
result.operation.adaptor.ledger_attributes_to_save.each do |key, value|
# save values

How it Works

The Library Structure

This library consists of two important layers:

  1. Resources
  2. Adaptors


Resources are named ruby objects (e.g. Customer, Payment, etc.) with strict attributes (e.g. name, amount, etc.). They are a layer between your application and an adaptor. They can be validated using an adaptor. You can create and use the resources, and an adaptor will update resources as needed based on the intention and outcome of that operation.

You can find supported resources by calling LedgerSync.resources.

Resources have defined attributes. Attributes are explicitly defined. An error is thrown if an unknown attribute is passed to it. You can retrieve the attributes of a resource by calling LedgerSync::Customer.attributes.

A subset of these attributes may be a reference, which is simply a special type of attribute that references another resource. You can retrieve the references of a resource by calling LedgerSync::Customer.references.


Adaptors are ledger-specific ruby objects that contain all the logic to authenticate to a ledger, perform ledger-specific operations, and validate resources based on the requirements of the ledger. Adaptors contain a number of useful objects:

  • adaptor
  • operations
  • searchers


The adaptor handles authentication and requests to the ledger. Each adaptors initializer will vary based on the needs of that ledger.


Each adaptor defines operations that can be performed on specific resources (e.g. Customer::Operations::Update, Payment::Operations::Create). The operation defines two key things:

  • a Contract class which is used to validate the resource using the dry-validation gem
  • a perform instance method, which handles the actual API requests and response/error handling.

Note: Adaptors may support different operations for each resource type.


Searchers are used to search objects in the ledger. A searcher takes an adaptor, query string and optional pagination hash. For example, to search customer's by name:

searcher =
adaptor: adaptor # assuming this is defined,
query: 'test'

result = # returns a LedgerSync::SearchResult

if result.success?
resources = result.resources
# Do something with found resources
else # result.failure?
raise result.error

# Different ledgers may use different pagination strategies.  In order
# to get the next and previous set of results, you can use the following:
next_searcher = searcher.next_searcher
previous_searcher = searcher.previous_searcher

QuickBooks Online



LedgerSync offers an easy way to validate and parse webhook payloads. It also allows you to easily fetch the resources referenced. You can create and use a webhook with the following:

# Assuming `request` is the webhook request received from Quickbooks Online
webhook =
payload: # It accepts a JSON string or hash

verification_token = WEBHOOK_VERIFICATION_TOKEN # You get this token when you create webhooks in the QuickBooks Online dashboard
signature = request.headers['intuit-signature']
raise 'Not valid' unless webhook.valid?(signature: signature, verification_token: verification_token)

# Although not yet used, webhooks may include notifications for multiple realms
webhook.notifications.each do |notification|
puts notification.realm_id

# Multiple events may be referenced. do |event|
  puts event.resource # Returns a LedgerSync resource with the `ledger_id` set

  # Other helpful methods
  notification.find_operation_class(adaptor: your_quickbooks_adaptor_instance) # The respective Find class
  notification.find_operation(adaptor: your_quickbooks_adaptor_instance) # The initialized respective Find operation
  notification.find(adaptor: your_quickbooks_adaptor_instance) # Performs a Find operation for the resource retrieving the latest version from QuickBooks Online

# Other helpful methods
notification.resources # All resources for a given webhook across all events

# Other helpful methods # All events for a given webhook across all realms
webhook.resources # All events for a given webhook across all realms and events


Tips and More!

Keyword Arguments

LedgerSync heavily uses ruby keyword arguments so as to make it clear what values are being passed and which attributes are required. When this README says something like "the fun_function function takes the argument foo" that translates to fun_function(foo: :some_value).


Most objects in LedgerSync can be fingerprinted by calling the instance method fingerprint. For example:

puts # "b3eab7ec00431a4ae0468fee72e5ba8f"

puts == # true
puts == :foo).fingerprint # false
puts == # false

Fingerprints are used to compare objects. This method is used in de-duping objects, as it only considers the data inside and not the instance itself (as shown above).


Most objects in LedgerSync can be serialized by calling the instance method serialize. For example:


root: "LedgerSync::Payment/8eed81c0177801a001f2544f0c85e21d",
objects: {
  "LedgerSync::Payment/8eed81c0177801a001f2544f0c85e21d": {
    id: "LedgerSync::Payment/8eed81c0177801a001f2544f0c85e21d",
    object: "LedgerSync::Payment",
    fingeprint: "8eed81c0177801a001f2544f0c85e21d",
    data: {
      currency: nil,
      amount: nil,
      customer: {
        object: "reference",
        id: "LedgerSync::Customer/b3eab7ec00431a4ae0468fee72e5ba8f"
      external_id: "",
      ledger_id: nil,

  "LedgerSync::Customer/b3eab7ec00431a4ae0468fee72e5ba8f": {
    id: "LedgerSync::Customer/b3eab7ec00431a4ae0468fee72e5ba8f",
    object: "LedgerSync::Customer",
    fingeprint: "b3eab7ec00431a4ae0468fee72e5ba8f",
    data: {
      name: nil,
      email: nil,
      phone_number: nil,
      external_id: "",
      ledger_id: nil

The serialization of any object follows the same structure. There is a :root key that holds the ID of the root object. There is also an :objects hash that contains all of the objects for this serialization. As you can see, unique nested objects listed in the :objects hash and referenced using a "reference object", in this case:

object: "reference",
id: "LedgerSync::Customer/b3eab7ec00431a4ae0468fee72e5ba8f"


LedgerSync offers a test adaptor LedgerSync::Adaptors::Test::Adaptor that you can easily use and stub without requiring API requests. For example:

operation =
resource: 'Test Customer')

expect(operation).to be_valid

result = operation.perform
expect(result).to be_a(LedgerSync::OperationResult::Success)
expect(result).to be_success

expect { operation.perform }.to raise_error(PerformedOperationError)


After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to

Run bundle console to start and interactive console with the library already loaded.


To deploy a new version of the gem to RubyGems, you can use the script in the root. The script takes advantage of the bump gem. So you may call the script using any of the following:

# Version Format: MAJOR.MINOR.PATCH
./ patch # to bump X in 1.1.X
./ minor # to bump X in 1.X.1
./ major # to bump X in X.1.1


The site is viewable at:

Our marketing and documentation exist in the /site directory using Hugo. To get started, you will need to install hugo:

brew install hugo

Once installed, you can deploy changes by running ./site/ "COMMIT MESSAGE". The site public is generated and pushed to the dedicated site repository. Once deployed, the changes will be immediately reflected.


If you want to convert markdown (e.g. this README) to HTML, you can use grip:

grip --export


Bug reports and pull requests are welcome on GitHub at This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.


The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the LedgerSync project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.


A huge thank you to our maintainers: