Skip to content

Commit 72d4bbc

Browse files
authored
Merge pull request #105 from edgurgel/add-users-by-email
Add support to /api/v2/users-by-email
2 parents 029c389 + b2bbd78 commit 72d4bbc

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

lib/auth0/api/v2.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require 'auth0/api/v2/rules'
99
require 'auth0/api/v2/stats'
1010
require 'auth0/api/v2/users'
11+
require 'auth0/api/v2/users_by_email'
1112
require 'auth0/api/v2/user_blocks'
1213
require 'auth0/api/v2/tenants'
1314
require 'auth0/api/v2/tickets'
@@ -28,6 +29,7 @@ module V2
2829
include Auth0::Api::V2::Rules
2930
include Auth0::Api::V2::Stats
3031
include Auth0::Api::V2::Users
32+
include Auth0::Api::V2::UsersByEmail
3133
include Auth0::Api::V2::UserBlocks
3234
include Auth0::Api::V2::Tenants
3335
include Auth0::Api::V2::Tickets

lib/auth0/api/v2/users_by_email.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Auth0
2+
module Api
3+
module V2
4+
# Methods to use the Users By Email endpoints
5+
module UsersByEmail
6+
attr_reader :users_by_email_path
7+
8+
# Retrieves a list of existing users by their email.
9+
# @see https://auth0.com/docs/api/v2#!/Users/get_users
10+
# @see https://auth0.com/docs/api/management/v2#!/Users_By_Email/get_users_by_email
11+
# @param fields [string] A comma separated list of fields to include or exclude from the result.
12+
# @param include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
13+
# @param email [string] E-mail to be searched
14+
#
15+
# @return [json] Returns the list of existing users.
16+
def users_by_email(email, options = {})
17+
raise Auth0::InvalidParameter, 'Must supply a valid email' if email.to_s.empty?
18+
request_params = {
19+
fields: options.fetch(:fields, nil),
20+
include_fields: options.fetch(:include_fields, nil)
21+
}
22+
request_params[:email] = email
23+
get(users_by_email_path, request_params)
24+
end
25+
26+
private
27+
28+
# Users By Emails API path
29+
def users_by_email_path
30+
@users_by_email_path ||= '/api/v2/users-by-email'
31+
end
32+
end
33+
end
34+
end
35+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'spec_helper'
2+
describe Auth0::Api::V2::UsersByEmail do
3+
before :all do
4+
dummy_instance = DummyClass.new
5+
dummy_instance.extend(Auth0::Api::V2::UsersByEmail)
6+
@instance = dummy_instance
7+
end
8+
9+
context '.users_by_email' do
10+
it { expect(@instance).to respond_to(:users_by_email) }
11+
it 'is expected to call /api/v2/users-by-email' do
12+
expect(@instance).to receive(:get).with(
13+
'/api/v2/users-by-email',
14+
fields: nil,
15+
include_fields: nil,
16+
email: 'email'
17+
)
18+
expect { @instance.users_by_email('email') }.not_to raise_error
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)