Class: Authsignal::Client
- Inherits:
-
Object
- Object
- Authsignal::Client
- Defined in:
- lib/authsignal/client.rb
Constant Summary collapse
- USER_AGENT =
"Authsignal Ruby v#{Authsignal::VERSION}"
- NO_API_KEY_MESSAGE =
"No Authsignal API Secret Key Set"
Instance Method Summary collapse
- #delete_authenticator(user_id:, user_authenticator_id:) ⇒ Object
- #delete_user(user_id:) ⇒ Object
- #enroll_verified_authenticator(user_id:, attributes:) ⇒ Object
- #get_action(user_id:, action:, idempotency_key:) ⇒ Object
- #get_authenticators(user_id:) ⇒ Object
- #get_user(user_id:) ⇒ Object
-
#identify(user_id, user_payload) ⇒ Object
TODO: delete identify?.
-
#initialize(retry_options: RETRY_OPTIONS) ⇒ Client
constructor
A new instance of Client.
- #track(user_id:, action:, attributes:) ⇒ Object
- #update_action(user_id:, action:, idempotency_key:, attributes:) ⇒ Object
- #update_user(user_id:, attributes:) ⇒ Object
- #validate_challenge(token:, user_id: nil, action: nil) ⇒ Object
Constructor Details
#initialize(retry_options: RETRY_OPTIONS) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/authsignal/client.rb', line 16 def initialize(retry_options: RETRY_OPTIONS) @api_key = require_api_key @client = Faraday.new do |builder| builder.url_prefix = Authsignal.configuration.api_url builder.adapter :net_http builder.request :authorization, :basic, @api_key, nil builder.headers['Accept'] = 'application/json' builder.headers['Content-Type'] = 'application/json' builder.headers['User-Agent'] = USER_AGENT builder.request :json builder.response :json, parser_options: { symbolize_names: true } builder.use Middleware::JsonRequest builder.use Middleware::JsonResponse builder.request :retry, if Authsignal.configuration.retry builder.response :logger, ::Logger.new(STDOUT), bodies: true if Authsignal.configuration.debug end end |
Instance Method Details
#delete_authenticator(user_id:, user_authenticator_id:) ⇒ Object
60 61 62 |
# File 'lib/authsignal/client.rb', line 60 def delete_authenticator(user_id:, user_authenticator_id:) make_request(:delete, "users/#{url_encode(user_id)}/authenticators/#{url_encode(user_authenticator_id)}") end |
#delete_user(user_id:) ⇒ Object
48 49 50 |
# File 'lib/authsignal/client.rb', line 48 def delete_user(user_id:) make_request(:delete, "users/#{url_encode(user_id)}") end |
#enroll_verified_authenticator(user_id:, attributes:) ⇒ Object
56 57 58 |
# File 'lib/authsignal/client.rb', line 56 def enroll_verified_authenticator(user_id:, attributes:) make_request(:post, "users/#{url_encode(user_id)}/authenticators", body: attributes) end |
#get_action(user_id:, action:, idempotency_key:) ⇒ Object
77 78 79 |
# File 'lib/authsignal/client.rb', line 77 def get_action(user_id:, action:, idempotency_key:) make_request(:get, "users/#{url_encode(user_id)}/actions/#{action}/#{url_encode(idempotency_key)}") end |
#get_authenticators(user_id:) ⇒ Object
52 53 54 |
# File 'lib/authsignal/client.rb', line 52 def get_authenticators(user_id:) make_request(:get, "users/#{url_encode(user_id)}/authenticators") end |
#get_user(user_id:) ⇒ Object
39 40 41 42 |
# File 'lib/authsignal/client.rb', line 39 def get_user(user_id:) path = "users/#{url_encode(user_id)}" make_request(:get, path) end |
#identify(user_id, user_payload) ⇒ Object
TODO: delete identify?
87 88 89 |
# File 'lib/authsignal/client.rb', line 87 def identify(user_id, user_payload) make_request(:post , "users/#{url_encode(user_id)}", body: user_payload) end |
#track(user_id:, action:, attributes:) ⇒ Object
64 65 66 67 68 |
# File 'lib/authsignal/client.rb', line 64 def track(user_id:, action:, attributes:) path = "users/#{user_id}/actions/#{action}" make_request(:post, path, body: attributes) end |
#update_action(user_id:, action:, idempotency_key:, attributes:) ⇒ Object
81 82 83 |
# File 'lib/authsignal/client.rb', line 81 def update_action(user_id:, action:, idempotency_key:, attributes:) make_request(:patch, "users/#{url_encode(user_id)}/actions/#{action}/#{url_encode(idempotency_key)}", body: attributes) end |
#update_user(user_id:, attributes:) ⇒ Object
44 45 46 |
# File 'lib/authsignal/client.rb', line 44 def update_user(user_id:, attributes:) make_request(:post, "users/#{url_encode(user_id)}", body: attributes) end |
#validate_challenge(token:, user_id: nil, action: nil) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/authsignal/client.rb', line 70 def validate_challenge(token:, user_id: nil, action: nil) path = "validate" body = { user_id: user_id, token: token, action: action } make_request(:post, path, body: body) end |