Sha256: 2e10a5e3f65ba90fb4e760690345d77e293c1dbad88efbf51f3d1639eb34ce59

Contents?: true

Size: 726 Bytes

Versions: 2

Compression:

Stored size: 726 Bytes

Contents

# -*- coding: utf-8 -*-

module Gemirro
  ##
  # The Http class is responsible for executing GET request
  # to a specific url and return an response as an HTTP::Message
  #
  # @!attribute [r] client
  #  @return [HTTPClient]
  #
  class Http
    attr_accessor :client

    ##
    # Requests the given HTTP resource.
    #
    # @param [String] url
    # @return [HTTP::Message]
    #
    def self.get(url)
      response = client.get(url, follow_redirect: true)

      unless HTTP::Status.successful?(response.status)
        raise HTTPClient::BadResponseError, response.reason
      end

      response
    end

    ##
    # @return [HTTPClient]
    #
    def self.client
      @client ||= HTTPClient.new
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gemirro-0.13.5 lib/gemirro/http.rb
gemirro-0.13.4 lib/gemirro/http.rb