Class: TridentAssistant::Client

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#endpointObject (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