Sha256: 3059b645be8750990890137cf976517cf006e68db207ffbee84f642bf93f1135

Contents?: true

Size: 1.16 KB

Versions: 12

Compression:

Stored size: 1.16 KB

Contents

require 'net/http'
require 'uri'

module Maxipago
  module RequestBuilder
    class Request

      def initialize(maxipagoId, apiKey)
        @maxipagoId = maxipagoId
        @apiKey = apiKey
        @apiVersion = Maxipago::Client::APIVERSION
        @header = { "Content-Type" => 'text/xml' }
      end

      def send_command(opts)
        xml = build_xml(opts)
        send_request(xml)
      end

      private

      def send_request(xml)
        set_uri
        set_http_session

        @http_session.start { |http|
          response = http.post(@uri.path, xml, @header)
          { header: response, body: response.body, message: response.message }
        }
      end

      def set_uri
        raise "This is an abstract method"
      end

      def build_xml(opts)
        raise "This is an abstract method"
      end

      def set_http_session
        @http_session = Net::HTTP.new(@uri.host, @uri.port)
        @http_session.use_ssl = true if @uri.scheme == "https"
        set_ssl_mode if @http_session.use_ssl?
      end

      def set_ssl_mode
        @http_session.verify_mode = OpenSSL::SSL::VERIFY_NONE
        @http_session.ssl_timeout = 30
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
maxipago-0.1.30 lib/maxipago/request_builder/request.rb
maxipago-0.1.29 lib/maxipago/request_builder/request.rb
maxipago-0.1.28 lib/maxipago/request_builder/request.rb
maxipago-0.1.27 lib/maxipago/request_builder/request.rb
maxipago-0.1.26 lib/maxipago/request_builder/request.rb
maxipago-0.1.25 lib/maxipago/request_builder/request.rb
maxipago-0.1.24 lib/maxipago/request_builder/request.rb
maxipago-0.1.23 lib/maxipago/request_builder/request.rb
maxipago-0.1.22 lib/maxipago/request_builder/request.rb
maxipago-0.1.21 lib/maxipago/request_builder/request.rb
maxipago-0.1.20 lib/maxipago/request_builder/request.rb
maxipago-0.1.19 lib/maxipago/request_builder/request.rb