Skip to content

Commit

Permalink
Merge branch 'master' of github.com:getcandy/candy-client-php
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed Apr 12, 2019
2 parents da77dc3 + 2967dfb commit 9ef284c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 571 deletions.
38 changes: 9 additions & 29 deletions src/Candy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace GetCandy\Client;

use Cache;
use Closure;
use GuzzleHttp\Client;
use Psr\Log\LoggerInterface;
use GuzzleHttp\Exception\ClientException;
Expand All @@ -21,21 +20,18 @@ class Candy
protected $clientId;
protected $clientSecret;
protected $channel = 'webstore';
protected $debug;
protected $locale = 'en';
protected $client;
protected $token = null;
protected $driver;
protected $logger;

public function __construct($app, $internal = false)
public function __construct($app, $driver = 'guzzle')
{
$manager = $app->make(CandyClientManager::class);
$this->logger = $app->make(LoggerInterface::class);
if ($internal) {
$this->driver = $manager->with('internal');
} else {
$this->driver = $manager->with('guzzle');
}
$this->driver = $manager->with($driver);
}

/**
Expand Down Expand Up @@ -67,8 +63,6 @@ public function revoke($token)
],
'verify' => config('services.ecommerce_api.verify'),
]);

dd('hit');
}

public function getClient()
Expand All @@ -90,6 +84,7 @@ public function init($url, array $config = [])
$this->clientId = $config['client_id'] ?? null;
$this->locale = $config['locale'] ?? $this->locale;
$this->channel = $config['channel'] ?? $this->channel;
$this->debug = $config['debug'] ?? false;

$this->client = new Client([
'base_uri' => $this->getUri(),
Expand Down Expand Up @@ -200,32 +195,16 @@ public function execute()
$response = $job->getRequest()->getResponse();
$status = $response->getStatus();

$level = 'info';

if ($status > 400) {
$level = 'error';
}

// $this->logger->log($level, $response->toArray());

return $job->getRequest();
}

public function batch(Closure $addJobs)
{
$batch = new \GetCandy\Client\InternalBatchRequestService();

$addJobs($batch);

$batch->execute();

$responses = [];

foreach ($batch->getJobs() as $key => $job) {
$responses[$key] = $job->getRequest()->getResponse();
if ($this->debug) {
// Helps to see actual response from API
$this->logger->log('debug', $response);
}

return $responses;
return $job->getRequest();
}

public function reset()
Expand Down Expand Up @@ -312,6 +291,7 @@ public function getToken($force = false)
if ($this->token) {
return $this->token;
}

return $this->getClientToken();
}

Expand Down
8 changes: 0 additions & 8 deletions src/CandyClientManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Support\Manager;
use GetCandy\Client\Drivers\Guzzle;
use GetCandy\Client\Drivers\Internal;

class CandyClientManager extends Manager
{
Expand All @@ -31,13 +30,6 @@ public function createGuzzleDriver()
);
}

public function createInternalDriver()
{
return $this->buildProvider(
Internal::class
);
}

/**
* Build a layout provider instance.
*
Expand Down
81 changes: 0 additions & 81 deletions src/Drivers/Internal.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/GetCandyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GetCandyServiceProvider extends ServiceProvider
public function boot()
{
$this->app->singleton(CandyClient::class, function ($app) {
return new Candy($app, config('getcandy.internal_requests', false));
return new Candy($app);
});

$this->app->bind(CandyClientManager::class, function ($app) {
Expand Down
Loading

0 comments on commit 9ef284c

Please sign in to comment.