Skip to content

Commit

Permalink
[65715] Add Event conferencing support (#320)
Browse files Browse the repository at this point in the history
This PR enables support for the new Nylas Conference Sync (Beta) feature as well as support for auto generating conference details. If you have an integration authorized and enabled for your Nylas account you can provide an autocreate object instead of a details object to have the Nylas API autofill the conferencing details.
  • Loading branch information
mrashed-dev authored Sep 23, 2021
1 parent e235fb5 commit 3060b56
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

### Unreleased
* Add support for Event Conferencing
* Fix update draft failing if version is not explicitly set
* Fix draft `.send` logic

Expand Down
6 changes: 6 additions & 0 deletions lib/nylas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
require_relative "nylas/when"
require_relative "nylas/free_busy"
require_relative "nylas/time_slot"
require_relative "nylas/event_conferencing"
require_relative "nylas/event_conferencing_details"
require_relative "nylas/event_conferencing_autocreate"

# Custom collection types
require_relative "nylas/search_collection"
Expand Down Expand Up @@ -123,6 +126,9 @@ module Nylas
Types.registry[:contact_group] = Types::ModelType.new(model: ContactGroup)
Types.registry[:when] = Types::ModelType.new(model: When)
Types.registry[:time_slot] = Types::ModelType.new(model: TimeSlot)
Types.registry[:event_conferencing] = Types::ModelType.new(model: EventConferencing)
Types.registry[:event_conferencing_details] = Types::ModelType.new(model: EventConferencingDetails)
Types.registry[:event_conferencing_autocreate] = Types::ModelType.new(model: EventConferencingAutocreate)
Types.registry[:neural] = Types::ModelType.new(model: Neural)
Types.registry[:categorize] = Types::ModelType.new(model: Categorize)
Types.registry[:neural_signature_contact] = Types::ModelType.new(model: NeuralSignatureContact)
Expand Down
12 changes: 12 additions & 0 deletions lib/nylas/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Event
attribute :title, :string
attribute :when, :when
attribute :metadata, :hash
attribute :conferencing, :event_conferencing
attribute :original_start_time, :unix_timestamp

attr_accessor :notify_participants
Expand All @@ -40,6 +41,17 @@ def read_only?
read_only
end

def save
if conferencing
body = to_h
if body.dig(:conferencing, :details) && body.dig(:conferencing, :autocreate)
raise ArgumentError, "Cannot set both 'details' and 'autocreate' in conferencing object."
end
end

super
end

def rsvp(status, notify_participants:)
rsvp = Rsvp.new(api: api, status: status, notify_participants: notify_participants,
event_id: id, account_id: account_id)
Expand Down
12 changes: 12 additions & 0 deletions lib/nylas/event_conferencing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module Nylas
# Structure to represent the Event Conferencing object
# @see https://developer.nylas.com/docs/connectivity/calendar/conference-sync-beta
class EventConferencing
include Model::Attributable
attribute :provider, :string
attribute :details, :event_conferencing_details
attribute :autocreate, :event_conferencing_autocreate
end
end
10 changes: 10 additions & 0 deletions lib/nylas/event_conferencing_autocreate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Nylas
# Structure to represent the autocreate object within the Event Conferencing object
# @see https://developer.nylas.com/docs/connectivity/calendar/conference-sync-beta
class EventConferencingAutocreate
include Model::Attributable
attribute :settings, :hash, default: {}
end
end
14 changes: 14 additions & 0 deletions lib/nylas/event_conferencing_details.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Nylas
# Structure to represent the details object within the Event Conferencing object
# @see https://developer.nylas.com/docs/connectivity/calendar/conference-sync-beta
class EventConferencingDetails
include Model::Attributable
attribute :meeting_code, :string
attribute :password, :string
attribute :pin, :string
attribute :url, :string
has_n_of_attribute :phone, :string
end
end
2 changes: 2 additions & 0 deletions lib/nylas/model/attributable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def to_h

def assign(**data)
data.each do |attribute_name, value|
next if value.nil?

if respond_to?(:"#{attribute_name}=")
send(:"#{attribute_name}=", value)
end
Expand Down
4 changes: 3 additions & 1 deletion lib/nylas/model/attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ def merge(new_data)
def to_h(keys: attribute_definitions.keys)
keys.each_with_object({}) do |key, casted_data|
value = attribute_definitions[key].serialize(self[key])
casted_data[key] = value unless value.nil? || (value.respond_to?(:empty?) && value.empty?)
# If the value is an empty hash but we specify that it is valid (via default value), serialize it
casted_data[key] = value unless value.nil? || (value.respond_to?(:empty?) && value.empty? &&
!(attribute_definitions[key].default == value && value.is_a?(Hash)))
end
end

Expand Down
119 changes: 119 additions & 0 deletions spec/nylas/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
},
metadata: {
"event_type": "gathering"
},
conferencing: {
provider: "Zoom Meeting",
details: {
url: "https://us02web.zoom.us/j/****************",
meeting_code: "213",
password: "xyz",
phone: [
"+11234567890"
]
}
}
}

