From 403b3a5e3a733a7c98c089369ff9cc4c85b89c4f Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Wed, 29 Nov 2023 13:19:22 -0500 Subject: [PATCH 1/4] Add support for detect-provider endpoint --- lib/nylas/api.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/nylas/api.rb b/lib/nylas/api.rb index f8c2b09d..384295c4 100644 --- a/lib/nylas/api.rb +++ b/lib/nylas/api.rb @@ -200,6 +200,23 @@ def ip_addresses client.as(client.app_secret).get(path: path, auth_method: HttpClient::AuthMethod::BASIC) end + # Returns list of IP addresses + # @param email_address [String] The email address to detect the provider for + # @return [Hash] The provider information + # hash has keys of :updated_at (unix timestamp) and :ip_addresses (array of strings) + def detect_provider(email_address) + payload = { + "client_id" => app_id, + "client_secret" => client.app_secret, + "email_address" => email_address + } + response = client.as(client.app_secret).execute( + method: :post, + path: "/connect/detect-provider", + payload: JSON.dump(payload), + ) + end + # @param message [Hash, String, #send!] # @return [Message] The resulting message def send!(message) From 87a6ad23736db7f0cbfdc43640a3c1d2808d3e00 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Wed, 29 Nov 2023 13:19:47 -0500 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b08df54d..cadb196d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +### 5.17.0 / TBD +* Add support for detect provider endpoint + ### 5.17.0 / 2022-04-04 * Add support for verifying webhook signatures * Add `event.updated_at` From d63ee942bc8d0a44d7983857679c7bb2ce15fe80 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Wed, 29 Nov 2023 14:09:16 -0500 Subject: [PATCH 3/4] rubocop fixes --- lib/nylas/api.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/nylas/api.rb b/lib/nylas/api.rb index 384295c4..4d91f544 100644 --- a/lib/nylas/api.rb +++ b/lib/nylas/api.rb @@ -210,10 +210,11 @@ def detect_provider(email_address) "client_secret" => client.app_secret, "email_address" => email_address } - response = client.as(client.app_secret).execute( + + client.as(client.app_secret).execute( method: :post, path: "/connect/detect-provider", - payload: JSON.dump(payload), + payload: JSON.dump(payload) ) end From 98c7a360da0baefc1b7fb2588f7805825351ad78 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Wed, 29 Nov 2023 15:24:02 -0500 Subject: [PATCH 4/4] add test case for detect_provider --- spec/nylas/api_spec.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/spec/nylas/api_spec.rb b/spec/nylas/api_spec.rb index ee96885f..73b6b9c4 100644 --- a/spec/nylas/api_spec.rb +++ b/spec/nylas/api_spec.rb @@ -5,6 +5,39 @@ # This spec is the only one that should have any webmock stuff going on, everything else should use the # FakeAPI to see what requests were made and what they included. describe Nylas::API do + describe "#detect_provider" do + # tests the detect_providr method + it "returns the provider" do + url = "https://api.nylas.com/connect/detect-provider" + client = Nylas::HttpClient.new(app_id: "not-real", app_secret: "also-not-real") + data = { + "client_id" => "not-real", + "client_secret" => "also-not-real", + "email_address" => "test@gmail.com" + } + response = { + auth_name: "gmail", + detected: true, + email_address: "test@gmail.com", + is_imap: false, + provider_name: "gmail" + } + + stub_request(:post, url) + .to_return( + status: 200, + body: response.to_json, + headers: { "content-type" => "application/json" } + ) + api = described_class.new(client: client) + res = api.detect_provider("test@gmail.com") + + expect(res).to eq(response) + expect(WebMock).to have_requested(:post, url) + .with(body: data) + end + end + describe "#exchange_code_for_token" do it "retrieves oauth token with code" do client = Nylas::HttpClient.new(app_id: "fake-app", app_secret: "fake-secret")