Class: Radio5::Http
- Inherits:
-
Object
- Object
- Radio5::Http
- Defined in:
- lib/radio5/http.rb
Constant Summary collapse
- DEFAULT_OPEN_TIMEOUT =
seconds
10
- DEFAULT_READ_TIMEOUT =
seconds
10
- DEFAULT_WRITE_TIMEOUT =
seconds
10
- DEFAULT_PROXY_URL =
nil
- DEFAULT_MAX_RETRIES =
3
- DEFAULT_DEBUG_OUTPUT =
nil
- DEFAULT_HEADERS =
{ "Content-Type" => "application/json; charset=utf-8", "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" }.freeze
- RETRIABLE_ERRORS =
[ Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::ETIMEDOUT, Net::OpenTimeout, Net::ReadTimeout, Net::WriteTimeout, OpenSSL::SSL::SSLError ].freeze
Instance Attribute Summary collapse
-
#debug_output ⇒ Object
readonly
Returns the value of attribute debug_output.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
-
#open_timeout ⇒ Object
readonly
Returns the value of attribute open_timeout.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#proxy_url ⇒ Object
readonly
Returns the value of attribute proxy_url.
-
#read_timeout ⇒ Object
readonly
Returns the value of attribute read_timeout.
-
#write_timeout ⇒ Object
readonly
Returns the value of attribute write_timeout.
Instance Method Summary collapse
-
#initialize(host:, port:, open_timeout: nil, read_timeout: nil, write_timeout: nil, proxy_url: nil, max_retries: nil, debug_output: nil) ⇒ Http
constructor
A new instance of Http.
- #proxy_uri ⇒ Object
- #request(http_method_class, path, query_params, body, headers) ⇒ Object
Constructor Details
#initialize(host:, port:, open_timeout: nil, read_timeout: nil, write_timeout: nil, proxy_url: nil, max_retries: nil, debug_output: nil) ⇒ Http
Returns a new instance of Http.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/radio5/http.rb', line 33 def initialize( host:, port:, open_timeout: nil, read_timeout: nil, write_timeout: nil, proxy_url: nil, max_retries: nil, debug_output: nil ) @host = host @port = port @open_timeout = open_timeout || DEFAULT_OPEN_TIMEOUT @read_timeout = read_timeout || DEFAULT_READ_TIMEOUT @write_timeout = write_timeout || DEFAULT_WRITE_TIMEOUT @proxy_url = proxy_url || DEFAULT_PROXY_URL @max_retries = max_retries || DEFAULT_MAX_RETRIES @debug_output = debug_output || DEFAULT_DEBUG_OUTPUT @http_client = Net::HTTP.new(@host, @port, proxy_uri&.host, proxy_uri&.port, proxy_uri&.user, proxy_uri&.password) @http_client.tap do |c| c.use_ssl = @port == 443 c.open_timeout = @open_timeout c.read_timeout = @read_timeout c.write_timeout = @write_timeout c.set_debug_output(@debug_output) end end |
Instance Attribute Details
#debug_output ⇒ Object (readonly)
Returns the value of attribute debug_output.
31 32 33 |
# File 'lib/radio5/http.rb', line 31 def debug_output @debug_output end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
31 32 33 |
# File 'lib/radio5/http.rb', line 31 def host @host end |
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
31 32 33 |
# File 'lib/radio5/http.rb', line 31 def http_client @http_client end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
31 32 33 |
# File 'lib/radio5/http.rb', line 31 def max_retries @max_retries end |
#open_timeout ⇒ Object (readonly)
Returns the value of attribute open_timeout.
31 32 33 |
# File 'lib/radio5/http.rb', line 31 def open_timeout @open_timeout end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
31 32 33 |
# File 'lib/radio5/http.rb', line 31 def port @port end |
#proxy_url ⇒ Object (readonly)
Returns the value of attribute proxy_url.
31 32 33 |
# File 'lib/radio5/http.rb', line 31 def proxy_url @proxy_url end |
#read_timeout ⇒ Object (readonly)
Returns the value of attribute read_timeout.
31 32 33 |
# File 'lib/radio5/http.rb', line 31 def read_timeout @read_timeout end |
#write_timeout ⇒ Object (readonly)
Returns the value of attribute write_timeout.
31 32 33 |
# File 'lib/radio5/http.rb', line 31 def write_timeout @write_timeout end |
Instance Method Details
#proxy_uri ⇒ Object
64 65 66 |
# File 'lib/radio5/http.rb', line 64 def proxy_uri @proxy_uri ||= parse_proxy_uri end |
#request(http_method_class, path, query_params, body, headers) ⇒ Object
68 69 70 71 |
# File 'lib/radio5/http.rb', line 68 def request(http_method_class, path, query_params, body, headers) request = build_request(http_method_class, path, query_params, body, headers) make_request(request) end |