Sha256: de4032a85c2acffe88e6dc56e68872026eb1c8263930162988f214eabcc7ab73

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

module Enotas
  class Nfe < EnotasObject
    include ApiResource

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

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

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

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

    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

    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

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

    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

    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

    def self.create_from(params)
      params
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
enotas-0.1.3 lib/enotas/nfe.rb