Giter Site home page Giter Site logo

edamamwrapper's Introduction

Golang wrapper around the Edamam API

EDAMAM API

There are 3 different apis in the edamam suite therefor this project will consist of 3 packages.

They all have the same structure of api key and api id but returns different types.

TODO: The nutrition analyse package is not implemented. The Nutrition list is not fully implemented only consist of a few properties. --Should have a constants of available categories,cautions, meal types etc.

Query

First you need a Query object for the api consisting of a key and id you get from Edamam and the additional query parameters

query := food.Query{Key: "121321fda","1fsafsaf",}
query := food.Query{Key: "121321fda","1fsafsaf"}

Food

The structure of the query parameters:

type Query struct {
	Key           string
	Id            string
	Upc           string
	Ingredients   []string
	Health        []string
	Calories      edamam.Range
	Category      string
	CategoryLabel string
}
type Range struct {
	To   int
	From int
}

Get food articles limited by query

func GetFoods(query Query, client network.GetClient) (*Response, error)

Response contains of a list of food articles and a function which resolves the next page of result if there is a next page url in the api response:

type Response struct {
    Articles []Food
    Next     func() (*Response, error)
}
type Food struct {
    Nutrients         Nutrients `json:"nutrients"`
    Category          string    `json:"category"`
    CategoryLabel     string    `json:"categoryLabel"`
    Label             string    `json:"label"`
    FoodContentsLabel string    `json:"foodContentsLabel"`
}
// To be expanded to support all the Nutrients in the edamam api
type Nutrients struct {
    Kcal    float64 `json:"ENERC_KCAL"`
    Protein float64 `json:"PROCNT"`
    Fat     float64 `json:"FAT"`
    Carbs   float64 `json:"CHOCDF"`
}

Recipes

type Query struct {
	SearchText     string
	Key            string
	Id             string
	MaxIngredients int
	DietLabel      string
	HealthLabel    string
	CuisineType    []string
	MealType       string
	DishType       []string
	Calories       edamam.Range
	Time           edamam.Range
	Excluded       []string
}
type Range struct {
	To   int
	From int
}

Get recipes on limited by query.

func GetRecipes(query Query, client network.GetClient) (*Response, error)

Response contains of a list of recipes and a function which resolves the next page of result if there is a next page url in the api response:

type Response struct {
  Recipes []Recipe
    Next    func() (*Response, error)
}
type Recipe struct {
	Source            string                `json:"source"`
	Url               string                `json:"url"`
	Portions          float64               `json:"yield"`
	DietLabels        []string              `json:"dietLabels"`
	HealthLabels      []string              `json:"healthLabels"`
	Cautions          []string              `json:"cautions"`
	Ingredients       []Ingredient          `json:"ingredients"`
	Label             string                `json:"label"`
	FoodContentsLabel string                `json:"foodContentsLabel"`
	Calories          float64               `json:"calories"`
	TotalWeight       float64               `json:"totalWeight"`
	TotalTime         float64               `json:"totalTime"`
	CuisineType       []string              `json:"cuisineType"`
	MealType          []string              `json:"mealType"`
	DishType          []string              `json:"dishType"`
	Nutrients         Nutrients `json:"totalNutrients"`
	TotalDaily        Nutrients `json:"totalDaily"`
}
type Nutrient struct {
	Quantity float64 `json:"quantity"`
	Unit     string  `json:"unit"`
}
// To be expanded to support all the Nutrients in the edamam api
type Nutrients struct {
	Kcal    Nutrient `json:"ENERC_KCAL"`
	Protein Nutrient `json:"PROCNT"`
	Fat     Nutrient `json:"FAT"`
	Carbs   Nutrient `json:"CHOCDF"`
}

type Ingredient struct {
  Text         string  `json:"text"`
    Quantity     float64 `json:"quantity"`
    Measure      string  `json:"measure"`
    Food         string  `json:"food"`
    Weight       float64 `json:"weight"`
    FoodCategory string  `json:"foodCategory"`
}

edamamwrapper's People

Watchers

James Cloos avatar Jonathan  avatar  avatar

edamamwrapper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.