From 587a0452dd61507f7540b51303e02b6f56a00737 Mon Sep 17 00:00:00 2001 From: David Patrick Date: Fri, 9 Apr 2021 09:47:49 -0700 Subject: [PATCH] Branding (#266) --- lib/auth0/api/v2.rb | 14 +++--- lib/auth0/api/v2/branding.rb | 66 ++++++++++++++++++++++++ spec/lib/auth0/api/v2/branding_spec.rb | 70 ++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 6 deletions(-) create mode 100644 lib/auth0/api/v2/branding.rb create mode 100644 spec/lib/auth0/api/v2/branding_spec.rb diff --git a/lib/auth0/api/v2.rb b/lib/auth0/api/v2.rb index 6f478fdf..39dd4168 100644 --- a/lib/auth0/api/v2.rb +++ b/lib/auth0/api/v2.rb @@ -1,5 +1,6 @@ require 'auth0/api/v2/anomaly' require 'auth0/api/v2/blacklists' +require 'auth0/api/v2/branding' require 'auth0/api/v2/clients' require 'auth0/api/v2/client_grants' require 'auth0/api/v2/connections' @@ -7,6 +8,7 @@ require 'auth0/api/v2/emails' require 'auth0/api/v2/jobs' require 'auth0/api/v2/prompts' +require 'auth0/api/v2/organizations' require 'auth0/api/v2/rules' require 'auth0/api/v2/roles' require 'auth0/api/v2/stats' @@ -19,7 +21,6 @@ require 'auth0/api/v2/log_streams' require 'auth0/api/v2/resource_servers' require 'auth0/api/v2/guardian' -require 'auth0/api/v2/organizations' module Auth0 module Api @@ -27,26 +28,27 @@ module Api module V2 include Auth0::Api::V2::Anomaly include Auth0::Api::V2::Blacklists + include Auth0::Api::V2::Branding include Auth0::Api::V2::Clients include Auth0::Api::V2::ClientGrants include Auth0::Api::V2::Connections include Auth0::Api::V2::DeviceCredentials include Auth0::Api::V2::Emails + include Auth0::Api::V2::Guardian include Auth0::Api::V2::Jobs + include Auth0::Api::V2::Logs + include Auth0::Api::V2::LogStreams include Auth0::Api::V2::Prompts + include Auth0::Api::V2::Organizations include Auth0::Api::V2::Rules include Auth0::Api::V2::Roles include Auth0::Api::V2::Stats include Auth0::Api::V2::Users include Auth0::Api::V2::UsersByEmail include Auth0::Api::V2::UserBlocks + include Auth0::Api::V2::ResourceServers include Auth0::Api::V2::Tenants include Auth0::Api::V2::Tickets - include Auth0::Api::V2::Logs - include Auth0::Api::V2::LogStreams - include Auth0::Api::V2::ResourceServers - include Auth0::Api::V2::Guardian - include Auth0::Api::V2::Organizations end end end diff --git a/lib/auth0/api/v2/branding.rb b/lib/auth0/api/v2/branding.rb new file mode 100644 index 00000000..291172a9 --- /dev/null +++ b/lib/auth0/api/v2/branding.rb @@ -0,0 +1,66 @@ +module Auth0 + module Api + module V2 + # Methods to use the branding endpoints + module Branding + attr_reader :branding_path + + # Retrieve branding settings. + # @see https://auth0.com/docs/api/management/v2/#!/Branding/get_branding + # + # @return [json] Returns branding settings. + def branding() + get(branding_path) + end + alias get_branding branding + + # Update branding settings. + # @see https://auth0.com/docs/api/management/v2/#!/Branding/patch_branding + # @param body [hash] the branding settings to update + # + # @return [json] Returns branding settings. + def patch_branding(body = {}) + patch(branding_path, body) + end + alias update_branding patch_branding + + # Get template for New Universal Login Experience + # @see https://auth0.com/docs/api/management/v2/#!/Branding/get_universal_login + # + # @return [json] Returns branding settings. + def branding_templates_for_universal_login + get(templates_path) + end + alias get_branding_templates_for_universal_login branding_templates_for_universal_login + + # Delete template for New Universal Login Experience + # @see https://auth0.com/docs/api/management/v2/#!/Branding/delete_universal_login + # @param rule_id [string] The id of the rule to delete. + def delete_branding_templates_for_universal_login + delete(templates_path) + end + + # Set template for New Universal Login Experience + # @see https://auth0.com/docs/api/management/v2/#!/Branding/put_universal_login + # @param body [hash] the branding settings to update + # + # @return [json] Returns branding settings. + def put_branding_templates_for_universal_login(body = {}) + put(templates_path, body) + end + alias set_branding_templates_for_universal_login put_branding_templates_for_universal_login + + private + + # Branding API path + def branding_path + @branding_path ||= '/api/v2/branding' + end + + def templates_path + @templates_path ||= "#{branding_path}/templates/universal-login" + end + end + end + end +end diff --git a/spec/lib/auth0/api/v2/branding_spec.rb b/spec/lib/auth0/api/v2/branding_spec.rb new file mode 100644 index 00000000..e6baf93d --- /dev/null +++ b/spec/lib/auth0/api/v2/branding_spec.rb @@ -0,0 +1,70 @@ +require 'spec_helper' +describe Auth0::Api::V2::Branding do + before :all do + dummy_instance = DummyClass.new + dummy_instance.extend(Auth0::Api::V2::Branding) + dummy_instance.extend(Auth0::Mixins::Initializer) + @instance = dummy_instance + end + + context '.branding' do + it { expect(@instance).to respond_to(:branding) } + + it 'is expected to call get /api/v2/branding' do + expect(@instance).to receive(:get).with('/api/v2/branding') + expect { @instance.branding }.not_to raise_error + end + + it 'is expected to respond to a get_branding method' do + expect(@instance).to respond_to(:get_branding) + end + end + + context '.patch_branding' do + it { expect(@instance).to respond_to(:patch_branding) } + it 'is expected to call post /api/v2/branding' do + expect(@instance).to receive(:patch).with( + '/api/v2/branding', + template: 'Test' + ) + expect { @instance.patch_branding({ template: 'Test' }) }.not_to raise_error + end + + it 'is expected to respond to a get_branding method' do + expect(@instance).to respond_to(:update_branding) + end + end + + context '.branding_templates_for_universal_login' do + it { expect(@instance).to respond_to(:branding) } + + it 'is expected to call get /api/v2/branding/templates/universal-login' do + expect(@instance).to receive(:get).with('/api/v2/branding/templates/universal-login') + expect { @instance.branding_templates_for_universal_login }.not_to raise_error + end + + it 'is expected to respond to a get_branding_templates_for_universal_login method' do + expect(@instance).to respond_to(:get_branding_templates_for_universal_login) + end + end + + context '.put_branding_templates_for_universal_login' do + it { expect(@instance).to respond_to(:put_branding_templates_for_universal_login) } + it 'is expected to call put /api/v2/branding/templates/universal-login' do + expect(@instance).to receive(:put).with( + '/api/v2/branding/templates/universal-login', template: 'Template' + ) + expect do + @instance.put_branding_templates_for_universal_login(template: 'Template') + end.not_to raise_error + end + end + + context '.delete_branding_templates_for_universal_login' do + it { expect(@instance).to respond_to(:delete_branding_templates_for_universal_login) } + it 'is expected to call delete /api/v2/branding/templates/universal-login' do + expect(@instance).to receive(:delete).with('/api/v2/branding/templates/universal-login') + expect { @instance.delete_branding_templates_for_universal_login() }.not_to raise_error + end + end +end