|
| 1 | +package com.auth0.client.mgmt; |
| 2 | + |
| 3 | +import com.auth0.json.mgmt.prompts.Prompt; |
| 4 | +import com.auth0.net.BaseRequest; |
| 5 | +import com.auth0.net.Request; |
| 6 | +import com.auth0.net.client.Auth0HttpClient; |
| 7 | +import com.auth0.net.client.HttpMethod; |
| 8 | +import com.auth0.utils.Asserts; |
| 9 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 10 | +import okhttp3.HttpUrl; |
| 11 | + |
| 12 | +public class PromptsEntity extends BaseManagementEntity { |
| 13 | + |
| 14 | + private final static String ORGS_PATH = "api/v2/prompts"; |
| 15 | + |
| 16 | + PromptsEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { |
| 17 | + super(client, baseUrl, tokenProvider); |
| 18 | + } |
| 19 | + |
| 20 | + /** |
| 21 | + * Get the prompt. |
| 22 | + * A token with {@code read:prompts} scope is required. |
| 23 | + * @return a Request to execute. |
| 24 | + * |
| 25 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/get-prompts">https://auth0.com/docs/api/management/v2#!/prompts/get-prompts</a> |
| 26 | + */ |
| 27 | + public Request<Prompt> getPrompt() { |
| 28 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 29 | + .addPathSegments(ORGS_PATH); |
| 30 | + String url = builder.build().toString(); |
| 31 | + |
| 32 | + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Prompt>() { |
| 33 | + }); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * Update the prompt. |
| 38 | + * A token with {@code update:prompts} scope is required. |
| 39 | + * @param prompt the prompt to update. |
| 40 | + * @return a Request to execute. |
| 41 | + * |
| 42 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/patch-prompts">https://auth0.com/docs/api/management/v2#!/prompts/patch-prompts</a> |
| 43 | + */ |
| 44 | + public Request<Prompt> updatePrompt(Prompt prompt) { |
| 45 | + Asserts.assertNotNull(prompt, "prompt"); |
| 46 | + |
| 47 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 48 | + .addPathSegments(ORGS_PATH); |
| 49 | + String url = builder.build().toString(); |
| 50 | + |
| 51 | + BaseRequest<Prompt> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<Prompt>() { |
| 52 | + }); |
| 53 | + |
| 54 | + request.setBody(prompt); |
| 55 | + return request; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * Get the custom text for specific prompt and language. |
| 60 | + * A token with {@code read:prompts} scope is required. |
| 61 | + * @param prompt the prompt name. |
| 62 | + * @param language the language. |
| 63 | + * @return a Request to execute. |
| 64 | + * |
| 65 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/get-custom-text-by-language">https://auth0.com/docs/api/management/v2#!/prompts/get-custom-text-by-language</a> |
| 66 | + */ |
| 67 | + public Request<Object> getCustomText(String prompt, String language) { |
| 68 | + Asserts.assertNotNull(prompt, "prompt"); |
| 69 | + Asserts.assertNotNull(language, "language"); |
| 70 | + |
| 71 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 72 | + .addPathSegments(ORGS_PATH) |
| 73 | + .addPathSegment(prompt) |
| 74 | + .addPathSegment("custom-text") |
| 75 | + .addPathSegments(language); |
| 76 | + |
| 77 | + String url = builder.build().toString(); |
| 78 | + |
| 79 | + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Object>() { |
| 80 | + }); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * Set the custom text for specific prompt and language. |
| 85 | + * A token with {@code update:prompts} scope is required. |
| 86 | + * @param prompt the prompt name. |
| 87 | + * @param language the language. |
| 88 | + * @param customText the custom text. |
| 89 | + * @return a Request to execute. |
| 90 | + * |
| 91 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/put-custom-text-by-language">https://auth0.com/docs/api/management/v2#!/prompts/put-custom-text-by-language</a> |
| 92 | + */ |
| 93 | + public Request<Void> setCustomText(String prompt, String language, Object customText) { |
| 94 | + Asserts.assertNotNull(prompt, "prompt"); |
| 95 | + Asserts.assertNotNull(language, "language"); |
| 96 | + Asserts.assertNotNull(customText, "customText"); |
| 97 | + |
| 98 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 99 | + .addPathSegments(ORGS_PATH) |
| 100 | + .addPathSegment(prompt) |
| 101 | + .addPathSegment("custom-text") |
| 102 | + .addPathSegments(language); |
| 103 | + |
| 104 | + String url = builder.build().toString(); |
| 105 | + |
| 106 | + BaseRequest<Void> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PUT, new TypeReference<Void>() { |
| 107 | + }); |
| 108 | + |
| 109 | + request.setBody(customText); |
| 110 | + return request; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Get the partials for specific prompt. |
| 115 | + * A token with {@code read:prompts} scope is required. |
| 116 | + * @param prompt the prompt name. |
| 117 | + * @return a Request to execute. |
| 118 | + * |
| 119 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/get-partialse">https://auth0.com/docs/api/management/v2#!/prompts/get-partials</a> |
| 120 | + */ |
| 121 | + public Request<Object> getPartialsPrompt(String prompt) { |
| 122 | + Asserts.assertNotNull(prompt, "prompt"); |
| 123 | + |
| 124 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 125 | + .addPathSegments(ORGS_PATH) |
| 126 | + .addPathSegment(prompt) |
| 127 | + .addPathSegment("partials"); |
| 128 | + |
| 129 | + String url = builder.build().toString(); |
| 130 | + |
| 131 | + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<Object>() { |
| 132 | + }); |
| 133 | + } |
| 134 | + |
| 135 | + /** |
| 136 | + * Set the partials for specific prompt. |
| 137 | + * A token with {@code read:prompts} scope is required. |
| 138 | + * @param prompt the prompt name. |
| 139 | + * @param partials the partials. |
| 140 | + * @return a Request to execute. |
| 141 | + * |
| 142 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/prompts/put-partials">https://auth0.com/docs/api/management/v2#!/prompts/put-partials</a> |
| 143 | + */ |
| 144 | + public Request<Void> setPartialsPrompt(String prompt, Object partials) { |
| 145 | + Asserts.assertNotNull(prompt, "prompt"); |
| 146 | + Asserts.assertNotNull(partials, "partials"); |
| 147 | + |
| 148 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 149 | + .addPathSegments(ORGS_PATH) |
| 150 | + .addPathSegment(prompt) |
| 151 | + .addPathSegment("partials"); |
| 152 | + |
| 153 | + String url = builder.build().toString(); |
| 154 | + |
| 155 | + BaseRequest<Void> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PUT, new TypeReference<Void>() { |
| 156 | + }); |
| 157 | + |
| 158 | + request.setBody(partials); |
| 159 | + return request; |
| 160 | + } |
| 161 | + |
| 162 | +} |
0 commit comments