Skip to content

Commit

Permalink
Merge branch 'main' into attach_file_custom_filename
Browse files Browse the repository at this point in the history
  • Loading branch information
SubashPradhan authored Nov 7, 2024
2 parents 24c194b + 25b9aad commit b260359
Show file tree
Hide file tree
Showing 16 changed files with 756 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### Unreleased
* Added support for scheduler APIs
* Added `query_params` field to `Folders` & `Threads` find


### 6.2.0 / 2024-09-24
* Added query support for folders
* Added dependency on `ostruct` gem
Expand Down
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
6 changes: 4 additions & 2 deletions lib/nylas/resources/folders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ def list(identifier:, query_params: nil)
#
# @param identifier [String] Grant ID or email account to query.
# @param folder_id [String] The id of the folder to return.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Hash, String)] The folder and API request ID.
def find(identifier:, folder_id:)
def find(identifier:, folder_id:, query_params: nil)
get(
path: "#{api_uri}/v3/grants/#{identifier}/folders/#{folder_id}"
path: "#{api_uri}/v3/grants/#{identifier}/folders/#{folder_id}",
query_params: query_params
)
end

Expand Down
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
6 changes: 4 additions & 2 deletions lib/nylas/resources/threads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ def list(identifier:, query_params: nil)
#
# @param identifier [String] Grant ID or email account to query.
# @param thread_id [String] The id of the thread to return.
# @param query_params [Hash, nil] Query params to pass to the request.
# @return [Array(Hash, String)] The thread and API request ID.
def find(identifier:, thread_id:)
def find(identifier:, thread_id:, query_params: nil)
get(
path: "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}"
path: "#{api_uri}/v3/grants/#{identifier}/threads/#{thread_id}",
query_params: query_params
)
end

Expand Down
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": ["[email protected]"],
"start_time": 1659367800,
"end_time": 1659369600
},
{
"emails": ["[email protected]"],
"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

0 comments on commit b260359

Please sign in to comment.