Code Examples


Download all code examples:

Get All Beef Cuts Example


 using BIWFD.BeefAPISDK;
using System;
using System.Linq;

namespace GetAllBeefCuts
{
    class Program
    {
        public static void Main()
        {
            // Request authorization: https://developer.beefapi.beef.org/signup

            string authorizationAppID = "YourAuthorizationAppID";
            string AuthorizationAppKey = "YourAuthorizationAppKey";

            BeefAPI client;
            client = new BeefAPI(authorizationAppID, AuthorizationAppKey);

            Console.WriteLine("Beef Cut List");
            DisplayBeefCuts(client);
        }

        /// 
        /// Uses the client object to get a list of the Beef Cuts
        /// 
        /// The initialized Beef API client object
        public static void DisplayBeefCuts(BeefAPI client)
        {
            try
            {
                // Get all beef cuts
                var response = client.GetAllBeefCuts();
                var sortedList = response.IngredientList.OrderBy(recipe => recipe.IngredientID);

                sortedList.ToList().ForEach(ingredient =>
                {
                    Console.WriteLine($"{ingredient.IngredientID}\t{ingredient.IngredientName}");
                    if(ingredient.IngredientType != null)
                    {
                        Console.WriteLine($"Ingredient Type Name: {ingredient.IngredientType.IngredientTypeName}");
                    }
                    Console.WriteLine($"Is Beef Fabricated Cut: {ingredient.IsBeefFabricatedCut}");
                    Console.WriteLine($"Is Beef Ingredient: {ingredient.IsBeefIngredient}");
                    Console.WriteLine($"Is Beef Primal: {ingredient.IsBeefPrimal}");
                    Console.WriteLine($"Is Beef Subprimal: {ingredient.IsBeefSubprimal}");
                    Console.WriteLine($"Is Beef Subsection: {ingredient.IsBeefSubsection}");
                    Console.WriteLine($"Is Lean: {ingredient.IsLean}");

                    //Media
                    if(ingredient.Media != null)
                    {
                        ingredient.Media.ForEach(media =>
                        {
                            Console.WriteLine($"Media Caption: {media.Caption}");
                            Console.WriteLine($"Media File Name: {media.Filename}");
                            Console.WriteLine($"Media URL: {media.WidenURL}");
                        });
                    }

                    Console.WriteLine();
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error encountered on server. Message:'{ex.Message}' getting beef cuts.");
            }
        }
    }
}

Get All Recipes Example


 using BIWFD.BeefAPISDK;
    using System;
    using System.Linq;

    namespace GetAllRecipes
    {
        public class Program
        {
            public static void Main()
            {
                // Request authorization: https://developer.beefapi.beef.org/signup

                string authorizationAppID = "YourAuthorizationAppID";
                string AuthorizationAppKey = "YourAuthorizationAppKey";

                BeefAPI client;
                client = new BeefAPI(authorizationAppID, AuthorizationAppKey);

                Console.WriteLine("Recipe List");
                DisplayRecipes(client);
            }

            /// 
            /// Uses the client object to get a list of the recpies
            /// 
            /// The initialized Beef API client object.
            public static void DisplayRecipes(BeefAPI client)
            {
                try
                {
                    // Get all recipes
                    var response = client.GetAllRecipes();
                    var sortedList = response.RecipeList.OrderBy(recipe => recipe.RecipeID);

                    sortedList.ToList().ForEach(recipe =>
                    {
                        Console.WriteLine($"{recipe.RecipeID}\t{recipe.RecipeName}");
                        Console.WriteLine($"{recipe.RecipeNameSlug}");
                    });
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Error encountered on server. Message:'{ex.Message}' getting recipes.");
                }
            }
        }
    }

}

Lookups Example


 using BIWFD.BeefAPISDK;
using System;

namespace Lookups
{
    class Program
    {
        public static void Main()
        {
            // Request authorization: https://developer.beefapi.beef.org/signup

            string authorizationAppID = "YourAuthorizationAppID";
            string AuthorizationAppKey = "YourAuthorizationAppKey";

            BeefAPI client;
            client = new BeefAPI(authorizationAppID, AuthorizationAppKey);

            DisplayCommonLookups(client);
        }

        /// 
        /// Uses the client object to get a list of the recpies
        /// 
        /// The initialized Beef API client object.
        public static void DisplayCommonLookups(BeefAPI client)
        {
            try
            {
                // Get all recipes
                var response = client.GetCommonLookups();

                //Attributes By Types
                Console.WriteLine("Attributes By Types");
                response.AttributesByTypes.ForEach(attribute =>
                {
                    Console.WriteLine($"{attribute.AttributeTypeName}");
                });
                Console.WriteLine();

                //Audiences
                Console.WriteLine("Audiences");
                response.Audiences.ForEach(audience =>
                {
                    Console.WriteLine($"{audience.AudienceName}");
                });
                Console.WriteLine();

                //Beef Ingredients
                Console.WriteLine("Beef Ingredients");
                response.BeefIngredients.ForEach(beefIngredient =>
                {
                    Console.WriteLine($"{beefIngredient.IngredientID}\t{beefIngredient.IngredientName}");
                });
                Console.WriteLine();

                //Brands
                Console.WriteLine("Brands");
                response.Brands.ForEach(brand =>
                {
                    Console.WriteLine($"{brand.BrandName}");
                });
                Console.WriteLine();

                //Collection Group Name
                Console.WriteLine("Collection Group Name");
                response.CollectionGroups.ForEach(collection =>
                {
                    Console.WriteLine($"{collection.CollectionGroupName}");
                });
                Console.WriteLine();

                //Collections
                Console.WriteLine("Collections");
                response.Collections.ForEach(collection =>
                {
                    Console.WriteLine($"{collection.CollectionID}\t{collection.CollectionName}");
                });
                Console.WriteLine();

                //Grocery Sections
                Console.WriteLine("Grocery Sections");
                response.GrocerySections.ForEach(grocery =>
                {
                    Console.WriteLine($"{grocery.GrocerySectionName}");
                });
                Console.WriteLine();

                //Ingredient Groups
                Console.WriteLine("Ingredient Groups");
                response.IngredientGroups.ForEach(ingredient =>
                {
                    Console.WriteLine($"{ingredient.IngredientGroupName}");
                });
                Console.WriteLine();

                //Ingredient Types
                Console.WriteLine("Ingredient Types");
                response.IngredientTypes.ForEach(ingredientType =>
                {
                    Console.WriteLine($"{ingredientType.IngredientTypeName}");
                });
                Console.WriteLine();

                //Media Groups
                Console.WriteLine("Media Groups");
                response.MediaGroups.ForEach(media =>
                {
                    Console.WriteLine($"{media.MediaGroupName}");
                });
                Console.WriteLine();

                //Object Types
                Console.WriteLine("Object Types");
                response.ObjectTypes.ForEach(objectType =>
                {
                    Console.WriteLine($"{objectType.ObjectTypeName}");
                });
                Console.WriteLine();

                //Primal Ingredients
                Console.WriteLine("Primal Ingredients");
                response.PrimalIngredients.ForEach(ingredient =>
                {
                    Console.WriteLine($"{ingredient.IngredientID}\t{ingredient.IngredientName}");
                });
                Console.WriteLine();

                //USDA Nutrients
                Console.WriteLine("USDA Nutrients");
                response.UsdaNutrients.ForEach(nutrient =>
                {
                    Console.WriteLine($"{nutrient.NutrientDisplayName}");
                });

            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error encountered on server. Message:'{ex.Message}' getting common lookups.");
            }
        }
    }
}