A financial service SDK for rails for innovative accounting solutions providers.
Lockstep automates accounting workflows to improve your operational efficiency and cash flow. Accelerate payments through automated customer communications, enhanced collections activity management, and innovative forecasting and reporting.
lockstep_rails makes it easy to interact with lockstep.io's REST API. It adheres to the ActiveRecord pattern. LockstepRails is fully ActiveModel compliant, meaning you can use validations and Rails forms.
Ruby/Rails developers should feel right at home.
If you're used to Lockstep::Contact.create(:email_address => "[email protected]")
, then this is for you.
- ActiveRecord-like API, almost no learning curve
- Validations
- Rails forms and scaffolds just work
Add this line to your application's Gemfile:
gem 'lockstep_rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install lockstep_rails
The gem is available as open source under the terms of the MIT License.
- Lockstep::Account
- Lockstep::ApiKey
- Lockstep::AppEnrollment
- Lockstep::Attachment
- Lockstep::Connection
- Lockstep::Contact
- Lockstep::CustomFieldValue
- Lockstep::CustomerSummary
- Lockstep::CompanyMagicLinkSummary
- Lockstep::FeatureFlag
- Lockstep::Invoice
- Lockstep::InvoiceAtRiskSummary
- Lockstep::InvoiceSummary
- Lockstep::MagicLink
- Lockstep::MagicLinkSummary
- Lockstep::Note
- Lockstep::Payments
- Lockstep::PaymentApplied
- Lockstep::PaymentSummary
- Lockstep::ReportApAgingHeader
- Lockstep::ReportArAgingHeader
- Lockstep::ReportCashflow
- Lockstep::ReportDailyPayableOutstanding
- Lockstep::ReportDailyPayableOutstandingSummary
- Lockstep::ReportDailySalesOutstanding
- Lockstep::ReportPayableComingDue
- Lockstep::ReportPayablesComingDueSummary
- Lockstep::ReportPayableSummary
- Lockstep::ReportRiskRate
- Lockstep::ServiceFabricPayment
- Lockstep::Status
- Lockstep::SyncRequest
- Lockstep::Transaction
- Lockstep::TranscriptionValidationRequest
- Lockstep::User
- Lockstep::WorkflowStatus
lockstep_rails
supports the standard CRUD interface of ActiveRecord.
You can create a record by calling new
or create
Lockstep::Contact.create(email_address: "[email protected]")
You can create records from associations as well. This will automatically association the relationship with the parent record
connection = Lockstep::Connection.find(company_id: "17544da8-7be8-4ee2-8c62-cbd81428c68b")
connection.contacts.create(email_address: "[email protected]")
Similar to ActiveRecord, you can update a record by calling update
, update_attributes
or update_attribute
Examples:
connection = Lockstep::Connection.find(company_id: "17544da8-7be8-4ee2-8c62-cbd81428c68b")
connection.update(company_name: "New name")
# Or
connection.update_attributes(company_name: "New name")
# Or
connection.update_attribute(:company_name, "New name")
Similar to ActiveRecord, you can find a record by calling find
, find_by
or find_by_company_id
Examples:
connection = Lockstep::Connection.find(company_id: "17544da8-7be8-4ee2-8c62-cbd81428c68b")
connection.update(company_name: "New name")
# Or
connection.update_attributes(company_name: "New name")
# Or
connection.update_attribute(:company_name, "New name")
Similar to ActiveRecord, you can search for records by calling where
.
Unless you are accessing the record via first
, you will have to call execute
to fetch the records
Examples:
Lockstep::Connection.where(status: "Active").execute
You can chain queries while calling where.
Lockstep::Connection.where(status: "Active").where(default_currency_code: "USD").execute
You can build an or query by calling or
Lockstep::Connection.where(status: "Active").or(Lockstep::Connection.where(default_currency_code: "USD")).execute
Searchlight supports building complex comparisons in the query.
Suffice | Searchlight Query | Example |
---|---|---|
_eq | Equals | where(name_eq: "Test Name") |
_gt | Greater Than | where(amount_gt: 100) |
_ge | Greater Than Or Equal | where(amount_ge: 100) |
_lt | Less Than | where(amount_lt: 100) |
_le | Less Than Or Equal | where(amount_le: 100) |
_ne | Not Equal | where(name_ne: "tak") |
_in | IN | where(name_in: ["tik", "tok"]) |
_contains | CONTAINS | where(name_contains: "kit") |
_starts_with | STARTSWITH | where(name_starts_with: "tik") |
_ends_with | ENDSWITH | where(name_ends_with: "tok") |
_is | IS | where(name_is: nil) where(name_is: "NOT NULL") |
Using the rails standard queries generates searchlight compatible queries. if you wish, you can always write raw Searchlight queries by passing a string in the where block
Lockstep::Connection.where("isActive is true OR default_currency_code in ('USD', 'INR')").execute
You can destroy a single object by calling destroy method on one object Lockstep::Connection.find(company_id: "17544da8-7be8-4ee2-8c62-cbd81428c68b").destroy
You can also destroy multiple objects at once by calling it on the model class and passing an array of relevant ids
Lockstep::Connection.destroy_all(id: ["17544da8-7be8-4ee2-8c62-cbd81428c68b"])
You can fetch the count of available records by calling count
Lockstep::Connection.count
# 1000
Lockstep::Connection.where(status: "Active").count
# 100
records , count = Lockstep::Connection.where(status: "active").with_count(true).execute
# records get the records for the query and the with count if used will return the total number of records present for that query.
You can limit the number of records being fetched by passing limit
The default limit is 200.
Lockstep::Connection.limit(100).execute
Lockstep::Connection.where(status: "Active").limit(100).execute
You can paginate the records by passing the page
Lockstep::Connection.page(2).execute
Lockstep::Connection.where(status: "Active").limit(100).page(2).execute
If you would like to link the Lockstep::ApiRecord
with an ActiveRecord::Base
, you can do so by including Lockstep::ActiveRecords::Association
This gives you access to 2 methods for defining relationships
- lockstep_has_many
- lockstep_belongs_to
class User < ActiveRecord::Base
include Lockstep::ActiveRecords::Association
lockstep_has_many :connections, class_name: "Lockstep::Connection", primary_key: 'company_id', foreign_key: "lockstep_company_id"
lockstep_belongs_to :account, class_name: "Lockstep::Account", primary_key: 'company_id', foreign_key: "lockstep_company_id"
end
You could define your own loader for fetching the records by passing a loader
Proc
class User < ActiveRecord::Base
include Lockstep::ActiveRecords::Association
lockstep_has_many :connections, class_name: "Lockstep::Connection", loader: -> (record) { Lockstep::Connection.where(is_active: true).where(company_id: record.lockstep_company_id) }
lockstep_belongs_to :account, class_name: "Lockstep::Account", loader: -> (record) { Lockstep::Account.where(is_active: true).first }
end
To update the schema to the latest one on https://api.dev.lockstep.io/swagger/v1/swagger.json, run
bundle exec rake update_api_schema