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::RadarListType)

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

  • action (WorkOS::Types::RadarListAction)

    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:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/workos/radar.rb', line 80

def add_list_entry(
  type:,
  action:,
  entry:,
  request_options: {}
)
  body = {
    "entry" => entry
  }
  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:, request_options: {}) ⇒ WorkOS::RadarStandaloneResponse

Create an attempt

Parameters:

Returns:



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

def create_attempt(
  ip_address:,
  user_agent:,
  email:,
  auth_method:,
  action:,
  request_options: {}
)
  body = {
    "ip_address" => ip_address,
    "user_agent" => user_agent,
    "email" => email,
    "auth_method" => auth_method,
    "action" => action
  }
  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::RadarListType)

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

  • action (WorkOS::Types::RadarListAction)

    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)



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/workos/radar.rb', line 107

def remove_list_entry(
  type:,
  action:,
  entry:,
  request_options: {}
)
  body = {
    "entry" => entry
  }
  @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)



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/workos/radar.rb', line 54

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