Class: Pgai::Client
- Inherits:
-
Object
- Object
- Pgai::Client
- Defined in:
- lib/pgai/client.rb
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #expected_cloning_time ⇒ Object
- #get(path) ⇒ Object
-
#initialize(token:, host: "http://127.0.0.1:2355") ⇒ Client
constructor
A new instance of Client.
- #post(path, body = nil) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(token:, host: "http://127.0.0.1:2355") ⇒ Client
Returns a new instance of Client.
7 8 9 |
# File 'lib/pgai/client.rb', line 7 def initialize(token:, host: "http://127.0.0.1:2355") @client = Excon.new(host, headers: {"Verification-Token" => token}) end |
Instance Method Details
#delete(path) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/pgai/client.rb', line 35 def delete(path) response = client.delete(path: path) return {} if response.body.empty? parse_reponse(response.body) end |
#expected_cloning_time ⇒ Object
15 16 17 |
# File 'lib/pgai/client.rb', line 15 def expected_cloning_time get("status").dig(:cloning, :expected_cloning_time) end |
#get(path) ⇒ Object
19 20 21 22 |
# File 'lib/pgai/client.rb', line 19 def get(path) response = client.get(path: path) parse_reponse(response.body) end |
#post(path, body = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pgai/client.rb', line 24 def post(path, body = nil) response = if body client.post(path: path, body: JSON.dump(body)) else client.post(path: path) end return {} if response.body.empty? parse_reponse(response.body) end |
#version ⇒ Object
11 12 13 |
# File 'lib/pgai/client.rb', line 11 def version get("healthz").fetch(:version) end |