Module: WorkOS::Events

Extended by:
Client
Defined in:
lib/workos/events.rb

Overview

The Events module provides convenience methods for working with the WorkOS Events platform. You’ll need a valid API key and be in the Events beta to be able to access the API

Class Method Summary collapse

Methods included from Client

client, delete_request, execute_request, get_request, handle_error_response, post_request, put_request, user_agent

Class Method Details

.list_events(options = {}) ⇒ Hash

Retrieve events.

Parameters:

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

    An options hash

Options Hash (options):

  • event (String)

    The type of event

  • organization_id (String)

    Limit scope of events to an organization

  • limit (String)

    Maximum number of records to return.

  • after (String)

    Pagination cursor to receive records after a provided Event ID.

Returns:

  • (Hash)

Raises:

  • (ArgumentError)


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

def list_events(options = {})
  raise ArgumentError, 'Events parameter is required.' if options[:events].nil?

  response = execute_request(
    request: get_request(
      path: '/events',
      auth: true,
      params: options,
    ),
  )

  parsed_response = JSON.parse(response.body)
  events = parsed_response['data'].map do |event|
    ::WorkOS::Event.new(event.to_json)
  end

  WorkOS::Types::ListStruct.new(
    data: events,
    list_metadata: parsed_response['list_metadata'],
  )
end