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

Add support for detect provider endpoint #439

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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
18 changes: 18 additions & 0 deletions lib/nylas/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ 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
}

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)
Expand Down
33 changes: 33 additions & 0 deletions spec/nylas/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" => "[email protected]"
}
response = {
auth_name: "gmail",
detected: true,
email_address: "[email protected]",
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("[email protected]")

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")
Expand Down
Loading