Class: WorkOS::Events

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Events

Returns a new instance of Events.



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

def initialize(client)
  @client = client
end

Instance Method Details

#list_events(events:, after: nil, limit: 10, range_start: nil, range_end: nil, organization_id: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::EventSchema>

List events

Parameters:

  • after (String, nil) (defaults to: nil) —

    An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with "obj_123", your subsequent call can include after="obj_123" to fetch a new batch of objects after "obj_123".

  • limit (Integer, nil) (defaults to: 10) —

    Upper limit on the number of objects to return, between 1 and 100.

  • events (Array<String>) —

    Filter events by one or more event types (e.g. dsync.user.created).

  • range_start (String, nil) (defaults to: nil) —

    ISO 8601 UTC timestamp with a Z suffix to filter events created after this date. Timezone offsets such as +00:00 are not accepted.

  • range_end (String, nil) (defaults to: nil) —

    ISO 8601 UTC timestamp with a Z suffix to filter events created before this date. Timezone offsets such as +00:00 are not accepted.

  • organization_id (String, nil) (defaults to: nil) —

    Filter events by the Organization that the event is associated with.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/workos/events.rb', line 22

def list_events(
  events:,
  after: nil,
  limit: 10,
  range_start: nil,
  range_end: nil,
  organization_id: nil,
  request_options: {}
)
  params = {
    "after" => after,
    "limit" => limit,
    "events" => events,
    "range_start" => range_start,
    "range_end" => range_end,
    "organization_id" => organization_id
  }.compact
  response = @client.request(
    method: :get,
    path: "/events",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = ->(cursor) {
    list_events(
      after: cursor,
      limit: limit,
      events: events,
      range_start: range_start,
      range_end: range_end,
      organization_id: organization_id,
      request_options: request_options
    )
  }
  WorkOS::Types::ListStruct.from_response(
    response,
    model: WorkOS::EventSchema,
    filters: {limit: limit, events: events, range_start: range_start, range_end: range_end, organization_id: organization_id},
    fetch_next: fetch_next
  )
end