Closed BeepDroid closed 3 months ago
Calls the method DeleteFromShopplistList from Spoonacular to allow a user to delete an item from their shoppling list.
import com.spoonacular.MealPlanningApi; import com.spoonacular.client.model.DeleteFromMealPlanRequest; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; public class DeleteFromShoppingList { public static void main(String[] args) { // Define your API base URL String baseUrl = "https://api.spoonacular.com/"; // Create Retrofit instance Retrofit retrofit = new Retrofit.Builder() .baseUrl(baseUrl) .addConverterFactory(GsonConverterFactory.create()) .build(); // Create your Retrofit service interface MealPlanningService service = retrofit.create(MealPlanningService.class); // Set your API key String apiKey = "faadc412663942a8909197924745241d"; // Prepare request data String username = "dsky"; // The username Integer id = 1; // The item's id String hash = "hash_example"; // The private hash for the username DeleteFromMealPlanRequest deleteFromMealPlanRequest = new DeleteFromMealPlanRequest(); // Make API call using Retrofit Call<Object> call = service.deleteFromShoppingList(username, id, hash, deleteFromMealPlanRequest, apiKey); call.enqueue(new Callback<Object>() { @Override public void onResponse(Call<Object> call, Response<Object> response) { if (response.isSuccessful()) { Object result = response.body(); System.out.println(result); } else { System.err.println("Failed to delete from shopping list: " + response.errorBody().toString()); } } @Override public void onFailure(Call<Object> call, Throwable t) { System.err.println("Exception occurred while calling MealPlanningApi#deleteFromShoppingList: " + t.getMessage()); } }); } }``` ### Environment Details: ____________________________ Android Studio, Retrofit2, Spoonacular API, Windows OS. ### Current Status: ________________________ Closed
Spoonacular API - DeleteFromShoppingList Class
Description:
Calls the method DeleteFromShopplistList from Spoonacular to allow a user to delete an item from their shoppling list.
Steps to Reproduce:
Expected vs. Actual Behavior:
Code Snippets: