lib/3scale/api/http_client.rb in 3scale-api-1.5.0 vs lib/3scale/api/http_client.rb in 3scale-api-1.6.0

- old
+ new

@@ -4,13 +4,13 @@ require 'openssl' module ThreeScale module API class HttpClient - attr_reader :endpoint, :admin_domain, :provider_key, :headers, :format + attr_reader :endpoint, :admin_domain, :provider_key, :headers, :format, :keep_alive - def initialize(endpoint:, provider_key:, format: :json, verify_ssl: true) + def initialize(endpoint:, provider_key:, format: :json, verify_ssl: true, keep_alive: false) @endpoint = URI(endpoint).freeze @admin_domain = @endpoint.host.freeze @provider_key = provider_key.freeze @http = Net::HTTP.new(admin_domain, @endpoint.port) @http.use_ssl = @endpoint.is_a?(URI::HTTPS) @@ -28,28 +28,40 @@ end @headers.freeze @format = format + + @keep_alive = keep_alive end def get(path, params: nil) + @http.start if keep_alive && !@http.started? + parse @http.get(format_path_n_query(path, params), headers) end def patch(path, body:, params: nil) + @http.start if keep_alive && !@http.started? + parse @http.patch(format_path_n_query(path, params), serialize(body), headers) end def post(path, body:, params: nil) + @http.start if keep_alive && !@http.started? + parse @http.post(format_path_n_query(path, params), serialize(body), headers) end def put(path, body: nil, params: nil) + @http.start if keep_alive && !@http.started? + parse @http.put(format_path_n_query(path, params), serialize(body), headers) end def delete(path, params: nil) + @http.start if keep_alive && !@http.started? + parse @http.delete(format_path_n_query(path, params), headers) end # @param [::Net::HTTPResponse] response def parse(response)