Class: Translatomatic::HTTP::Client
- Inherits:
-
Object
- Object
- Translatomatic::HTTP::Client
- Includes:
- Util
- Defined in:
- lib/translatomatic/http/client.rb
Overview
HTTP client
Defined Under Namespace
Classes: HttpRetryExecutor
Instance Method Summary collapse
-
#delete(url, options = {}) ⇒ Net::HTTP::Response
Send an HTTP DELETE request.
-
#get(url, query = nil, options = {}) ⇒ Net::HTTP::Response
Send an HTTP GET request.
-
#head(url, options = {}) ⇒ Net::HTTP::Response
Send an HTTP HEAD request.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#post(url, body, options = {}) ⇒ Net::HTTP::Response
Send an HTTP POST request.
-
#start(url, _options = {}) ⇒ Object
Start an HTTP request.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 |
# File 'lib/translatomatic/http/client.rb', line 7 def initialize( = {}) @redirects = 0 @jar = ::HTTP::CookieJar.new @retry_delay = [:retry_delay] || 2 end |
Instance Method Details
#delete(url, options = {}) ⇒ Net::HTTP::Response
Send an HTTP DELETE request
43 44 45 |
# File 'lib/translatomatic/http/client.rb', line 43 def delete(url, = {}) send_request_with_method(:delete, url, ) end |
#get(url, query = nil, options = {}) ⇒ Net::HTTP::Response
Send an HTTP GET request
18 19 20 |
# File 'lib/translatomatic/http/client.rb', line 18 def get(url, query = nil, = {}) send_request_with_method(:get, url, .merge(query: query)) end |
#head(url, options = {}) ⇒ Net::HTTP::Response
Send an HTTP HEAD request
35 36 37 |
# File 'lib/translatomatic/http/client.rb', line 35 def head(url, = {}) send_request_with_method(:head, url, ) end |
#post(url, body, options = {}) ⇒ Net::HTTP::Response
Send an HTTP POST request
27 28 29 |
# File 'lib/translatomatic/http/client.rb', line 27 def post(url, body, = {}) send_request_with_method(:post, url, .merge(body: body)) end |
#start(url, _options = {}) ⇒ Object
Start an HTTP request. Yields the http object.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/translatomatic/http/client.rb', line 50 def start(url, = {}) uri = url.respond_to?(:host) ? url : URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' # http.set_debug_output(Translatomatic.config.logger) if ENV['DEBUG'] result = http.start do @http = http yield http end @http = nil result end |