IanTDuncan / MealTime

Project for CSC 480
0 stars 0 forks source link

API - Spoonacular - SDK Import #133

Closed IanTDuncan closed 6 months ago

IanTDuncan commented 7 months ago

API - Spoontacular - SDK Import


Description:

This will be a guide on how to install the Java SDK from Spoontacular into Android Studio as a library.

Originally this issue was for the Android SDK client, but it turned out that the client was out of date and thus not usable

Links:

Requirements:


Steps To Reproduce:

  1. Download the Java SDK from one of the two links above
  2. Extract the SDK into a folder
  3. Copy the folder's path
  4. Open up command line and type cd your-file-path-here
  5. Next type mvn clean package this will generate .jar files within the folder
  6. Under \java-client\target you should find a .jar file named java-client-1.1.1
  7. Copy the above file
  8. In your Android Studio file create a directory named libs under the app
  9. In the libs directory paste the java-client-1.1.1
  10. Right-click on java-client-1.1.1 and select the add to the project as a library option
  11. Copy and paste the code below to verify it worked

Expected Vs. Actual Behavior:

Expected Behavior: Perfect synchronization within the project Actual Behavior: Perfect synchronization within the project


Code Snippets:

import com.spoonacular.DefaultApi;
import com.spoonacular.MealPlanningApi;
import com.spoonacular.client.ApiException;
import com.spoonacular.client.model.AnalyzeRecipeRequest;

public class DefaultApiExample {

    public static void main(String[] args) {
        DefaultApi apiInstance = new DefaultApi();
        AnalyzeRecipeRequest analyzeRecipeRequest = new AnalyzeRecipeRequest(); // AnalyzeRecipeRequest | Example request body.
        String language = "en"; // String | The input language, either \"en\" or \"de\".
        Boolean includeNutrition = false; // Boolean | Whether nutrition data should be added to correctly parsed ingredients.
        Boolean includeTaste = false; // Boolean | Whether taste data should be added to correctly parsed ingredients.
        try {
            Object result = apiInstance.analyzeRecipe(analyzeRecipeRequest, language, includeNutrition, includeTaste);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling DefaultApi#analyzeRecipe");
            e.printStackTrace();
        }
    }
}

Environment Details:

Operating System: Windows 11 Kotlin Version: 1.5.21 Android Studio Iguana 2023.2.1 Android Gradle Plugin Version: 8.3.0 Gradle Version: 8.4


Current Status:

COMPLETED