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.
5 6 7 |
# File 'lib/pgai/client.rb', line 5 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
33 34 35 36 37 38 |
# File 'lib/pgai/client.rb', line 33 def delete(path) response = client.delete(path: path) return {} if response.body.empty? parse_reponse(response.body) end |
#expected_cloning_time ⇒ Object
13 14 15 |
# File 'lib/pgai/client.rb', line 13 def expected_cloning_time get("status").dig(:cloning, :expected_cloning_time) end |
#get(path) ⇒ Object
17 18 19 20 |
# File 'lib/pgai/client.rb', line 17 def get(path) response = client.get(path: path) parse_reponse(response.body) end |
#post(path, body = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pgai/client.rb', line 22 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
9 10 11 |
# File 'lib/pgai/client.rb', line 9 def version get("healthz").fetch(:version) end |