Class: Pinot::HttpClient
- Inherits:
-
Object
- Object
- Pinot::HttpClient
- Defined in:
- lib/pinot/transport.rb
Instance Method Summary collapse
- #get(url, headers: {}) ⇒ Object
-
#initialize(timeout: nil) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(url, body:, headers: {}) ⇒ Object
Constructor Details
#initialize(timeout: nil) ⇒ HttpClient
Returns a new instance of HttpClient.
8 9 10 |
# File 'lib/pinot/transport.rb', line 8 def initialize(timeout: nil) @timeout = timeout end |
Instance Method Details
#get(url, headers: {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/pinot/transport.rb', line 26 def get(url, headers: {}) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" if @timeout http.open_timeout = @timeout http.read_timeout = @timeout end req = Net::HTTP::Get.new(uri.request_uri) headers.each { |k, v| req[k] = v } http.request(req) end |
#post(url, body:, headers: {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pinot/transport.rb', line 12 def post(url, body:, headers: {}) uri = URI.parse(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == "https" if @timeout http.open_timeout = @timeout http.read_timeout = @timeout end req = Net::HTTP::Post.new(uri.request_uri) headers.each { |k, v| req[k] = v } req.body = body http.request(req) end |