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, read_timeout: default_timeout, timeout: default_timeout) ⇒ Connection

Returns a new instance of Connection.

Parameters:

  • read_timeout (Integer) (defaults to: default_timeout)

    the value in seconds to set the read timeout



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

#connectionObject



15
16
17
18
19
20
# File 'lib/sdr_client/connection.rb', line 15

def connection
  @connection ||= Faraday.new(url: url, request: request_options) 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.

Parameters:

  • the (String)

    email address of the person to proxy to.

Returns:

  • (Result)

    the token for the account



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