Class: Emites::Resources::Emitter

Inherits:
Base
  • Object
show all
Defined in:
lib/emites/resources/emitter.rb

Overview

A wrapper to Emites emitters API

API

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html

Examples:

Listing all emitters:

client = Emites.client("MY_SECRET_TOKEN")
client.emitters.list

Creating an emitter:

client = Emites.client("MY_SECRET_TOKEN")
client.emitters.create({cnpj: "01001001000113", certificate: Base64.encode64(File.read("path/to/certificate.pfx"))})

See Also:

Instance Attribute Summary

Attributes inherited from Base

#http

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from Hooks

#notify

Constructor Details

This class inherits a constructor from Emites::Resources::Base

Instance Method Details

#create(params) ⇒ Emites::Entities::Emitter

Creates an Emitter related to the Account

API

Method: POST /api/v1/emitters

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html#criacao

Parameters:

  • params (Hash)

    a hash with Emitter attributes

Returns:



29
30
31
32
33
# File 'lib/emites/resources/emitter.rb', line 29

def create(params)
  http.post("/emitters", { body: params }) do |response|
    respond_with_entity(response)
  end
end

#destroy(id) ⇒ Boolean

Deletes an Emitter by it’s id. Returns true</true> if deletion performed well, otherwise, returns <tt>false.

API

Method: DELETE /api/v1/emitters/:id

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html#remocao

Parameters:

  • id (Integer)

    the Emitter id

Returns:

  • (Boolean)

    whether deletion was performed or not



89
90
91
92
93
# File 'lib/emites/resources/emitter.rb', line 89

def destroy(id)
  http.delete("/emitters/#{id}") do |response|
    response.code == 204
  end
end

#info(id) ⇒ Emites::Entities::Emitter

Retrieves an Emitter by it’s id

API

Method: GET /api/v1/emitters/:id

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html#detalhes

Parameters:

  • id (Integer)

    the Emitter id

Returns:



44
45
46
47
48
# File 'lib/emites/resources/emitter.rb', line 44

def info(id)
  http.get("/emitters/#{id}") do |response|
    respond_with_entity(response)
  end
end

#listArray

Lists all Emitters related to the account

API

Method: GET /api/v1/emitters

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html#listagem

Returns:

  • (Array)

    an array of Emitter



58
59
60
61
62
# File 'lib/emites/resources/emitter.rb', line 58

def list
  http.get("/emitters") do |response|
    respond_with_collection(response)
  end
end

#search(params) ⇒ Array

Lists all Emitters related to the account matching search results

API

Method: GET /api/v1/emitters?cnpj=:cnpj

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/emitter.html#filtros

Parameters:

  • params (Hash)

    a hash with Emitter attributes

Returns:

  • (Array)

    an array of Emitter



73
74
75
76
77
# File 'lib/emites/resources/emitter.rb', line 73

def search(params)
  http.get("/emitters", { params: params }) do |response|
    respond_with_collection(response)
  end
end