Class: SdrClient::Connection
- Inherits:
-
Object
- Object
- SdrClient::Connection
- Defined in:
- lib/sdr_client/connection.rb
Overview
The connection to the server
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(url:, token: Credentials.read) ⇒ Connection
constructor
A new instance of Connection.
-
#proxy(to) ⇒ Result
This is only available to certain blessed accounts (argo) as it gives the token that allows you to act as any other user.
Constructor Details
#initialize(url:, token: Credentials.read) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 |
# File 'lib/sdr_client/connection.rb', line 8 def initialize(url:, token: Credentials.read) @url = url @token = token end |
Instance Method Details
#connection ⇒ Object
13 14 15 16 17 18 |
# File 'lib/sdr_client/connection.rb', line 13 def connection @connection ||= Faraday.new(url: url) do |conn| conn. :Bearer, token conn.adapter :net_http end end |
#proxy(to) ⇒ Result
This is only available to certain blessed accounts (argo) as it gives the token that allows you to act as any other user. Thus the caller must authenticate the user (e.g. using Shibboleth) before calling this method with their email address.
25 26 27 28 29 30 31 32 33 |
# File 'lib/sdr_client/connection.rb', line 25 def proxy(to) response = connection.post("/v1/auth/proxy?to=#{to}") case response.status when 200 Success(response.body) else Failure("Status: #{response.status}\n#{response.body}") end end |