Expand Down Expand Up @@ -69,6 +80,11 @@
expect(event.when).to cover(Time.at(1_511_306_400))
expect(event.when).not_to cover(Time.at(1_511_306_401))
expect(event.metadata[:event_type]).to eql "gathering"
expect(event.conferencing.provider).to eql "Zoom Meeting"
expect(event.conferencing.details.url).to eql "https://us02web.zoom.us/j/****************"
expect(event.conferencing.details.meeting_code).to eql "213"
expect(event.conferencing.details.password).to eql "xyz"
expect(event.conferencing.details.phone).to eql ["+11234567890"]
end
end

Expand Down Expand Up @@ -230,6 +246,109 @@
query: {}
)
end

it "sends the conferencing autocreate object even if settings is empty" do
api = instance_double(Nylas::API)
allow(api).to receive(:execute).and_return({})
data = {
id: "event-id",
calendar_id: "cal-0987",
conferencing: {
provider: "Zoom meetings",
autocreate: {
settings: {}
}
}
}
event = described_class.from_json(JSON.dump(data), api: api)

event.save

expect(api).to have_received(:execute).with(
method: :put,
path: "/events/event-id",
payload: {
calendar_id: "cal-0987",
conferencing: {
provider: "Zoom meetings",
autocreate: {
settings: {}
}
}
}.to_json,
query: {}
)
end

it "sends the conferencing object if details alone is set" do
api = instance_double(Nylas::API)
allow(api).to receive(:execute).and_return({})
data = {
id: "event-id",
calendar_id: "cal-0987",
conferencing: {
provider: "Zoom meetings",
details: {
url: "https://us02web.zoom.us/j/****************",
meeting_code: "213",
password: "xyz",
phone: [
"+11234567890"
]
}
}
}
event = described_class.from_json(JSON.dump(data), api: api)

event.save

expect(api).to have_received(:execute).with(
method: :put,
path: "/events/event-id",
payload: {
calendar_id: "cal-0987",
conferencing: {
provider: "Zoom meetings",
details: {
meeting_code: "213",
password: "xyz",
url: "https://us02web.zoom.us/j/****************",
phone: [
"+11234567890"
]
}
}
}.to_json,
query: {}
)
end

it "throws an error if both conferencing details and autocreate are set" do
api = instance_double(Nylas::API)
allow(api).to receive(:execute).and_return({})
data = {
id: "event-id",
calendar_id: "cal-0987",
conferencing: {
provider: "Zoom meetings",
details: {
url: "https://us02web.zoom.us/j/****************",
meeting_code: "213",
password: "xyz",
phone: [
"+11234567890"
]
},
autocreate: {
settings: {}
}
}
}
event = described_class.from_json(JSON.dump(data), api: api)
error = "Cannot set both 'details' and 'autocreate' in conferencing object."

expect { event.save }.to raise_error(ArgumentError, error)
end
end
end

Expand Down

0 comments on commit 3060b56

Please sign in to comment.