Class: SdrClient::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/sdr_client/connection.rb

Overview

The connection to the server

Instance Method Summary collapse

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

#connectionObject



13
14
15
16
17
18
# File 'lib/sdr_client/connection.rb', line 13

def connection
  @connection ||= Faraday.new(url: url) do |conn|
    conn.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.

Parameters:

  • the (String)

    email address of the person to proxy to.

Returns:

  • (Result)

    the token for the account



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