# Billimatic API Ruby Client This is the official Ruby client for the [Billimatic](http://www.billimatic.com.br) API. [![Gem Version](https://badge.fury.io/rb/billimatic-client.png)](https://rubygems.org/gems/billimatic-client) [![Build Status](https://api.travis-ci.org/myfreecomm/billimatic-client-ruby.svg?branch=master)](https://travis-ci.org/myfreecomm/billimatic-client-ruby) [![Test Coverage](https://codeclimate.com/github/myfreecomm/billimatic-client-ruby/badges/coverage.svg)](https://codeclimate.com/github/myfreecomm/billimatic-client-ruby/coverage) [![Code Climate Grade](https://codeclimate.com/github/myfreecomm/billimatic-client-ruby/badges/gpa.svg)](https://codeclimate.com/github/myfreecomm/billimatic-client-ruby) [![Inline docs](http://inch-ci.org/github/myfreecomm/billimatic-client-ruby.svg?branch=master)](http://inch-ci.org/github/myfreecomm/billimatic-client-ruby) ## Installation Add this line to your application's Gemfile: ```ruby gem 'billimatic-client' ``` And then execute: $ bundle Or install it yourself as: $ gem install billimatic-client ## Configuration ##### Use Billimatic.configure to setup your environment: ```ruby require 'billimatic' Billimatic.configure do |config| config.host = 'https://sandbox.billimatic.com.br' # defaults to 'https://app.billimatic.com.br' config.user_agent = 'My App v1.0' # optional, but you should pass a custom user-agent identifying your app end ``` ## Usage ##### Given your token, create an instance of Billimatic::Client, as below: ```ruby client = Billimatic.client("YOUR_TOKEN_HERE") ``` ##### Now you have acess to every API endpoint: * [Organizations API](https://app.billimatic.com.br/docs/api#!/organizations) as `client.organizations` * [Plans API](https://app.billimatic.com.br/docs/api#!/plans) as `client.plans` * [Subscriptions API](https://app.billimatic.com.br/docs/api#!/subscriptions) as `client.subscriptions` * [Contracts API](https://app.billimatic.com.br/docs/api#!/contracts) as `client.contracts` * [Invoices API](https://app.billimatic.com.br/docs/api#!/invoices) as `client.invoices` * [Invoice Rules API](https://app.billimatic.com.br/docs/api#!/invoice_rules) as `client.invoice_rules` * [Companies API](https://app.billimatic.com.br/docs/api#!/companies) as `client.companies` * [People API](https://app.billimatic.com.br/docs/api#!/people) as `client.people` * [Service Items API](https://app.billimatic.com.br/docs/api#!/service_items) as `client.service_items` ## Endpoints #### [Organizations](https://app.billimatic.com.br/docs/api#!/organizations)
HTTP method Endpoint Client method
GET /api/v1/organizations/search?cnpj=:cnpj client.organizations.search(cnpj: cnpj)
POST /api/v1/organizations client.organizations.create(attributes_hash)
PATCH /api/v1/organizations/:id client.organizations.update(id, attributes_hash)
DELETE /api/v1/organizations/:id client.organizations.destroy(id)
#### [Plans](https://app.billimatic.com.br/docs/api#!/plans)
HTTP method Endpoint Client method
GET /api/v1/organizations/:organization_id/plans client.plans.list(organization_id: id)
POST /api/v1/organizations/:organization_id/plans client.plans.create(attributes_hash, organization_id: id)
PATCH /api/v1/organizations/:organization_id/plans/:id client.plans.update(id, attributes_hash, organization_id: id)
DELETE /api/v1/organizations/:organization_id/plans/:id client.plans.destroy(id, organization_id: id)
#### [Subscriptions](https://app.billimatic.com.br/docs/api#!/subscriptions)
HTTP method Endpoint Client method
GET /api/v1/subscriptions/token/:token client.subscriptions.show(token: token)
POST /api/v1/subscriptions client.subscriptions.create(attributes_hash)
POST /api/v1/subscriptions/checkout/:token client.subscriptions.checkout(attributes_hash, token: token)
PATCH /api/v1/subscriptions/:token/change_plan client.subscriptions.change_plan(token: token, new_plan_id: id)
PATCH /api/v1/subscriptions/:token/update_payment_information client.subscriptions.update_payment_information(attributes_hash, token: token)
PATCH /api/v1/subscriptions/:token/cancel # cancel_date and cancel_reason are optional arguments
client.subscriptions.cancel(token: token, cancel_date: date, cancel_reason: reason)
#### [Contracts](https://app.billimatic.com.br/docs/api#!/contracts)
HTTP method Endpoint Client method
GET /api/v1/contracts/search?name=:name client.contracts.search(name: name)
POST /api/v1/contracts client.contracts.create(attributes_hash)
PATCH /api/v1/contracts/:id client.contracts.update(id, attributes_hash)
DELETE /api/v1/contracts/:id client.contracts.destroy(id)
#### [Invoices](https://app.billimatic.com.br/docs/api#!/invoices)
HTTP method Endpoint Client method
GET /api/v1/contracts/:contract_id/invoices/search?issue_date_from=:issue_date_from&issue_date_to=:issue_date_to client.invoices.search(contract_id: id, issue_date_from: 'dd-mm-yyyy', issue_date_to: 'dd-mm-yyyy')
GET /api/v1/contracts/:contract_id/invoices/:id client.invoices.show(id, contract_id: id)
POST /api/v1/contracts/:contract_id/invoices client.invoices.create(attributes_hash, contract_id: id)
PATCH /api/v1/contracts/:contract_id/invoices/:id client.invoices.update(id, attributes_hash, contract_id: id)
DELETE /api/v1/contracts/:contract_id/invoices/:id client.invoices.destroy(id, contract_id: id)
#### [Invoice Rules](https://app.billimatic.com.br/docs/api#!/invoice_rules)
HTTP method Endpoint Client method
POST /api/v1/contracts/:contract_id/invoice_rules client.invoice_rules.create(attributes_hash, contract_id: id)
PATCH /api/v1/contracts/:contract_id/invoice_rules/:id client.invoice_rules.update(id, attributes_hash, contract_id: id)
#### [Companies](https://app.billimatic.com.br/docs/api#!/companies)
HTTP method Endpoint Client method
GET /api/v1/companies/search?cnpj=:cnpj client.companies.search(cnpj)
POST /api/v1/companies client.companies.create(attributes_hash)
PATCH /api/v1/companies/:id client.companies.update(id, attributes_hash)
DELETE /api/v1/companies/:id client.companies.destroy(id)
#### [People](https://app.billimatic.com.br/docs/api#!/people)
HTTP method Endpoint Client method
GET /api/v1/people/search?cpf=:cpf client.people.search(cnpj)
POST /api/v1/people client.people.create(attributes_hash)
PATCH /api/v1/people/:id client.people.update(id, attributes_hash)
DELETE /api/v1/people/:id client.people.destroy(id)
#### [Service Items](https://app.billimatic.com.br/docs/api#!/service_items)
HTTP method Endpoint Client method
GET /api/v1/service_items/search?name=:name client.service_items.search(name: name)
POST /api/v1/service_items client.service_items.create(attributes_hash)
PATCH /api/v1/service_items/:id client.service_items.update(id, attributes_hash)
DELETE /api/v1/service_items/:id client.service_items.destroy(id)
## Url helpers Some url helpers are available: ### Checkout ```ruby Billimatic.url_helpers.checkout_url(token: "some-subscription-token") ``` ### Subscription dashboard ```ruby Billimatic.url_helpers.subscription_dashboard_url(token: "some-subscription-token") ``` ### Change plan ```ruby Billimatic.url_helpers.change_plan_url(token: "some-subscription-token", plan_id: 52) ``` ## Callbacks TODO ## Contributing 1. Fork it ( https://github.com/[my-github-username]/billimatic-client-ruby/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request