Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduling api #495

Merged
merged 15 commits into from
Oct 25, 2024
1 change: 1 addition & 0 deletions lib/nylas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
require_relative "nylas/resources/threads"
require_relative "nylas/resources/redirect_uris"
require_relative "nylas/resources/webhooks"
require_relative "nylas/resources/scheduler"

require_relative "nylas/utils/file_utils"
7 changes: 7 additions & 0 deletions lib/nylas/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require_relative "resources/webhooks"
require_relative "resources/applications"
require_relative "resources/folders"
require_relative "resources/scheduler"

module Nylas
# Methods to retrieve data from the Nylas API as Ruby objects.
Expand Down Expand Up @@ -117,5 +118,11 @@ def threads
def webhooks
Webhooks.new(self)
end

# The Scheduler resources for your Nylas application.
# @return [Nylas::Scheduler] Scheduler resources for your Nylas application.
def scheduler
Scheduler.new(self)
end
end
end
22 changes: 22 additions & 0 deletions lib/nylas/resources/availability.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require_relative "resource"
require_relative "../handler/api_operations"

module Nylas
# Nylas Messages API
class Availability < Resource
include ApiOperations::Get

# Return availabilities for a configuration.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Array(Hash), String, String)] The list of configurations, API Request ID,
# and next cursor.
def list(query_params: nil)
get_list(
path: "#{api_uri}/v3/scheduling/availability",
query_params: query_params
)
end
end
end
77 changes: 77 additions & 0 deletions lib/nylas/resources/bookings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# frozen_string_literal: true

require_relative "resource"
require_relative "../handler/api_operations"

module Nylas
# Nylas Messages API
class Bookings < Resource
include ApiOperations::Get
include ApiOperations::Post
include ApiOperations::Put
include ApiOperations::Delete
include ApiOperations::Patch

# Return a booking.
# @param booking_id [String] The id of the booking to return.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Hash, String)] The booking and API request ID.
def find(booking_id:, query_params:)
get(
path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}",
query_params: query_params
)
end

# Create a booking.
# @param request_body [Hash] The values to create the booking with.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Hash, String)] The created booking and API Request ID.
def create(request_body:, query_params:)
post(
path: "#{api_uri}/v3/scheduling/bookings",
request_body: request_body,
query_params: query_params
)
end

# Create a booking.
# @param request_body [Hash] The values to update the booking with.
# @param booking_id [String] The id of the booking to update.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Hash, String)] The created booking and API Request ID.
def update(request_body:, booking_id:, query_params:)
patch(
path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}",
request_body: request_body,
query_params: query_params
)
end

# Confirm a booking.
# @param booking_id [String] The id of the booking to confirm.
# @param request_body [Hash] The values to update the booking with
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Hash, String)] The updated booking and API Request ID.
def confirm_booking(booking_id:, request_body:, query_params:)
put(
path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}",
request_body: request_body,
query_params: query_params
)
end

# Delete a booking.
# @param booking_id [String] The id of the booking to delete.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
def destroy(booking_id:, query_params:)
_, request_id = delete(
path: "#{api_uri}/v3/scheduling/bookings/#{booking_id}",
query_params: query_params
)

[true, request_id]
end
end
end
76 changes: 76 additions & 0 deletions lib/nylas/resources/configurations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# frozen_string_literal: true

require_relative "resource"
require_relative "../handler/api_operations"

module Nylas
# Nylas Scheduler Configurations API
class Configurations < Resource
include ApiOperations::Get
include ApiOperations::Post
include ApiOperations::Put
include ApiOperations::Delete

# Return all Scheduler Configurations.
#
# @param identifier [String] Grant ID or email account to query.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Array(Hash), String, String)] The list of configurations, API Request ID,
# and next cursor.
def list(identifier:, query_params: nil)
get_list(
path: "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations",
query_params: query_params
)
end

# Return a Configuration.
#
# @param identifier [String] Grant ID or email account to query.
# @param configuration_id [String] The id of the configuration to return.
# @return [Array(Hash, String)] The configuration and API request ID.
def find(identifier:, configuration_id:)
get(
path: "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations/#{configuration_id}"
)
end

