From bdf4d6cd86b75f2832da182051b757116b9b0bd9 Mon Sep 17 00:00:00 2001 From: Carmen Alvarez Date: Thu, 26 Sep 2024 12:59:57 +0200 Subject: [PATCH] Use the `GET /v3/recipes/` route to retrieve recipes. See the documentation: https://developer.genymotion.com/saas/#tag/Recipes-v3/operation/listRecipesV3 --- example/geny-window.js | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/example/geny-window.js b/example/geny-window.js index 451ac6b..d46b4de 100644 --- a/example/geny-window.js +++ b/example/geny-window.js @@ -146,14 +146,14 @@ const stopInstance = async () => { // Fetch recipe and add them to the select const fetchRecipes = async () => { try { - const response = await fetch(baseUrlToFetch + `/v1/recipes?limit=1000`, { + const response = await fetch(baseUrlToFetch + `/v3/recipes/?arch=x86_64&arch=x86&arch=arm64&limit=1000`, { ...requestInit, method: 'GET', }); - const recipes = await response.json(); + const recipesResult = await response.json(); if (response.status !== 200) { - alert(recipes.message); + alert(recipesResult.message); return; } @@ -166,30 +166,20 @@ const fetchRecipes = async () => { placeholderOption.disabled = true; placeholderOption.selected = true; selectElement.add(placeholderOption, selectElement.firstChild); - - for (const recipeType in recipes) { - addOptionsToGroup(recipeType, recipes[recipeType]); + const recipes = recipesResult.results; + + for (let i = 0; i < recipes.length; i++) { + const recipe = recipes[i]; + const optionElement = document.createElement('option'); + optionElement.value = recipe.uuid; + optionElement.textContent = recipe.name; + selectElement.appendChild(optionElement); } } catch (error) { alert(error); } }; -const addOptionsToGroup = (recipeType, recipes) => { - const selectElement = document.querySelector('#listRecipes'); - - const optgroup = document.createElement('optgroup'); - optgroup.label = recipeType; - - recipes.forEach((recipe) => { - const optionElement = document.createElement('option'); - optionElement.value = recipe.uuid; - optionElement.textContent = recipe.name; - optgroup.appendChild(optionElement); - }); - - selectElement.appendChild(optgroup); -}; // connect to an existing instance through an instance Uuid or an instance ws address const connectInstance = async (wsAddress) => {