Class: Nylas::Events

Inherits:
Resource show all
Includes:
ApiOperations::Delete, ApiOperations::Get, ApiOperations::Post, ApiOperations::Put
Defined in:
lib/nylas/resources/events.rb

Overview

Nylas Events API

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Nylas::Resource

Instance Method Details

#batch(identifier:, request_body:, query_params:) ⇒ Array(Array<Hash>, String, Hash)

Create, update, or delete events in one request (Google and Microsoft).

Results follow the operation order. Both 200 and 207 responses return normally; inspect each result's status and error, even when every operation failed. The API validates the operations and batch size. No operations are retried automatically.

Parameters:

  • identifier (String) —

    Grant ID or email account in which to modify events.

  • request_body (Hash) —

    The batch request.

  • query_params (Hash) —

    Query parameters applied to every operation.

Options Hash (request_body:):

  • :operations (Array<Hash>) —

    The event operations to execute. Each operation has a :method of "create", "update", or "delete". Create and update require :body, using the same event Hash as #create or #update. Update and delete require :event_id [String].

Options Hash (query_params:):

  • :calendar_id (String) —

    The required calendar ID.

  • :notify_participants (Boolean) —

    Defaults to true on the server. Microsoft does not support false.

  • :grant_email (String) —

    Optional grant email.

  • :tentative_as_busy (Boolean) —

    Whether tentative events count as busy.

  • :select (String) —

    Comma-separated event fields to return.

Returns:

  • (Array(Array<Hash>, String, Hash)) —

    Ordered results, API request ID, and response headers. Each result has :status [Integer], optional :data [Hash] with the event for a successful create or update, and optional :error [Hash] with :type [String], :message [String], and :provider_error [Hash]. A successful delete has no :data. Failed results may include :retry_after [Numeric] (seconds, including zero) and :provider_event_created [Boolean]. Never retry an operation with :provider_event_created set to true; it would create a duplicate.

Raises:

  • (ArgumentError) —

    If the grant identifier is not a nonblank String or is a URL dot segment.



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/nylas/resources/events.rb', line 81

def batch(identifier:, request_body:, query_params:)
  unless identifier.is_a?(String) && !identifier.strip.empty? && !%w[. ..].include?(identifier.strip)
    raise ArgumentError, "Invalid grant identifier."
  end

  encoded_identifier = URI.encode_www_form_component(identifier).gsub("+", "%20")
  post(
    path: "#{api_uri}/v3/grants/#{encoded_identifier}/events/batch",
    query_params: query_params,
    request_body: request_body
  )
end

#create(identifier:, request_body:, query_params:) ⇒ Array(Hash, String)

Create an event.

Parameters:

  • identifier (String) —

    Grant ID or email account in which to create the object.

  • request_body (Hash) —

    The values to create the event with. This can include a notetaker object with settings for the Notetaker bot.

  • query_params (Hash) —

    The query parameters to include in the request.

Returns:

  • (Array(Hash, String)) —

    The created event and API Request ID.



47
48
49
50
51
52
53
# File 'lib/nylas/resources/events.rb', line 47

def create(identifier:, request_body:, query_params:)
  post(
    path: "#{api_uri}/v3/grants/#{identifier}/events",
    query_params: query_params,
    request_body: request_body
  )
end

#destroy(identifier:, event_id:, query_params:) ⇒ Array(TrueClass, String)

Delete an event.

Parameters:

  • identifier (String) —

    Grant ID or email account from which to delete an object.

  • event_id (String) —

    The id of the event to delete.

  • query_params (Hash) —

    The query parameters to include in the request

Returns:

  • (Array(TrueClass, String)) —

    True and the API Request ID for the delete operation.



116
117
118
119
120
121
122
123
# File 'lib/nylas/resources/events.rb', line 116

def destroy(identifier:, event_id:, query_params:)
  _, request_id = delete(
    path: "#{api_uri}/v3/grants/#{identifier}/events/#{event_id}",
    query_params: query_params
  )

  [true, request_id]
end

#find(identifier:, event_id:, query_params:) ⇒ Array(Hash, String)

Return an event.

Parameters:

  • identifier (String) —

    Grant ID or email account to query.

  • event_id (String) —

    The id of the event to return.

  • query_params (Hash) —

    The query parameters to include in the request

Returns:

  • (Array(Hash, String)) —

    The event and API request ID.



33
34
35
36
37
38
# File 'lib/nylas/resources/events.rb', line 33

def find(identifier:, event_id:, query_params:)
  get(
    path: "#{api_uri}/v3/grants/#{identifier}/events/#{event_id}",
    query_params: query_params
  )
end

#list(identifier:, query_params:) ⇒ Array(Array(Hash), String, String)

Return all events.

Parameters:

  • identifier (String) —

    Grant ID or email account to query.

  • query_params (Hash) —

    Query params to pass to the request.

Returns:

  • (Array(Array(Hash), String, String)) —

    The list of events, API Request ID, and next cursor.



20
21
22
23
24
25
# File 'lib/nylas/resources/events.rb', line 20

def list(identifier:, query_params:)
  get_list(
    path: "#{api_uri}/v3/grants/#{identifier}/events",
    query_params: query_params
  )
end

#list_import_events(identifier:, query_params:) ⇒ (Array(Hash), String, String)

Returns a list of recurring events, recurring event exceptions, and single events from the specified calendar within a given time frame. This is useful when you want to import, store, and synchronize events from the time frame to your application

Parameters:

  • identifier (String) —

    Grant ID or email account to import events from.

  • query_params (Hash) —

    The query parameters to include in the request

Returns:

  • ((Array(Hash), String, String)) —

    The list of events, API Request ID, and next cursor.



147
148
149
150
151
152
# File 'lib/nylas/resources/events.rb', line 147

def list_import_events(identifier:, query_params:)
  get_list(
    path: "#{api_uri}/v3/grants/#{identifier}/events/import",
    query_params: query_params
  )
end

#send_rsvp(identifier:, event_id:, request_body:, query_params:) ⇒ (Hash, String)

Send RSVP. Allows users to respond to events they have been added to as an attendee.

Parameters:

  • identifier (String) —

    Grant ID or email account from which to send RSVP with.

  • event_id (String) —

    The id of the event to respond to.

  • request_body (Hash) —

    The status values to send the RSVP with.

  • query_params (Hash) —

    The query parameters to include in the request

Returns:

  • ((Hash, String)) —

    Response object with the API Request ID.



132
133
134
135
136
137
138
# File 'lib/nylas/resources/events.rb', line 132

def send_rsvp(identifier:, event_id:, request_body:, query_params:)
  post(
    path: "#{api_uri}/v3/grants/#{identifier}/events/#{event_id}/send-rsvp",
    query_params: query_params,
    request_body: request_body
  )
end

#update(identifier:, event_id:, request_body:, query_params:) ⇒ Array(Hash, String)

Update an event.

Parameters:

  • identifier (String) —

    Grant ID or email account in which to update an object.

  • event_id (String) —

    The id of the event to update.

  • request_body (Hash) —

    The values to update the event with. This can include a notetaker object with settings for the Notetaker bot.

  • query_params (Hash) —

    The query parameters to include in the request

Returns:

  • (Array(Hash, String)) —

    The updated event and API Request ID.



102
103
104
105
106
107
108
# File 'lib/nylas/resources/events.rb', line 102

def update(identifier:, event_id:, request_body:, query_params:)
  put(
    path: "#{api_uri}/v3/grants/#{identifier}/events/#{event_id}",
    query_params: query_params,
    request_body: request_body
  )
end