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(before: nil, after: nil, limit: nil, order: "desc", events: nil, range_start: nil, range_end: nil, organization_id: nil, request_options: {}) ⇒ WorkOS::Types::ListStruct<WorkOS::EventSchema>

List events

Parameters:

  • before (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 `before=“obj_123”` to fetch a new batch of objects before `“obj_123”`.

  • 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: nil)

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

  • order (WorkOS::Types::EventsOrder, nil) (defaults to: "desc")

    Order the results by the creation time. Supported values are ‘“asc”` (ascending), `“desc”` (descending), and `“normal”` (descending with reversed cursor semantics where `before` fetches older records and `after` fetches newer records). Defaults to descending.

  • events (Array<String>, nil) (defaults to: nil)

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

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

    ISO-8601 date string to filter events created after this date.

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

    ISO-8601 date string to filter events created before this date.

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

    Filter events by the [Organization](workos.com/docs/reference/organization) that the event is associated with.

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

    (see WorkOS::Types::RequestOptions)

Returns:



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
64
65
66
67
68
69
70
71
# File 'lib/workos/events.rb', line 24

def list_events(
  before: nil,
  after: nil,
  limit: nil,
  order: "desc",
  events: nil,
  range_start: nil,
  range_end: nil,
  organization_id: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "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(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      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: {before: before, limit: limit, order: order, events: events, range_start: range_start, range_end: range_end, organization_id: organization_id},
    fetch_next: fetch_next
  )
end