| 1 |
<?php |
| 2 |
namespace Depicter\Controllers\Ajax; |
| 3 |
|
| 4 |
use Averta\WordPress\Utility\JSON; |
| 5 |
use Depicter\GuzzleHttp\Exception\GuzzleException; |
| 6 |
use Psr\Http\Message\ResponseInterface; |
| 7 |
use WPEmerge\Requests\RequestInterface; |
| 8 |
|
| 9 |
class AppInfoAjaxController { |
| 10 |
|
| 11 |
/** |
| 12 |
* Retrieves Lists of all entries. (GET) |
| 13 |
* |
| 14 |
* @param RequestInterface $request |
| 15 |
* @param string $view |
| 16 |
* |
| 17 |
* @return ResponseInterface |
| 18 |
* @throws GuzzleException |
| 19 |
*/ |
| 20 |
public function changelogs( RequestInterface $request, string $view) |
| 21 |
{ |
| 22 |
try { |
| 23 |
$response = \Depicter::remote()->get( 'v1/core/changelogs', [ 'query' => $request->getQueryParams() ] ); |
| 24 |
return \Depicter::json( |
| 25 |
JSON::decode( $response->getBody(), true ) |
| 26 |
)->withStatus( 200 ); |
| 27 |
|
| 28 |
} catch( \Exception $exception ) { |
| 29 |
return \Depicter::json([ |
| 30 |
'errors' => [ $exception->getMessage() ] |
| 31 |
])->withStatus( 503 ); |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Retrieves the existing promotion |
| 37 |
* |
| 38 |
* @param RequestInterface $request |
| 39 |
* @param string $view |
| 40 |
* |
| 41 |
* @return ResponseInterface |
| 42 |
* @throws GuzzleException |
| 43 |
*/ |
| 44 |
public function getPromotion( RequestInterface $request, string $view) |
| 45 |
{ |
| 46 |
try { |
| 47 |
$response = \Depicter::remote()->get( 'v1/core/announcements', [ 'query' => [ 'category' => 'promotions-wp-dash' ] ] ); |
| 48 |
$promotions = JSON::decode( $response->getBody(), true ); |
| 49 |
$currentPromotion = []; |
| 50 |
|
| 51 |
if( ! empty( $promotions['hits'] ) ){ |
| 52 |
$currentPromotion = reset($promotions['hits'] ); |
| 53 |
} |
| 54 |
return \Depicter::json( $currentPromotion )->withStatus( 200 ); |
| 55 |
|
| 56 |
} catch( \Exception $exception ) { |
| 57 |
return \Depicter::json([ |
| 58 |
'errors' => [ $exception->getMessage() ] |
| 59 |
])->withStatus( 503 ); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
} |
| 64 |
|