Sha256: 0ee2b670b9c5cbd6a439795a7862319e3cd00a5356fe33c737e457fbb5a1390b

Contents?: true

Size: 714 Bytes

Versions: 1

Compression:

Stored size: 714 Bytes

Contents

# frozen_string_literal: true

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)

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

      response
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gemirro-1.3.0 lib/gemirro/http.rb