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

v6.0.0 beta 2 release #436

Merged
merged 6 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Changelog

### 6.0.0-beta.2 / TBD
### 6.0.0-beta.2 / 2023-11-21
* Added additional error classes
* Added support for free/busy endpoint
* Added support for Messages, Drafts, and Smart Compose APIs
* Added support for custom authentication, connectors, and credentials APIs
* Added support for folders API
* Added support for attachments API
* Set default timeout to 30 seconds

### 6.0.0-beta.1 / 2023-08-16
Expand Down
42 changes: 27 additions & 15 deletions lib/nylas/handler/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,14 @@ def execute(method:, path:, timeout:, headers: {}, query: {}, payload: nil, api_
# @return [nil, String] Returns nil when a block is given (streaming mode).
# When no block is provided, the return is the entire raw response body.
def download_request(path:, timeout:, headers: {}, query: {}, api_key: nil, &block)
request = build_request(method: :get, path: path, headers: headers,
query: query, api_key: api_key, timeout: timeout)
uri = URI(request[:url])
request, uri, http = setup_http(path, timeout, headers, query, api_key)

begin
Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: timeout,
open_timeout: timeout) do |http|
http.start do |setup_http|
get_request = Net::HTTP::Get.new(uri)
request[:headers].each { |key, value| get_request[key] = value }

http.request(get_request) do |response|
if response.is_a?(Net::HTTPSuccess)
return response.body unless block_given?

response.read_body(&block)
else
parse_json_evaluate_error(response.code.to_i, response.body, path, response["Content-Type"])
break
end
end
handle_response(setup_http, get_request, path, &block)
end
rescue Net::OpenTimeout, Net::ReadTimeout
raise Nylas::NylasSdkTimeoutError.new(request[:url], timeout)
Expand Down Expand Up @@ -148,6 +136,30 @@ def rest_client_execute(method:, url:, headers:, payload:, timeout:, &block)
headers: headers, timeout: timeout, &block)
end

def setup_http(path, timeout, headers, query, api_key)
request = build_request(method: :get, path: path, headers: headers,
query: query, api_key: api_key, timeout: timeout)
uri = URI(request[:url])
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.read_timeout = timeout
http.open_timeout = timeout
[request, uri, http]
end

def handle_response(http, get_request, path, &block)
http.request(get_request) do |response|
if response.is_a?(Net::HTTPSuccess)
return response.body unless block_given?

response.read_body(&block)
else
parse_json_evaluate_error(response.code.to_i, response.body, path, response["Content-Type"])
break
end
end
end

# Parses the response from the Nylas API and evaluates for errors.
def parse_json_evaluate_error(http_code, response, path, content_type = nil)
begin
Expand Down
2 changes: 1 addition & 1 deletion lib/nylas/resources/smart_compose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def compose_message(identifier:, request_body:)
#
# @param identifier [String] Grant ID or email account to generate a message suggestion for.
# @param message_id [String] The id of the message to reply to.
# @param request_body [Hash] The prompt that smart compose will use to generate a message reply suggestion.
# @param request_body [Hash] The prompt that smart compose will use to generate a message reply.
# @return [Array(Hash, String)] The generated message reply and API Request ID.
def compose_message_reply(identifier:, message_id:, request_body:)
post(
Expand Down
26 changes: 13 additions & 13 deletions lib/nylas/resources/webhooks.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: trues
# frozen_string_literal: true

require_relative "resource"
require_relative "../handler/api_operations"
Expand All @@ -7,18 +7,18 @@ module Nylas
# Module representing the possible 'trigger' values in a Webhook.
# @see https://developer.nylas.com/docs/api#post/a/client_id/webhooks
module WebhookTrigger
CALENDAR_CREATED = "calendar.created".freeze
CALENDAR_UPDATED = "calendar.updated".freeze
CALENDAR_DELETED = "calendar.deleted".freeze
EVENT_CREATED = "event.created".freeze
EVENT_UPDATED = "event.updated".freeze
EVENT_DELETED = "event.deleted".freeze
GRANT_CREATED = "grant.created".freeze
GRANT_UPDATED = "grant.updated".freeze
GRANT_DELETED = "grant.deleted".freeze
GRANT_EXPIRED = "grant.expired".freeze
MESSAGE_SEND_SUCCESS = "message.send_success".freeze
MESSAGE_SEND_FAILED = "message.send_failed".freeze
CALENDAR_CREATED = "calendar.created"
CALENDAR_UPDATED = "calendar.updated"
CALENDAR_DELETED = "calendar.deleted"
EVENT_CREATED = "event.created"
EVENT_UPDATED = "event.updated"
EVENT_DELETED = "event.deleted"
GRANT_CREATED = "grant.created"
GRANT_UPDATED = "grant.updated"
GRANT_DELETED = "grant.deleted"
GRANT_EXPIRED = "grant.expired"
MESSAGE_SEND_SUCCESS = "message.send_success"
MESSAGE_SEND_FAILED = "message.send_failed"
end

# Nylas Webhooks API
Expand Down
2 changes: 1 addition & 1 deletion lib/nylas/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Nylas
VERSION = "6.0.0.beta.1"
VERSION = "6.0.0.beta.2"
end
Loading