Class: Etwin::Client::HttpEtwinClient

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Includes:
EtwinClient
Defined in:
lib/etwin/client/http_etwin_client.rb

Overview

HTTP Etwin client interface

Instance Method Summary collapse

Constructor Details

#initialize(base_uri) ⇒ HttpEtwinClient

Returns a new instance of HttpEtwinClient.



16
17
18
19
20
21
22
# File 'lib/etwin/client/http_etwin_client.rb', line 16

def initialize(base_uri)
  # @type [URI::HTTP]
  @base_uri = T.let(base_uri.freeze, URI::HTTP)
  # @type [Faraday::Connection]
  @client = T.let(Faraday::Connection.new.freeze, Faraday::Connection)
  freeze
end

Instance Method Details

#get_user(auth, user_id) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/etwin/client/http_etwin_client.rb', line 25

def get_user(auth, user_id)
  uri = resolve(['users', user_id.to_s])
  # @type [Faraday::Request] req
  # @type [Faraday::Response] res
  res = @client.get uri do |req|
    req.headers['Authorization'] = auth.authorization_header
  end
  Etwin::User::User.from_json res.body
end