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



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.



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