Class: Alloy::KYC::Backends::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/alloy/kyc/backends/remote.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bearer_tokenObject (readonly)

Returns the value of attribute bearer_token.



6
7
8
# File 'lib/alloy/kyc/backends/remote.rb', line 6

def bearer_token
  @bearer_token
end

Instance Method Details

#connObject



8
9
10
11
12
13
14
15
# File 'lib/alloy/kyc/backends/remote.rb', line 8

def conn
  if @conn.nil?
    @conn = Faraday.new(url: "#{Alloy::KYC.configuration.api_endpoint}")
    @conn.options.open_timeout = Alloy::KYC.configuration.open_timeout
    @conn.options.timeout = Alloy::KYC.configuration.read_timeout
  end
  @conn
end

#create_evaluation(params) ⇒ Object

domain methods



35
36
37
# File 'lib/alloy/kyc/backends/remote.rb', line 35

def create_evaluation(params)
  post("evaluations", params)
end

#fork_evaluation(path) ⇒ Object



43
44
45
# File 'lib/alloy/kyc/backends/remote.rb', line 43

def fork_evaluation(path)
  post(path)
end

#get(url, options = {}) ⇒ Object

http-level methods



48
49
50
51
# File 'lib/alloy/kyc/backends/remote.rb', line 48

def get(url, options={})
  set_auth_header
  conn.get(url, options)
end

#get_bearer_tokenObject



17
18
19
20
21
22
# File 'lib/alloy/kyc/backends/remote.rb', line 17

def get_bearer_token
  conn.basic_auth(Alloy::KYC.configuration.application_token, Alloy::KYC.configuration.application_secret)
  response = conn.post("oauth/bearer")
  token_info = JSON.parse(response.body)
  @bearer_token = BearerToken.new(token_info["access_token"], token_info["expires_in"])
end

#patch(url, params = {}) ⇒ Object



58
59
60
61
# File 'lib/alloy/kyc/backends/remote.rb', line 58

def patch(url, params={})
  set_auth_header
  conn.patch(url, params)
end

#post(url, params = {}) ⇒ Object



53
54
55
56
# File 'lib/alloy/kyc/backends/remote.rb', line 53

def post(url, params={})
  set_auth_header
  conn.post(url, params)
end

#requires_bearer_token?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/alloy/kyc/backends/remote.rb', line 24

def requires_bearer_token?
  bearer_token.nil? || bearer_token.expired?
end

#set_auth_headerObject



28
29
30
31
32
# File 'lib/alloy/kyc/backends/remote.rb', line 28

def set_auth_header
  if requires_bearer_token?
    conn.authorization("Bearer", get_bearer_token.token)
  end
end

#submit_oow_responses(path, responses) ⇒ Object



39
40
41
# File 'lib/alloy/kyc/backends/remote.rb', line 39

def submit_oow_responses(path, responses)
  patch(path, responses)
end