Class: Alloy::KYC::Backends::Remote
- Inherits:
-
Object
- Object
- Alloy::KYC::Backends::Remote
- Defined in:
- lib/alloy/kyc/backends/remote.rb
Instance Attribute Summary collapse
-
#bearer_token ⇒ Object
readonly
Returns the value of attribute bearer_token.
Instance Method Summary collapse
- #conn ⇒ Object
-
#create_evaluation(params) ⇒ Object
domain methods.
- #fork_evaluation(path) ⇒ Object
-
#get(url, options = {}) ⇒ Object
http-level methods.
- #get_bearer_token ⇒ Object
- #patch(url, params = {}) ⇒ Object
- #post(url, params = {}) ⇒ Object
- #requires_bearer_token? ⇒ Boolean
- #set_auth_header ⇒ Object
- #submit_oow_responses(path, responses) ⇒ Object
Instance Attribute Details
#bearer_token ⇒ Object (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
#conn ⇒ Object
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..open_timeout = Alloy::KYC.configuration.open_timeout @conn..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, ={}) set_auth_header conn.get(url, ) end |
#get_bearer_token ⇒ Object
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
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_header ⇒ Object
28 29 30 31 32 |
# File 'lib/alloy/kyc/backends/remote.rb', line 28 def set_auth_header if requires_bearer_token? conn.("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 |