Skip to content

Commit

Permalink
added list of castle events
Browse files Browse the repository at this point in the history
  • Loading branch information
bartes committed Mar 16, 2020
1 parent 7c141ff commit 80bedc5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ If you need to modify the event context properties or if you desire to add addit
```ruby
request_context = ::Castle::Client.to_context(request)
track_options = ::Castle::Client.to_options({
event: '$login.succeeded',
event: ::Castle::Events::LOGIN_SUCCEEDED,
user_id: user.id,
ip: request_context.headers["x-forwarded-for"].split(',')[0]
properties: {
Expand All @@ -119,7 +119,7 @@ Here is a simple example of a track event.
```ruby
begin
castle.track(
event: '$login.succeeded',
event: ::Castle::Events::LOGIN_SUCCEEDED,
user_id: user.id
)
rescue Castle::Error => e
Expand Down Expand Up @@ -153,7 +153,7 @@ end
```ruby
request_context = ::Castle::Client.to_context(request)
track_options = ::Castle::Client.to_options({
event: '$login.succeeded',
event: ::Castle::Events::LOGIN_SUCCEEDED,
user_id: user.id,
properties: {
key: 'value'
Expand All @@ -165,6 +165,10 @@ track_options = ::Castle::Client.to_options({
CastleTrackingWorker.perform_async(request_context, track_options)
```

## Events

List of Recognized Events can be found [here](https://github.com/castle/castle-ruby/tree/master/lib/castle/events.rb) or in the [docs](https://docs.castle.io/api_reference/#list-of-recognized-events)

## Impersonation mode

https://castle.io/docs/impersonation_mode
Expand Down
1 change: 1 addition & 0 deletions lib/castle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

%w[
castle/version
castle/events
castle/errors
castle/command
castle/utils
Expand Down
48 changes: 48 additions & 0 deletions lib/castle/events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

module Castle
# list of events based on https://docs.castle.io/api_reference/#list-of-recognized-events
module Events
# Record when a user succesfully logs in.
LOGIN_SUCCEEDED = '$login.succeeded'
# Record when a user failed to log in.
LOGIN_FAILED = '$login.failed'
# Record when a user logs out.
LOGOUT_SUCCEEDED = '$logout.succeeded'
# Record when a user updated their profile (including password, email, phone, etc).
PROFILE_UPDATE_SUCCEEDED = '$profile_update.succeeded'
# Record errors when updating profile.
PROFILE_UPDATE_FAILED = '$profile_update.failed'
# Capture account creation, both when a user signs up as well as when created manually
# by an administrator.
REGISTRATION_SUCCEEDED = '$registration.succeeded'
# Record when an account failed to be created.
REGISTRATION_FAILED = '$registration.failed'
# The user completed all of the steps in the password reset process and the password was
# successfully reset.Password resets do not required knowledge of the current password.
PASSWORD_RESET_SUCCEEDED = '$password_reset.succeeded'
# Use to record when a user failed to reset their password.
PASSWORD_RESET_FAILED = '$password_reset.failed'
# The user successfully requested a password reset.
PASSWORD_RESET_REQUEST_SUCCCEEDED = '$password_reset_request.succeeded'
# The user failed to request a password reset.
PASSWORD_RESET_REQUEST_FAILED = '$password_reset_request.failed'
# User account has been reset.
INCIDENT_MITIGATED = '$incident.mitigated'
# User confirmed malicious activity.
REVIEW_ESCALATED = '$review.escalated'
# User confirmed safe activity.
REVIEW_RESOLVED = '$review.resolved'
# Record when a user is prompted with additional verification, such as two-factor
# authentication or a captcha.
CHALLENGE_REQUESTED = '$challenge.requested'
# Record when additional verification was successful.
CHALLENGE_SUCCEEDED = '$challenge.succeeded'
# Record when additional verification failed.
CHALLENGE_FAILED = '$challenge.failed'
# Record when a user attempts an in-app transaction, such as a purchase or withdrawal.
TRANSACTION_ATTEMPTED = '$transaction.attempted'
# Record when a user session is extended, or use any time you want to re-authenticate a user mid-session.
SESSION_EXTENDED = '$session.extended'
end
end
5 changes: 5 additions & 0 deletions spec/lib/castle/events_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

describe Castle::Events do
it { expect(described_class::LOGIN_SUCCEEDED).to eq('$login.succeeded') }
end

0 comments on commit 80bedc5

Please sign in to comment.