Class: HandleSystem::HttpClient
- Inherits:
-
Object
- Object
- HandleSystem::HttpClient
- Includes:
- HTTParty
- Defined in:
- lib/handle_system/http_client.rb
Overview
HTTP utility class for Handle client
Provides some convenience methods so we don’t have to set headers and options with each request, checks for and throws errors reported by the handle server, and does the work of acquiring a session
Instance Method Summary collapse
-
#delete(path) ⇒ JSON
Send a delete request.
-
#get(path) ⇒ JSON
Send a get request.
-
#initialize(server, hs_admin, priv_key_path, pass_phrase = nil) ⇒ HttpClient
constructor
New Handle HTTP client.
-
#put(path, body) ⇒ JSON
Send a put request.
Constructor Details
#initialize(server, hs_admin, priv_key_path, pass_phrase = nil) ⇒ HttpClient
New Handle HTTP client
28 29 30 31 32 33 34 |
# File 'lib/handle_system/http_client.rb', line 28 def initialize(server, hs_admin, priv_key_path, pass_phrase = nil) @hs_admin = hs_admin @private_key_path = priv_key_path @pass_phrase = pass_phrase @base_url = 'https://' + server + '/api' @session_id = initialize_session end |
Instance Method Details
#delete(path) ⇒ JSON
Send a delete request
73 74 75 76 77 |
# File 'lib/handle_system/http_client.rb', line 73 def delete(path) url = @base_url + path response = self.class.delete(url, ) process_response(url, response) end |
#get(path) ⇒ JSON
Send a get request
44 45 46 47 48 |
# File 'lib/handle_system/http_client.rb', line 44 def get(path) url = @base_url + path response = self.class.get(url, ) process_response(url, response) end |
#put(path, body) ⇒ JSON
Send a put request
59 60 61 62 63 |
# File 'lib/handle_system/http_client.rb', line 59 def put(path, body) url = @base_url + path response = self.class.put(url, body: body, **) process_response(url, response) end |