Emites Client
This is the official Ruby client for the Emites API.
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
endCreate 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:
-
Emitters API as
client.emitters -
Takers API as
client.takers -
Services API as
client.services -
Webhooks API as
client.webhooks -
NFSe API as
client.nfse
Endpoints
| 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
|
| 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
|
| 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
|
| 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
|
| 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
endWhere:
-
resultis the return of a client method -
argsis 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:
-
resultwould betrue or false- depending on whatclient.emitters.destroy(1)returned -
argswould be[1]- an array with the arguments passed to the client method
Available hooks
| Resource | Events |
|---|---|
emitters |
emites.emitters.createemites.emitters.destroy
|
takers |
emites.takers.createemites.takers.destroy
|
services |
emites.services.createemites.services.destroy
|
webhooks |
emites.webhooks.createemites.webhooks.updateemites.webhooks.destroy
|
nfse |
emites.nfse.createemites.nfse.updateemites.nfse.destroyemites.nfse.cancel
|
Contributing
- Fork it ( https://github.com/myfreecomm/emites-client-ruby/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request