Class: VsClient::NetHttp
- Inherits:
-
Object
- Object
- VsClient::NetHttp
- Defined in:
- lib/vs_client/net_http.rb
Constant Summary collapse
- CONTENT_TYPE =
'application/json'
Instance Method Summary collapse
-
#delete(path:, headers: {}, desired_api_version: nil) ⇒ Object
Execute DELETE requests.
-
#get(path:, query: nil, payload: nil, headers: {}, desired_api_version: nil) ⇒ Hash
Execute GET requests Raise error incase of failure (exceptions, 3xx, 4xx, 5xx).
-
#initialize(config: VsClient::Configuration.new) ⇒ NetHttp
constructor
A new instance of NetHttp.
-
#post(path:, payload: {}, headers: {}, desired_api_version: nil) ⇒ Object
Execute POST requests.
-
#start_session ⇒ Net::HTTP
Establish a connection with remote server.
Constructor Details
#initialize(config: VsClient::Configuration.new) ⇒ NetHttp
Returns a new instance of NetHttp.
10 11 12 13 14 15 16 17 18 |
# File 'lib/vs_client/net_http.rb', line 10 def initialize(config: VsClient::Configuration.new) @uri = URI(config.url) @enabled_debug_mode = config.enable_http_debug_mode @use_ssl = config.use_ssl @keep_alive_timeout = config.keep_alive_timeout @read_timeout = config.timeout @open_timeout = config.open_timeout @default_api_version = config.api_version end |
Instance Method Details
#delete(path:, headers: {}, desired_api_version: nil) ⇒ Object
Execute DELETE requests
57 58 59 60 61 62 63 64 |
# File 'lib/vs_client/net_http.rb', line 57 def delete(path:, headers: {}, desired_api_version: nil) @uri.path = full_path(path: path, desired_api_version: desired_api_version) @uri.query = nil @request = Net::HTTP::Delete.new(@uri) inject_headers!(headers) execute end |
#get(path:, query: nil, payload: nil, headers: {}, desired_api_version: nil) ⇒ Hash
Execute GET requests Raise error incase of failure (exceptions, 3xx, 4xx, 5xx)
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/vs_client/net_http.rb', line 33 def get(path:, query: nil, payload: nil, headers: {}, desired_api_version: nil) @uri.path = full_path(path: path, desired_api_version: desired_api_version) @uri.query = URI.encode_www_form(query) if query @request = Net::HTTP::Get.new(@uri) @request.body = payload.to_json if payload inject_headers!(headers) execute end |
#post(path:, payload: {}, headers: {}, desired_api_version: nil) ⇒ Object
Execute POST requests
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/vs_client/net_http.rb', line 45 def post(path:, payload: {}, headers: {}, desired_api_version: nil) @uri.path = full_path(path: path, desired_api_version: desired_api_version) @uri.query = nil @request = Net::HTTP::Post.new(@uri) @request.body = payload.to_json inject_headers!(headers) execute end |
#start_session ⇒ Net::HTTP
Establish a connection with remote server
22 23 24 25 26 |
# File 'lib/vs_client/net_http.rb', line 22 def start_session return session if session&.started? session.start end |