Class: Rixie::Http::Client
- Inherits:
-
Object
- Object
- Rixie::Http::Client
- Defined in:
- lib/rixie/http/client.rb
Constant Summary collapse
- DEFAULT_TIMEOUT =
30- DEFAULT_HEADERS =
{"User-Agent" => "Rixie/#{Rixie::VERSION}"}.freeze
- CONNECTION_ERRORS =
[ Errno::EHOSTUNREACH, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL, Errno::ENETUNREACH, SocketError, OpenSSL::SSL::SSLError ].freeze
- REDIRECT_CODES =
[301, 302, 303, 307, 308].freeze
Instance Method Summary collapse
- #get(url) ⇒ Object
-
#initialize(timeout: DEFAULT_TIMEOUT, headers: {}, http_client: nil, allow_private: false) ⇒ Client
constructor
A new instance of Client.
- #post(url, body: nil) ⇒ Object
Constructor Details
#initialize(timeout: DEFAULT_TIMEOUT, headers: {}, http_client: nil, allow_private: false) ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 |
# File 'lib/rixie/http/client.rb', line 22 def initialize(timeout: DEFAULT_TIMEOUT, headers: {}, http_client: nil, allow_private: false) @timeout = timeout @default_headers = DEFAULT_HEADERS.merge(headers) @http_client = http_client @allow_private = allow_private end |
Instance Method Details
#get(url) ⇒ Object
29 30 31 32 |
# File 'lib/rixie/http/client.rb', line 29 def get(url) validate_url!(url) execute_request(url) { |uri| Net::HTTP::Get.new(uri) } end |
#post(url, body: nil) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/rixie/http/client.rb', line 34 def post(url, body: nil) validate_url!(url) execute_request(url) do |uri| req = Net::HTTP::Post.new(uri) req.body = body req end end |