mandarvaze / lockstep-sdk-ruby-rails

Lockstep-sdk-ruby-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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lockstep

A financial service SDK for rails for innovative accounting solutions providers.

Who are we?

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

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 => "test@emaildomain.com"), then this is for you.

Features

  • ActiveRecord-like API, almost no learning curve
  • Validations
  • Rails forms and scaffolds just work

Installation

Add this line to your application's Gemfile:

gem 'lockstep_rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install lockstep_rails

License

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

Usage

Available Records

  • Lockstep::Account
  • Lockstep::ApiKey
  • Lockstep::AppEnrollment
  • Lockstep::Attachment
  • Lockstep::Connection
  • Lockstep::Contact
  • Lockstep::CustomerSummary
  • Lockstep::CompanyMagicLinkSummary
  • Lockstep::FeatureFlag
  • Lockstep::Invoice
  • Lockstep::InvoiceAtRiskSummary
  • Lockstep::InvoiceSummary
  • Lockstep::MagicLink
  • 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::TranscriptionValidationRequest
  • Lockstep::User
  • Lockstep::WorkflowStatus

ActiveModel Interfaces

lockstep_rails supports the standard CRUD interface of ActiveRecord.

Create

You can create a record by calling new or create

Lockstep::Contact.create(email_address: "inbox@companyemail.com")

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: "inbox@companyemail.com")

Update

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")

Find

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")

Where

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

Chaining

You can chain queries while calling where.

Lockstep::Connection.where(status: "Active").where(default_currency_code: "USD").execute

OR Query

You can build an or query by calling or

Lockstep::Connection.where(status: "Active").or(Lockstep::Connection.where(default_currency_code: "USD")).execute

Advanced Queries

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")

Searchlight Queries

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

Destroy and Destroy all

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"])

Count

You can fetch the count of available records by calling count

Lockstep::Connection.count
# 1000

Lockstep::Connection.where(status: "Active").count
# 100

With Count

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.

Limit

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

Pagination

You can paginate the records by passing the page

Lockstep::Connection.page(2).execute

Lockstep::Connection.where(status: "Active").limit(100).page(2).execute

Adding relationships with ActiveRecord

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

Loader

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

Updating API Schema

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

About

Lockstep-sdk-ruby-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.

License:MIT License


Languages

Language:Ruby 97.5%Language:HTML 2.0%Language:JavaScript 0.3%Language:CSS 0.3%