GithubHelp home page GithubHelp logo

cedhavalpanchal / openfoodfacts-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from openfoodfacts/openfoodfacts-php

1.0 0.0 0.0 95 KB

PHP wrapper for Open Food Facts

License: MIT License

PHP 100.00%

openfoodfacts-php's Introduction

openfoodfacts-php

Open Food Facts

PHP API Wrapper for Open Food Facts, the open database about food.

Project Status Build Status Average time to resolve an issue Percentage of issues still open

Installation

With Composer:

composer require openfoodfacts/openfoodfacts-php

Usage

This is the most basic way of creating the API:

$api = new OpenFoodFacts\Api('food','fr');
$product = $api->getProduct('3057640385148');

In the example above you access the "food" database, limited to the French language/country scope. The first parameter is either

  • "food"
  • "beauty" or
  • "pet"

to decide which product database you want to use.

The second parameter decides the language/country scope of the chosen database: f.e. "world" or "de" or "fr".

For more details on this topic: see the API Documentation

These are all the parameters you really need for basic usage.

As return types for $api->getProduct you get an Document::class Object. This may also be an Object of Type FoodProduct::class,PetProduct::class, BeautyProduct::class depending on which API you are creating. These objects inherit from the more generic Document::class

In the example above, we use the 'food' API and there will get a FoodProduct::class

For getting a first overview the Document::class has a function to return an array representation(sorted) for a first start.

$product = $api->getProduct('3057640385148');
$productDataAsArray = $product->getData();

Optional Parameters

The other parameters are optional and for a more sophisticated use of the api (from a software development point of view):

An example in code is found here: cached_example.php

LoggerInterface: A logger which decieds where to log errors to (file, console , etc)

see: PSR-3 Loggerinterface

ClientInterface: The HTTP Client - to adjust the connection configs to your needs and more

see: Guzzle HTTP Client

CacheInterface: To temporarily save the results of API request to improve the performance and to reduce the load on the API- Server

see: PSR-16 Simple Cache

Development

Contributing

  1. Fork it ( https://github.com/openfoodfacts/openfoodfacts-php/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Launch test vendor/bin/phpunit && cs-fixer vendor/bin/php-cs-fixer fix
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

openfoodfacts-php's People

Contributors

dwarfex avatar teolemon avatar benoit382 avatar rampmaster avatar jordan-temim avatar mikaelcom avatar rmoreno-as avatar sebrave avatar tazorax avatar deepsourcebot avatar nicolasleger avatar deepsource-autofix[bot] avatar dependabot-preview[bot] avatar

Stargazers

Dhaval Panchal avatar

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.