# Create a configuration.
#
# @param identifier [String] Grant ID or email account in which to create the object.
# @param request_body [Hash] The values to create the configuration with.
# @return [Array(Hash, String)] The created configuration and API Request ID.
def create(identifier:, request_body:)
post(
path: "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations",
request_body: request_body
)
end

# Update a configuration.
#
# @param identifier [String] Grant ID or email account in which to update an object.
# @param configuration_id [String] The id of the configuration to update.
# @param request_body [Hash] The values to update the configuration with
# @return [Array(Hash, String)] The updated configuration and API Request ID.
def update(identifier:, configuration_id:, request_body:)
put(
path: "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations/#{configuration_id}",
request_body: request_body
)
end

# Delete a configuration.
#
# @param identifier [String] Grant ID or email account from which to delete an object.
# @param configuration_id [String] The id of the configuration to delete.
# @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
def destroy(identifier:, configuration_id:)
_, request_id = delete(
path: "#{api_uri}/v3/grants/#{identifier}/scheduling/configurations/#{configuration_id}"
)

[true, request_id]
end
end
end
35 changes: 35 additions & 0 deletions lib/nylas/resources/scheduler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require_relative "./configurations"
require_relative "./sessions"
require_relative "./bookings"
require_relative "./availability"

module Nylas
# Nylas Scheduler API
# This class provides access to the Scheduler resources, including
# configurations, bookings, sessions, and availability.
#
# @attr_reader [Nylas::Configurations] configurations The Scheduler configurations resource for your
# Nylas application.
# @attr_reader [Nylas::Bookings] bookings The Scheduler bookings resource for your
# Nylas application.
# @attr_reader [Nylas::Sessions] sessions The Scheduler sessions resource for your
# Nylas application.
# @attr_reader [Nylas::Availability] availability The Scheduler availability resource for your
# Nylas application.
class Scheduler
attr_reader :configurations, :sessions, :bookings, :availability

# Initializes the Scheduler class.
#
# @param api_client [APIClient] The Nylas API client instance for making requests.
def initialize(api_client)
@api_client = api_client
@configurations = Configurations.new(@api_client)
@bookings = Bookings.new(@api_client)
@sessions = Sessions.new(@api_client)
@availability = Availability.new(@api_client)
end
end
end
33 changes: 33 additions & 0 deletions lib/nylas/resources/sessions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require_relative "resource"
require_relative "../handler/api_operations"

module Nylas
# Nylas Messages API
class Sessions < Resource
include ApiOperations::Post
include ApiOperations::Delete

# Create a session for a configuration.
# @param request_body [Hash] The values to create a configuration sessions.
# @return [Array(Hash, String)] The created configuration and API Request ID.
def create(request_body:)
post(
path: "#{api_uri}/v3/scheduling/sessions",
request_body: request_body
)
end

# Delete a session for a configuration.
# @param session_id [String] The id of the session to delete.
# @return [Array(TrueClass, String)] True and the API Request ID for the delete operation.
def destroy(session_id:)
_, request_id = delete(
path: "#{api_uri}/v3/scheduling/sessions/#{session_id}"
)

[true, request_id]
end
end
end
35 changes: 35 additions & 0 deletions spec/nylas/resources/availability_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

describe Nylas::Availability do
let(:availability) { described_class.new(client) }
let(:response) do
[{
"emails": ["user1@example.com"],
"start_time": 1659367800,
"end_time": 1659369600
},
{
"emails": ["user1@example.com"],
"start_time": 1659376800,
"end_time": 1659378600
}]
end

describe "#list" do
let(:list_response) do
response
end

it "calls the get method with the correct parameters" do
query_params = { "start_time": 1659376800, "end_time": 1659369600,
configuration_id: "confifiguration-123" }
path = "#{api_uri}/v3/scheduling/availability"
allow(availability).to receive(:get_list)
.with(path: path, query_params: query_params)
.and_return(list_response)

availability_response = availability.list(query_params: query_params)
expect(availability_response).to eq(list_response)
end
end
end
Loading
Loading