0.0
The project is in a healthy, maintained state
Ruby library for the FreeAgent v2 API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

~> 0.6.0
~> 2.11
 Project Readme

FreeAgentRB

This library is a work in progress

FreeAgentRB is a Ruby library for interacting with the FreeAgent v2 API.

Installation

Add this line to your application's Gemfile:

gem "freeagentrb"

Usage

Set Client Details

Firstly you'll need to set an Access Token, which would be created from OAuth. See this page for more info.

@client = FreeAgent::Client.new(access_token: "", sandbox: true)

Rate Limiting

The library automatically tracks rate limiting based on the FreeAgent API's Retry-After header when you receive a 429 (Too Many Requests) response. You can access rate limit information through the client's rate limiter:

# Initialize with optional logger
require "logger"
logger = Logger.new($stdout)
@client = FreeAgent::Client.new(access_token: "", sandbox: true, logger: logger)

# Check rate limit status
@client.rate_limiter.status
# => "Not rate limited" or "Rate limited. Retry in 60 seconds"

# Check if currently rate limited
@client.rate_limiter.rate_limited?
# => true/false

# Get seconds until rate limit resets
@client.rate_limiter.reset_in
# => 60 (seconds remaining)

# Manually wait if rate limited
@client.rate_limiter.wait_if_rate_limited

For testing rate limiting in the sandbox, enable the X-RateLimit-Test header:

# This artificially lowers sandbox API calls to 5 requests/minute
@client = FreeAgent::Client.new(
  access_token: "",
  sandbox: true,
  enable_rate_limit_test: true
)

OAuth

This library includes the ability to create, refresh and revoke OAuth tokens.

# Firstly, set the client details
@oauth = FreeAgent::OAuth.new(sandbox: true, client_id: "", client_secret: "")

# Generate an authorisation URL
# state can be nil
@oauth.authorise_url(redirect: "https://mysite.com/auth", state: "something")

# Create a Token from the authorisation code
@oauth.create(token: "abc123", redirect: "https://mysite.com/auth")

# Refresh a Token
@oauth.refresh(refresh_token: "abc123")

Bank Accounts

@client.bank_accounts.list
@client.bank_accounts.list(view: "paypal_accounts")
@client.bank_accounts.retrieve(id: "12345")
@client.bank_accounts.create type: "StandardBankAccount", name: "My Account", opening_balance: "10"
@client.bank_accounts.update id: "12345", name: "My Other Account"