Class: Enotas::Nfe

Inherits:
EnotasObject show all
Includes:
ApiResource
Defined in:
lib/enotas/nfe.rb

Constant Summary

Constants included from ApiResource

ApiResource::BASE_URL, ApiResource::SSL_BUNDLE_PATH

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ApiResource

#api_request, #encode, included, #recursive_symbolize_keys, #url_encode

Methods inherited from EnotasObject

#create_fields, #initialize, #metaclass, #method_missing, #reflesh_object, #set_properties, #to_hash, #to_json, #to_s

Constructor Details

This class inherits a constructor from Enotas::EnotasObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Enotas::EnotasObject

Class Method Details

.cancel(id_empresa, obj_id) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/enotas/nfe.rb', line 46

def self.cancel(id_empresa, obj_id)
  @company_id = id_empresa
  obj_id = "?id=#{obj_id}" if obj_id.include? '@'
  method = :delete
  response = api_request("#{url}/#{obj_id}",method)
  create_from(response)
end

.cancel_by_external_id(id_empresa, external_id) ⇒ Object



54
55
56
57
58
59
# File 'lib/enotas/nfe.rb', line 54

def self.cancel_by_external_id(id_empresa, external_id)
  @company_id = id_empresa
  method = :delete
  response = api_request("#{url}/porIdExterno/#{external_id}",method)
  create_from(response)
end

.company_id(company_id) ⇒ Object



5
6
7
# File 'lib/enotas/nfe.rb', line 5

def self.company_id(company_id)
  @company_id = company_id
end

.create(id_empresa, params) ⇒ Object



17
18
19
20
21
22
# File 'lib/enotas/nfe.rb', line 17

def self.create(id_empresa, params)
  @company_id = id_empresa
  method = :post
  response = api_request(url, method, params)
  create_from(response)
end

.create_from(params) ⇒ Object



61
62
63
# File 'lib/enotas/nfe.rb', line 61

def self.create_from(params)
  params
end

.retrieve(id_empresa, obj_id) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/enotas/nfe.rb', line 24

def self.retrieve(id_empresa, obj_id)
  @company_id = id_empresa
  obj_id = "?id=#{obj_id}" if obj_id.include? '@'
  method = :get
  response = api_request("#{url}/#{obj_id}",method)
  create_from(response)
end

.retrieve_by_external_id(id_empresa, external_id) ⇒ Object



32
33
34
35
36
37
# File 'lib/enotas/nfe.rb', line 32

def self.retrieve_by_external_id(id_empresa, external_id)
  @company_id = id_empresa
  method = :get
  response = api_request("#{url}/porIdExterno/#{external_id}",method)
  create_from(response)
end

.retrieve_by_period(id_empresa, params) ⇒ Object



39
40
41
42
43
44
# File 'lib/enotas/nfe.rb', line 39

def self.retrieve_by_period(id_empresa, params)
  @company_id = id_empresa
  method = :get
  response = api_request(url, method, params)
  create_from(response)
end

.urlObject



9
10
11
# File 'lib/enotas/nfe.rb', line 9

def self.url
  "/v1/empresas/#{@company_id}/nfes"
end

Instance Method Details

#urlObject



13
14
15
# File 'lib/enotas/nfe.rb', line 13

def url
  "#{self.class.url}/#{self.id}"
end