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, read_timeout: default_timeout, timeout: default_timeout) ⇒ 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, read_timeout: default_timeout, timeout: default_timeout) ⇒ Connection
Returns a new instance of Connection.
9 10 11 12 13 |
# File 'lib/sdr_client/connection.rb', line 9 def initialize(url:, token: Credentials.read, read_timeout: default_timeout, timeout: default_timeout) @url = url @token = token @request_options = { read_timeout: read_timeout, timeout: timeout } end |
Instance Method Details
#connection ⇒ Object
15 16 17 18 19 20 |
# File 'lib/sdr_client/connection.rb', line 15 def connection @connection ||= Faraday.new(url: url, request: ) do |conn| conn.request :authorization, :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.
27 28 29 30 31 32 33 34 35 |
# File 'lib/sdr_client/connection.rb', line 27 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 |