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

Checkpoint pagination [SDK-2667] #284

Merged
merged 10 commits into from
Jul 23, 2021
4 changes: 2 additions & 2 deletions lib/auth0/api/v2/logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ module Logs
# * :fields [string] A comma separated list of fields to include or exclude from the result.
# * :include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.
# * :include_totals [string] True if a query summary must be included in the result, false otherwise.
# * :from [string] Log Event Id to start retrieving logs. You can limit the amount of logs using the take parameter.
# * :take [integer] The total amount of entries to retrieve when using the from parameter.
# * :from [string] For checkpoint pagination, the Id from which to start selection from.
davidpatrick marked this conversation as resolved.
Show resolved Hide resolved
# * :take [integer] or checkpoint pagination, the number of entries to retrieve. Default 50.
davidpatrick marked this conversation as resolved.
Show resolved Hide resolved
# Default: 50. Max value: 100.
#
# @return [json] Returns the list of existing log entries.
Expand Down
22 changes: 19 additions & 3 deletions lib/auth0/api/v2/organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ module Organizations
# @param options [hash] The Hash options used to define the paging of rersults
# * :per_page [integer] The amount of entries per page. Default: 50. Max value: 100.
# * :page [integer] The page number. Zero based.
# * :from [string] For checkpoint pagination, the Id from which to start selection from.
davidpatrick marked this conversation as resolved.
Show resolved Hide resolved
# * :take [integer] or checkpoint pagination, the number of entries to retrieve. Default 50.
davidpatrick marked this conversation as resolved.
Show resolved Hide resolved
# * :include_totals [boolean] True to include query summary in the result, false or nil otherwise.
# @return [json] All Organizations
def organizations(options = {})
request_params = {
per_page: options.fetch(:per_page, nil),
page: options.fetch(:page, nil),
from: options.fetch(:from, nil),
take: options.fetch(:take, nil),
include_totals: options.fetch(:include_totals, nil)
}
get(organizations_path, request_params)
Expand Down Expand Up @@ -212,13 +216,25 @@ def delete_organizations_invite(organization_id, invitation_id)
# Get Members in a Organization
# @see https://auth0.com/docs/api/management/v2/#!/Organizations/get_members
# @param organization_id [string] The Organization ID
# @param user_id [string] The User ID
# @param options [hash] The Hash options used to define the paging of rersults
# * :per_page [integer] The amount of entries per page. Default: 50. Max value: 100.
# * :page [integer] The page number. Zero based.
# * :from [string] For checkpoint pagination, the Id from which to start selection from.
davidpatrick marked this conversation as resolved.
Show resolved Hide resolved
# * :take [integer] or checkpoint pagination, the number of entries to retrieve. Default 50.
davidpatrick marked this conversation as resolved.
Show resolved Hide resolved
# * :include_totals [boolean] True to include query summary in the result, false or nil otherwise.
#
# @return [json] Returns the members for the given organization
def get_organizations_members(organization_id)
def get_organizations_members(organization_id, options = {})
raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
request_params = {
per_page: options.fetch(:per_page, nil),
page: options.fetch(:page, nil),
from: options.fetch(:from, nil),
take: options.fetch(:take, nil),
include_totals: options.fetch(:include_totals, nil)
}
path = "#{organizations_members_path(organization_id)}"
get(path)
get(path, request_params)
end

# Add members in an organization
Expand Down
10 changes: 7 additions & 3 deletions lib/auth0/api/v2/roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,17 @@ def delete_role(role_id)
# @param options [hash] A hash of options for getting Roles
# - per_page: Number of Roles to return.
# - page: Page number to return, zero-based.
# - include_totals: True to include query summary in the result, false or nil otherwise.
# * :from [string] For checkpoint pagination, the Id from which to start selection from.
davidpatrick marked this conversation as resolved.
Show resolved Hide resolved
# * :take [integer] or checkpoint pagination, the number of entries to retrieve. Default 50.
davidpatrick marked this conversation as resolved.
Show resolved Hide resolved
# * :include_totals [boolean] True to include query summary in the result, false or nil otherwise.
def get_role_users(role_id, options = {})
raise Auth0::MissingParameter, 'Must supply a valid role_id' if role_id.to_s.empty?

request_params = {
per_page: options.fetch(:per_page, nil),
page: options.fetch(:page, nil),
per_page: options.fetch(:per_page, nil),
page: options.fetch(:page, nil),
from: options.fetch(:from, nil),
take: options.fetch(:take, nil),
include_totals: options.fetch(:include_totals, nil)
}
get "#{roles_path}/#{role_id}/users", request_params
Expand Down
37 changes: 31 additions & 6 deletions spec/lib/auth0/api/v2/organizations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
'/api/v2/organizations',
per_page: nil,
page: nil,
from: nil,
take: nil,
include_totals: nil
)
expect { @instance.organizations }.not_to raise_error
Expand All @@ -30,12 +32,16 @@
'/api/v2/organizations',
per_page: 10,
page: 1,
from: 'org_id',
take: 50,
include_totals: true
)
expect do
@instance.organizations(
per_page: 10,
page: 1,
from: 'org_id',
take: 50,
include_totals: true
)
end.not_to raise_error
Expand Down Expand Up @@ -438,19 +444,38 @@
expect { @instance.get_organizations_members(nil) }.to raise_exception(Auth0::MissingOrganizationId)
end

it 'is expected to get invitations for an org' do
it 'is expected to get members for an org' do
expect(@instance).to receive(:get).with(
'/api/v2/organizations/org_id/members'
'/api/v2/organizations/org_id/members',
per_page: nil,
page: nil,
from: nil,
take: nil,
include_totals: nil
)
expect { @instance.get_organizations_members('org_id') }.not_to raise_error
expect do
@instance.get_organizations_members('org_id')
end.not_to raise_error
end

it 'is expected to get members for an org' do
it 'is expected to get /api/v2/organizations with custom parameters' do
expect(@instance).to receive(:get).with(
'/api/v2/organizations/org_id/members'
'/api/v2/organizations/org_id/members',
per_page: 10,
page: 1,
from: 'org_id',
take: 50,
include_totals: true
)
expect do
@instance.get_organizations_members('org_id')
@instance.get_organizations_members(
'org_id',
per_page: 10,
page: 1,
from: 'org_id',
take: 50,
include_totals: true
)
end.not_to raise_error
end
end
Expand Down
6 changes: 5 additions & 1 deletion spec/lib/auth0/api/v2/roles_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@
'/api/v2/roles/ROLE_ID/users',
per_page: nil,
page: nil,
from: nil,
take: nil,
include_totals: nil
)
expect { @instance.get_role_users('ROLE_ID') }.not_to raise_error
Expand All @@ -162,10 +164,12 @@
'/api/v2/roles/ROLE_ID/users',
per_page: 30,
page: 4,
from: 'org_id',
take: 50,
include_totals: true
)
expect do
@instance.get_role_users('ROLE_ID', per_page: 30, page: 4, include_totals: true)
@instance.get_role_users('ROLE_ID', per_page: 30, page: 4, from: 'org_id', take: 50, include_totals: true)
end.not_to raise_error
end
end
Expand Down