Class: Emites::Resources::Nfse

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

Overview

A wrapper to Emites NFSes API

API

Documentation: myfreecomm.github.io/emites/v1/modules/nfse.html

Examples:

Listing all NFSe:

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

Creating a NFSe:

client = Emites.client("MY_SECRET_TOKEN")
client.nfse.create({emitter_id: 1, serie: "a", ...)

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

#cancel(id) ⇒ Emites::Entities::NfseStatus

Cancels a Nfse by it’s id

API

Method: POST /api/v1/nfse/:id/cancel

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#cancelamento

Parameters:

  • id (Integer)

    the Nfse id

Returns:



133
134
135
136
137
# File 'lib/emites/resources/nfse.rb', line 133

def cancel(id)
  http.post("/nfse/#{id}/cancel") do |response|
    respond_with_entity(response, Entities::NfseStatus)
  end
end

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

Creates an Nfse

API

Method: POST /api/v1/nfse

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

Parameters:

  • params (Hash)

    a hash with Nfse attributes

Returns:



163
164
165
166
167
# File 'lib/emites/resources/nfse.rb', line 163

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

#destroy(id) ⇒ Boolean

Deletes a Nfse by it’s id

API

Method: DELETE /api/v1/nfse/:id

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

Parameters:

  • id (Integer)

    the Nfse id

Returns:

  • (Boolean)

    whether deletion was performed or not



148
149
150
151
152
# File 'lib/emites/resources/nfse.rb', line 148

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

#history(id) ⇒ Object

Retrieves the entire Nfse status history by it’s id

API

Method: GET /api/v1/nfse/:id/history

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#historico

Parameters:

  • id (Integer)

    the Nfse id

Returns:

  • Emites::Entities::Collection a collection of Emites::Entities::NfseStatusTransition



88
89
90
91
92
# File 'lib/emites/resources/nfse.rb', line 88

def history(id)
  http.get("/nfse/#{id}/history") do |response|
    respond_with_collection(response, Entities::NfseStatusTransition)
  end
end

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

Retrieves a Nfse by it’s id

API

Method: GET /api/v1/nfse/:id

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

Parameters:

  • id (Integer)

    the Nfse id

Returns:



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

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

#listObject

Lists all NFSes

API

Method: GET /api/v1/nfse

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

Returns:

  • Emites::Entities::Collection a collection of Emites::Entities::Nfse



28
29
30
31
32
# File 'lib/emites/resources/nfse.rb', line 28

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

#pdf(id) ⇒ String

Retrieves Nfse PDF url

API

Method: GET /api/v1/nfse/:id/pdf

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#pdf

Parameters:

  • id (Integer)

    the Nfse id

Returns:

  • (String)

    the url to redirect or an empty string if an error occurred



103
104
105
106
107
# File 'lib/emites/resources/nfse.rb', line 103

def pdf(id)
  http.get("/nfse/#{id}/pdf") do |response|
    response.headers.fetch("Location") { "" }
  end
end

#search(params = {}) ⇒ Object

Lists all NFSes matching search parameters

API

Method: GET /api/v1/nfse?status=:status&page=:page

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

Parameters:

  • params (Hash) (defaults to: {})

    an optional hash with filter parameters

Returns:

  • Emites::Entities::Collection a collection of Emites::Entities::Nfse



43
44
45
46
47
# File 'lib/emites/resources/nfse.rb', line 43

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

#status(id) ⇒ Emites::Entities::NfseStatus

Retrieves a Nfse status by it’s id

API

Method: GET /api/v1/nfse/:id/status

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#status

Parameters:

  • id (Integer)

    the Nfse id

Returns:



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

def status(id)
  http.get("/nfse/#{id}/status") do |response|
    respond_with_entity(response, Entities::NfseStatus)
  end
end

#update(id, params) ⇒ Emites::Entities::Nfse

Updates an Nfse

API

Method: PUT /api/v1/:id

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#atualizacao-parcial-e-completa

Parameters:

  • id (Integer)

    the Nfse id

  • params (Hash)

    a hash with Nfse attributes

Returns:



179
180
181
182
183
# File 'lib/emites/resources/nfse.rb', line 179

def update(id, params)
  http.put("/nfse/#{id}", { body: params }) do |response|
    respond_with_entity(response)
  end
end

#xml(id) ⇒ String

Retrieves Nfse XML url

API

Method: GET /api/v1/nfse/:id/xml

Documentation: myfreecomm.github.io/emites/sandbox/v1/modules/nfse.html#xml

Parameters:

  • id (Integer)

    the Nfse id

Returns:

  • (String)

    the url to redirect or an empty string if an error occurred



118
119
120
121
122
# File 'lib/emites/resources/nfse.rb', line 118

def xml(id)
  http.get("/nfse/#{id}/xml") do |response|
    response.headers.fetch("Location") { "" }
  end
end