Sha256: 9631efaab97d50108566843ecafb3073206b6a5c5ba9588254290ad62383a789

Contents?: true

Size: 798 Bytes

Versions: 1

Compression:

Stored size: 798 Bytes

Contents

module NedbankApi
  class Http
    def initialize(url:)
      @url = URI(url)
    end

    def get(body: {}, headers: {})
      request = Net::HTTP::Get.new(@url)
      make_request(request: request, body: body, headers: headers)
    end

    def post(body: {}, headers: {})
      request = Net::HTTP::Post.new(@url)
      make_request(request: request, body: body, headers: headers)
    end

    def make_request(request:, body: {}, headers: {})
      headers.each do |key,value|
        request[key] = value
      end

      request.body = body
      net_http.request(request)
    end

    private

    def net_http
      @net_http ||= Net::HTTP.new(@url.host, @url.port).tap do |http|
        http.use_ssl = true
        http.verify_mode = OpenSSL::SSL::VERIFY_PEER
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nedbank_api-0.2.5 lib/nedbank_api/services/http.rb