Emites Client

This is the official Ruby client for the Emites API.

Gem Version Build Status Test Coverage Code Climate Grade Inline docs

Installation

Add this line to your application's Gemfile:

gem 'emites-client', require: 'emites'

And then execute:

$ bundle

Or install it yourself as:

$ gem install emites-client

Configuration

Use Emites.configure to setup your environment:
require "emites"

Emites.configure do |config|
  config.url = "https://sandbox.emites.com.br/api/v1" # defaults to "https://app.emites.com.br/api/v1"
  config.user_agent = 'My App v1.0' # optional, but you should pass a custom user-agent identifying your app
end
Create a new token in your Emites account: https://app.emites.com.br/config/api

Usage

Given your token, create an instance of Emites::Client, as below:
client = Emites.client("YOUR_TOKEN_HERE")
Now you have access to every API endpoint:

Endpoints

Emitters

HTTP method Endpoint Client method
POST /api/v1/emitters client.emitters.create
GET /api/v1/emitters client.emitters.list
GET /api/v1/emitters/:id client.emitters.info
GET /api/v1/emitters?cnpj=?:cnpj client.emitters.search
DELETE /api/v1/emitters/:id client.emitters.destroy

Takers

HTTP method Endpoint Client method
POST /api/v1/takers client.takers.create
GET /api/v1/takers client.takers.list
GET /api/v1/takers/:id client.takers.info
GET /api/v1/takers?cnpj=:cnpj client.takers.search
DELETE /api/v1/takers/:id client.takers.destroy

Services

HTTP method Endpoint Client method
POST /api/v1/service-values client.services.create
GET /api/v1/service-values client.services.list
GET /api/v1/service-values/:id client.services.info
GET /api/v1/service-values?name=:name client.services.search
DELETE /api/v1/service-values/:id client.services.destroy
POST /api/v1/service-values/:id/calculation-liquid-amount client.services.calculate_liquid_amount

Webhooks

HTTP method Endpoint Client method
POST /api/v1/webhooks client.webhooks.create
GET /api/v1/webhooks client.webhooks.list
PUT /api/v1/webhooks/:id client.webhooks.update
DELETE /api/v1/webhooks/:id client.webhooks.destroy

NFSe

HTTP method Endpoint Client method
POST /api/v1/nfse client.nfse.create
GET /api/v1/nfse client.nfse.list
GET /api/v1/nfse/:id client.nfse.info
GET /api/v1/nfse/:id/status client.nfse.status
GET /api/v1/nfse/:id/history client.nfse.history
GET /api/v1/nfse/:id/pdf client.nfse.pdf
GET /api/v1/nfse/:id/xml client.nfse.xml
POST /api/v1/nfse/:id/cancel client.nfse.cancel
DELETE /api/v1/nfse/:id client.nfse.destroy
PUT /api/v1/nfse/:id client.nfse.update

Callbacks

All actions that change data triggers an event that you can subscribe to. This event allow you to extend the logic executed when you call a client method.

Subscribing to an event

All you have to do is create a class that responds to a method #call with two arguments:

class MyListener
  def call(result, args)
  end
end

Where:

  • result is the return of a client method
  • args is an array of arguments passed to the client method you called

Now you have a listener, you can subscribe to an event:

Emites.subscribe("emites.emitters.destroy", MyListener.new)

Example:

When you call client.emitters.destroy(1), an event emites.emitters.destroy will be triggered. Your listener method #call will receive:

  • result would be true or false - depending on what client.emitters.destroy(1) returned
  • args would be [1] - an array with the arguments passed to the client method

Available hooks

Resource Events
emitters emites.emitters.create
emites.emitters.destroy
takers emites.takers.create
emites.takers.destroy
services emites.services.create
emites.services.destroy
webhooks emites.webhooks.create
emites.webhooks.update
emites.webhooks.destroy
nfse emites.nfse.create
emites.nfse.update
emites.nfse.destroy
emites.nfse.cancel

Contributing

  1. Fork it ( https://github.com/myfreecomm/emites-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