-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial working version - wrapping OpenFoodFacts API
- Loading branch information
Showing
10 changed files
with
157 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
|
||
return [ | ||
'geography' => 'world', | ||
'max_results' => 1000, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Palmans\LaravelOpenFoodFacts\Facades; | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class OpenFoodFacts extends Facade | ||
{ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'openfoodfacts'; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Palmans\LaravelOpenFoodFacts; | ||
|
||
use GuzzleHttp\Client; | ||
use OpenFoodFacts\Api; | ||
use Psr\SimpleCache\CacheInterface; | ||
|
||
class OpenFoodFactsApiWrapper | ||
{ | ||
protected $parameters; | ||
protected $cache; | ||
|
||
public $api; | ||
|
||
public function __construct(array $parameters, CacheInterface $cache = null) | ||
{ | ||
$this->parameters = $parameters; | ||
$this->cache = $cache; | ||
|
||
$this->api = $this->setupApi(); | ||
} | ||
|
||
protected function setupApi($environment = 'food') | ||
{ | ||
return new Api( | ||
$environment, | ||
$this->parameters['geography'] ?? 'world', | ||
null, | ||
$this->httpClient(), | ||
$this->cache | ||
); | ||
} | ||
|
||
protected function httpClient() | ||
{ | ||
return new Client([ | ||
'headers' => ['User-Agent' => $this->parameters['app'] ?? 'Laravel Open Food Facts - https://github.com/palmans/laravel-openfoodfacts'], | ||
]); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Palmans\LaravelOpenFoodFacts; | ||
|
||
use Illuminate\Contracts\Container\Container; | ||
use Illuminate\Support\ServiceProvider; | ||
|
||
class OpenFoodFactsServiceProvider extends ServiceProvider | ||
{ | ||
public function boot() | ||
{ | ||
if ($this->app->runningInConsole()) { | ||
$this->publishes([ | ||
__DIR__.'/../config/openfoodfacts.php' => config_path('openfoodfacts.php'), | ||
], 'config'); | ||
} | ||
} | ||
|
||
public function register() | ||
{ | ||
$this->mergeConfigFrom(__DIR__.'/../config/openfoodfacts.php', 'openfoodfacts'); | ||
|
||
$this->app->singleton('openfoodfacts', function (Container $app) { | ||
return new OpenFoodFacts($app); | ||
}); | ||
} | ||
} |