Class: WorkOS::Radar

Inherits:
Object
  • Object
show all
Defined in:
lib/workos/radar.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Radar

Returns a new instance of Radar.



9
10
11
# File 'lib/workos/radar.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#add_list_entry(type:, action:, entry:, request_options: {}) ⇒ WorkOS::RadarListEntryAlreadyPresentResponse

Add an entry to a Radar list

Parameters:

  • type (WorkOS::Types::RadarType)

    The type of the Radar list (e.g. ip_address, domain, email).

  • action (WorkOS::Types::RadarAction)

    The list action indicating whether to add the entry to the allow or block list.

  • entry (String)

    The value to add to the list. Must match the format of the list type (e.g. a valid IP address for ‘ip_address`, a valid email for `email`).

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/workos/radar.rb', line 86

def add_list_entry(
  type:,
  action:,
  entry:,
  request_options: {}
)
  body = {
    "entry" => entry
  }.compact
  response = @client.request(
    method: :post,
    path: "/radar/lists/#{WorkOS::Util.encode_path(type)}/#{WorkOS::Util.encode_path(action)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::RadarListEntryAlreadyPresentResponse.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#create_attempt(ip_address:, user_agent:, email:, auth_method:, action:, device_fingerprint: nil, bot_score: nil, request_options: {}) ⇒ WorkOS::RadarStandaloneResponse

Create an attempt

Parameters:

  • ip_address (String)

    The IP address of the request to assess.

  • user_agent (String)

    The user agent string of the request to assess.

  • email (String)

    The email address of the user making the request.

  • auth_method (WorkOS::Types::RadarStandaloneAssessRequestAuthMethod)

    The authentication method being used.

  • action (WorkOS::Types::RadarStandaloneAssessRequestAction)

    The action being performed.

  • device_fingerprint (String, nil) (defaults to: nil)

    An optional device fingerprint for the request.

  • bot_score (String, nil) (defaults to: nil)

    An optional bot detection score for the request.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/workos/radar.rb', line 23

def create_attempt(
  ip_address:,
  user_agent:,
  email:,
  auth_method:,
  action:,
  device_fingerprint: nil,
  bot_score: nil,
  request_options: {}
)
  body = {
    "ip_address" => ip_address,
    "user_agent" => user_agent,
    "email" => email,
    "auth_method" => auth_method,
    "action" => action,
    "device_fingerprint" => device_fingerprint,
    "bot_score" => bot_score
  }.compact
  response = @client.request(
    method: :post,
    path: "/radar/attempts",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = WorkOS::RadarStandaloneResponse.new(response.body)
  result.last_response = WorkOS::Types::ApiResponse.new(http_status: response.code.to_i, http_headers: response.each_header.to_h, request_id: response["x-request-id"])
  result
end

#remove_list_entry(type:, action:, entry:, request_options: {}) ⇒ void

This method returns an undefined value.

Remove an entry from a Radar list

Parameters:

  • type (WorkOS::Types::RadarType)

    The type of the Radar list (e.g. ip_address, domain, email).

  • action (WorkOS::Types::RadarAction)

    The list action indicating whether to remove the entry from the allow or block list.

  • entry (String)

    The value to remove from the list. Must match an existing entry.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/workos/radar.rb', line 113

def remove_list_entry(
  type:,
  action:,
  entry:,
  request_options: {}
)
  body = {
    "entry" => entry
  }.compact
  @client.request(
    method: :delete,
    path: "/radar/lists/#{WorkOS::Util.encode_path(type)}/#{WorkOS::Util.encode_path(action)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  nil
end

#update_attempt(id:, challenge_status: nil, attempt_status: nil, request_options: {}) ⇒ void

This method returns an undefined value.

Update a Radar attempt

Parameters:

  • id (String)

    The unique identifier of the Radar attempt to update.

  • challenge_status (String, nil) (defaults to: nil)

    Set to ‘“success”` to mark the challenge as completed.

  • attempt_status (String, nil) (defaults to: nil)

    Set to ‘“success”` to mark the authentication attempt as successful.

  • request_options (Hash) (defaults to: {})

    (see WorkOS::Types::RequestOptions)



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/workos/radar.rb', line 60

def update_attempt(
  id:,
  challenge_status: nil,
  attempt_status: nil,
  request_options: {}
)
  body = {
    "challenge_status" => challenge_status,
    "attempt_status" => attempt_status
  }.compact
  @client.request(
    method: :put,
    path: "/radar/attempts/#{WorkOS::Util.encode_path(id)}",
    auth: true,
    body: body,
    request_options: request_options
  )
  nil
end