From bdd6c332eae937a0c8c4ac4a2809816447567a2f Mon Sep 17 00:00:00 2001 From: Phoenix He Date: Thu, 24 Oct 2019 13:28:45 +0800 Subject: [PATCH 1/4] Update swagger_to_sdk_config.json --- swagger_to_sdk_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swagger_to_sdk_config.json b/swagger_to_sdk_config.json index a4f763911359..399fe6789da5 100644 --- a/swagger_to_sdk_config.json +++ b/swagger_to_sdk_config.json @@ -5,7 +5,7 @@ "typescript": "", "license-header": "MICROSOFT_MIT_NO_VERSION", "sdkrel:typescript-sdks-folder": ".", - "use": "@microsoft.azure/autorest.typescript@4.1.1" + "use": "@microsoft.azure/autorest.typescript@4.2.2" }, "advanced_options": { "clone_dir": "./azure-sdk-for-js", From be583e41b9d1d90a0302d8468afacd475bada73c Mon Sep 17 00:00:00 2001 From: Phoenix He Date: Thu, 24 Oct 2019 14:40:18 +0800 Subject: [PATCH 2/4] Update swagger_to_sdk_config.json --- swagger_to_sdk_config.json | 1 + 1 file changed, 1 insertion(+) diff --git a/swagger_to_sdk_config.json b/swagger_to_sdk_config.json index 399fe6789da5..b8a4c993ce88 100644 --- a/swagger_to_sdk_config.json +++ b/swagger_to_sdk_config.json @@ -5,6 +5,7 @@ "typescript": "", "license-header": "MICROSOFT_MIT_NO_VERSION", "sdkrel:typescript-sdks-folder": ".", + "go.clear-output-folder": "", "use": "@microsoft.azure/autorest.typescript@4.2.2" }, "advanced_options": { From c9511411cee2cb98d6bd53a8deae2c47a3e7c284 Mon Sep 17 00:00:00 2001 From: Phoenix He Date: Thu, 24 Oct 2019 14:49:49 +0800 Subject: [PATCH 3/4] Update swagger_to_sdk_config.json --- swagger_to_sdk_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swagger_to_sdk_config.json b/swagger_to_sdk_config.json index b8a4c993ce88..0387101043cb 100644 --- a/swagger_to_sdk_config.json +++ b/swagger_to_sdk_config.json @@ -5,7 +5,7 @@ "typescript": "", "license-header": "MICROSOFT_MIT_NO_VERSION", "sdkrel:typescript-sdks-folder": ".", - "go.clear-output-folder": "", + "typescript.clear-output-folder": "", "use": "@microsoft.azure/autorest.typescript@4.2.2" }, "advanced_options": { From 3ce1715881b47a2dcabcb866f7b5c23ba7d0a4ac Mon Sep 17 00:00:00 2001 From: SDK Automation Date: Fri, 25 Oct 2019 09:46:21 +0000 Subject: [PATCH 4/4] Generated from a71df15a587ec060147aaef2dcfc12d19500fdc8 Fix json format by prettier --- .../cognitiveservices-personalizer/README.md | 172 +++++------------- 1 file changed, 47 insertions(+), 125 deletions(-) diff --git a/sdk/cognitiveservices/cognitiveservices-personalizer/README.md b/sdk/cognitiveservices/cognitiveservices-personalizer/README.md index 481ecb1aaff0..a4750c3ab1de 100644 --- a/sdk/cognitiveservices/cognitiveservices-personalizer/README.md +++ b/sdk/cognitiveservices/cognitiveservices-personalizer/README.md @@ -17,91 +17,48 @@ npm install @azure/cognitiveservices-personalizer #### nodejs - Authentication, client creation and reward events as an example written in TypeScript. -##### Install @azure/ms-rest-azure-js +##### Install @azure/ms-rest-nodeauth +- Please install minimum version of `"@azure/ms-rest-nodeauth": "^3.0.0"`. ```bash -npm install @azure/ms-rest-azure-js +npm install @azure/ms-rest-nodeauth@"^3.0.0" ``` ##### Sample code -The following sample ranks a personalized request object. To know more, refer to the [Azure Documentation on Personalizer](https://docs.microsoft.com/en-us/azure/cognitive-services/personalizer/) ```typescript -import { - PersonalizerClient, - PersonalizerModels -} from "@azure/cognitiveservices-personalizer"; -import { CognitiveServicesCredentials } from "@azure/ms-rest-azure-js"; - -async function main(): Promise { - const personalizerKey = process.env["personalizerKey"] || ""; - const personalizerEndPoint = - process.env["personalizerEndPoint"] || ""; - const cognitiveServiceCredentials = new CognitiveServicesCredentials( - personalizerKey - ); - - const client = new PersonalizerClient( - cognitiveServiceCredentials, - personalizerEndPoint - ); - - const rankRequest: PersonalizerModels.RankRequest = { - contextFeatures: [ - { - timeOfDay: "Morning" - } - ], - actions: [ - { - id: "NewsArticle", - features: [ - { - type: "News" - } - ] - }, - { - id: "SportsArticle", - features: [ - { - type: "Sports" - } - ] - }, - { - id: "EntertainmentArticle", - features: [ - { - type: "Entertainment" - } - ] - } - ], - excludedActions: ["SportsArticle"], - eventId: "75269AD0-BFEE-4598-8196-C57383D38E10", - deferActivation: false +import * as msRest from "@azure/ms-rest-js"; +import * as msRestNodeAuth from "@azure/ms-rest-nodeauth"; +import { PersonalizerClient, PersonalizerModels, PersonalizerMappers } from "@azure/cognitiveservices-personalizer"; +const subscriptionId = process.env["AZURE_SUBSCRIPTION_ID"]; + +msRestNodeAuth.interactiveLogin().then((creds) => { + const client = new PersonalizerClient(creds, subscriptionId); + const eventId = "testeventId"; + const rewardParameter: PersonalizerModels.RewardRequest = { + value: 1.01 }; - - client - .rank(rankRequest) - .then(result => { - console.log("The result is: "); - console.log(result); - }) - .catch(err => { - console.log("An error occurred:"); - console.error(err); - }); -} - -main(); + client.events.reward(eventId, rewardParameter).then((result) => { + console.log("The result is:"); + console.log(result); + }); +}).catch((err) => { + console.error(err); +}); ``` #### browser - Authentication, client creation and reward events as an example written in JavaScript. +##### Install @azure/ms-rest-browserauth + +```bash +npm install @azure/ms-rest-browserauth +``` + ##### Sample code +See https://github.com/Azure/ms-rest-browserauth to learn how to authenticate to Azure in the browser. + - index.html ```html @@ -109,67 +66,32 @@ main(); @azure/cognitiveservices-personalizer sample +