Sha256: 6c209b468a91166e5d5dd5dc6f8f01b41310200c76080aa201eb6cca7e39833a

Contents?: true

Size: 813 Bytes

Versions: 6

Compression:

Stored size: 813 Bytes

Contents

module AfipWsfe
  class Client
    def initialize(authenticate=true)
      AfipWsfe.environment ||= :test
      @auth = authenticate ? AfipWsfe.auth_hash : {}
    end

    def call_endpoint(endpoint, savon_method, params={})
      return_key = endpoint == :wsaa ? :"#{savon_method}_return" : :"#{savon_method}_result"
      
      result = Savon.client(
        log: AfipWsfe.log?,
        log_level: AfipWsfe.log_level || :debug,
        wsdl: "#{AfipWsfe::URLS[AfipWsfe.environment][endpoint]}?wsdl",
        convert_request_keys_to: :camelcase
      ).call(savon_method, message: params.merge(@auth))

      response = result.body[:"#{savon_method}_response"][return_key]
      response = Hash.from_xml response if endpoint == :wsaa

      [result.success?, response]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

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