Sha256: 0c7b382526f87a5ee182b0ad559ff5483864182eeb98fdb5d6bf488579d091cb

Contents?: true

Size: 701 Bytes

Versions: 7

Compression:

Stored size: 701 Bytes

Contents

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

7 entries across 7 versions & 1 rubygems

Version Path
gemirro-1.2.0 lib/gemirro/http.rb
gemirro-1.1.1 lib/gemirro/http.rb
gemirro-1.1.0 lib/gemirro/http.rb
gemirro-1.0.0 lib/gemirro/http.rb
gemirro-0.16.0 lib/gemirro/http.rb
gemirro-0.15.0 lib/gemirro/http.rb
gemirro-0.14.0 lib/gemirro/http.rb