Sha256: cb5da2bdb433eb57b2ba23dbb73aca39e5b33da53cb1d968398ac635c2182442

Contents?: true

Size: 905 Bytes

Versions: 5

Compression:

Stored size: 905 Bytes

Contents

require 'net/http'
require 'uri'

module Gem
  module Release
    module Helper
      module Http
        class Client < Struct.new(:method, :url, :body, :headers)
          def request
            req = const.new(uri.request_uri, headers)
            req.body = body if body
            resp = client.request(req)
            [resp.code.to_i, resp.body]
          end

          private

            def uri
              @uri ||= URI.parse(url)
            end

            def client
              http_client = Net::HTTP.new(uri.host, uri.port)
              http_client.use_ssl = (uri.scheme == 'https')
              http_client
            end

            def const
              Net::HTTP.const_get(method.to_s.capitalize)
            end
        end

        def post(url, body = nil, headers = {})
          Client.new(:post, url, body, headers).request
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gem-release-2.2.2 lib/gem/release/helper/http.rb
gem-release-2.2.1 lib/gem/release/helper/http.rb
gem-release-2.2.0 lib/gem/release/helper/http.rb
gem-release-2.1.1 lib/gem/release/helper/http.rb
gem-release-2.1.0 lib/gem/release/helper/http.rb