Sha256: 92c86e1eedbb87f1ec09c77c06a789f033dafecd3c064c218015c30bf514deff

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'faraday'

module VIISP
  module Auth
    class Client
      def post(document)
        with_error_handling do
          request = Signing.sign(document)
          response = connection.post('', request)
          xml = Nokogiri::XML(response.body)
          Signing.validate!(xml)
          xml
        end
      end

      private

      def with_error_handling
        yield
      rescue Faraday::ClientError => e
        raise(RequestError, "#{e.message}. #{e.response}")
      end

      def connection
        @connection ||= Faraday.new(url: configuration.endpoint) do |builder|
          builder.options[:timeout] = configuration.read_timeout
          builder.options[:open_timeout] = configuration.open_timeout

          builder.headers['Accept'] = 'application/xml'

          builder.response :raise_error

          builder.adapter Faraday.default_adapter
        end
      end

      def configuration
        VIISP::Auth.configuration
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
viisp-auth-custom-0.1.0 lib/viisp/auth/client.rb