Skip to content

Commit

Permalink
5.x Updates
Browse files Browse the repository at this point in the history
- Better error handling
- Share is depreacated, now is singleton
- Updated README.md
  • Loading branch information
Braunson committed Aug 13, 2017
1 parent 2dca38c commit b5f8dc1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 40 deletions.
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ How to Install
1. Install the `braunson/fatsecret` package

```shell
$ composer require "braunson/fatsecret:dev-master"
$ composer require "braunson/fatsecret"
```

2. Update `app/config/app.php` to activate FatSecret package
2. Update `config/app.php` to activate FatSecret package

```php
# Add `FatSecretServiceProvider` to the `providers` array
Expand All @@ -34,20 +34,32 @@ How to Install
Configuration
-------------

1. Go to `app/config/services.php` and add this in with your details in the provided array
1. Go to `config/services.php` and add this in with your details in the provided array

```php
// API Key & Secret (http://platform.fatsecret.com)
'fatsecret' => [
'key' => 'YOUR-API-KEY-HERE',
'secret' => 'YOUR-API-SECRET-HERE',
],
'fatsecret' => [
'secret' => env('FATSECRET_SECRET'),
'key' => env('FATSECRET_KEY'),
],
```

2. Open your `.env` file and add in
```
FATSECRET_SECRET=YOUR-API-SECRET
FATSECRET_KEY=YOUR-API-KEY
```


Usage
------------------------

When you are using this package in a file, make sure to add this to the top of your file:

```php
use Fatsecret;
```

The FatSecret is available as `FatSecret`, for example:

```php
Expand Down
9 changes: 3 additions & 6 deletions src/Braunson/FatSecret/FatSecret.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,9 @@ private function GetQueryResponse($requestUrl, $postString)
private function ErrorCheck($exception)
{
if (isset($exception['error'])) {
App::fatal(function(Exception $exception)
{
Log::error($exception['error']['message']);
});

App::abort(500, $exception['error']['message']);
\Log::error($exception['error']['message']);
$backtrace = debug_backtrace();
throw new \ErrorException($exception['error']['message'], 0, $exception['error']['code'], __FILE__, $backtrace[0]['line']);
}
}
}
32 changes: 5 additions & 27 deletions src/Braunson/FatSecret/FatSecretServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,22 @@

class FatSecretServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = false;

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$this->package('braunson/fat-secret');
//
}

/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['fatsecret'] = $this->app->share(function($app)
{
return new FatSecret(\Config::get('services.fatsecret.key'), \Config::get('services.fatsecret.secret'));
$this->app->singleton(FatSecret::class, function () {
return new FatSecret(config('services.fatsecret.key'), config('services.fatsecret.secret'));
});

$this->app->alias(FatSecret::class, 'fatsecret');
}

/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('fatsecret');
}

}

0 comments on commit b5f8dc1

Please # to comment.