# Emites Client This is the official Ruby client for the [Emites](https://app.emites.com.br) API. [![Gem Version](https://badge.fury.io/rb/emites-client.png)](https://rubygems.org/gems/emites-client) [![Build Status](https://api.travis-ci.org/myfreecomm/emites-client-ruby.svg?branch=master)](https://travis-ci.org/myfreecomm/emites-client-ruby) [![Test Coverage](https://codeclimate.com/github/myfreecomm/emites-client-ruby/badges/coverage.svg)](https://codeclimate.com/github/myfreecomm/emites-client-ruby) [![Code Climate Grade](https://codeclimate.com/github/myfreecomm/emites-client-ruby/badges/gpa.svg)](https://codeclimate.com/github/myfreecomm/emites-client-ruby) [![Inline docs](http://inch-ci.org/github/myfreecomm/emites-client-ruby.svg)](http://inch-ci.org/github/myfreecomm/emites-client-ruby) ## 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: ```ruby 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: ```ruby client = Emites.client("YOUR_TOKEN_HERE") ``` ##### Now you have access to every API endpoint: * [Emitters API](http://myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html) as `client.emitters` * [Webhooks API](http://myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html) as `client.webhooks` * [NFSe API](http://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html) as `client.nfse` ### Endpoints #### [Emitters](http://myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html)
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
#### [Webhooks](http://myfreecomm.github.io/emites/sandbox/v1/modules/webhooks.html)
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://myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html)
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: ```ruby 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: ```ruby 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
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