Sha256: 0cd5885082a573c0f275e0adb65221ba2a5285473f2e21b270c2d29e20f5f4db

Contents?: true

Size: 1.01 KB

Versions: 7

Compression:

Stored size: 1.01 KB

Contents

module AfipWsfe

  class AuthData

    class << self

      attr_accessor :todays_data_file_name

      def auth_hash
        fetch unless AfipWsfe.constants.include?(:TOKEN) && AfipWsfe.constants.include?(:SIGN)
        
        {
          auth: {
            token: AfipWsfe::TOKEN,
            sign: AfipWsfe::SIGN,
            cuit: AfipWsfe.cuit,
          }
        }
      end

      def todays_data_file_name
        @todays_data_file ||= "/tmp/afip_wsfe_#{ AfipWsfe.cuit }_#{ Time.zone.today.strftime('%Y_%m_%d') }.yml"
      end

      private
      
      def fetch
        unless File.exists?(todays_data_file_name)
          wsaa = AfipWsfe::Wsaa.new
          wsaa.login
        end

        YAML.load_file(todays_data_file_name).each do |k, v|
          AfipWsfe.const_set(k.to_s.upcase, v)
        end
      end

      def remove
        AfipWsfe.remove_const(:TOKEN)
        AfipWsfe.remove_const(:SIGN)
        File.delete(@todays_data_file)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
afip_wsfe-0.2.7 lib/afip_wsfe/auth_data.rb
afip_wsfe-0.2.6 lib/afip_wsfe/auth_data.rb
afip_wsfe-0.2.5 lib/afip_wsfe/auth_data.rb
afip_wsfe-0.2.4 lib/afip_wsfe/auth_data.rb
afip_wsfe-0.2.3 lib/afip_wsfe/auth_data.rb
afip_wsfe-0.2.1 lib/afip_wsfe/auth_data.rb
afip_wsfe-0.2.0 lib/afip_wsfe/auth_data.rb