Class: TridentAssistant::Client
- Inherits:
-
Object
- Object
- TridentAssistant::Client
- Defined in:
- lib/trident_assistant/client.rb
Overview
HTTP client to trident server
Defined Under Namespace
Classes: HttpError, RequestError
Constant Summary collapse
- ENDPOINT =
"https://thetrident.one"
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
Instance Method Summary collapse
- #get(path, params = nil, headers = nil) ⇒ Object
-
#initialize(**kwargs) ⇒ Client
constructor
A new instance of Client.
- #post(path, body = nil, headers = nil) ⇒ Object
- #put(path, body = nil, headers = nil) ⇒ Object
Constructor Details
#initialize(**kwargs) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/trident_assistant/client.rb', line 13 def initialize(**kwargs) @endpoint = URI(kwargs[:endpoint] || ENDPOINT) @conn = Faraday.new(url: @endpoint.to_s) do |f| f.request :json f.request :retry f.response :raise_error f.response :json f.response :logger if kwargs[:debug] end end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
11 12 13 |
# File 'lib/trident_assistant/client.rb', line 11 def endpoint @endpoint end |
Instance Method Details
#get(path, params = nil, headers = nil) ⇒ Object
24 25 26 |
# File 'lib/trident_assistant/client.rb', line 24 def get(path, params = nil, headers = nil) @conn.get(path, params&.compact, headers).body end |
#post(path, body = nil, headers = nil) ⇒ Object
28 29 30 |
# File 'lib/trident_assistant/client.rb', line 28 def post(path, body = nil, headers = nil) @conn.post(path, body&.compact, headers).body end |
#put(path, body = nil, headers = nil) ⇒ Object
32 33 34 |
# File 'lib/trident_assistant/client.rb', line 32 def put(path, body = nil, headers = nil) @conn.post(path, body&.compact, headers).body end |