Added static data to the API

This commit is contained in:
Hillel Coren 2015-11-19 13:37:30 +02:00
parent 7720c45ae2
commit 01946f7bc8
4 changed files with 30 additions and 15 deletions

View File

@ -4,6 +4,7 @@ use Auth;
use Utils;
use Response;
use Input;
use Cache;
use App\Models\Client;
use App\Models\Account;
use App\Models\AccountToken;
@ -72,4 +73,15 @@ class AccountApiController extends BaseAPIController
return $this->response($response);
}
public function getStaticData()
{
$data = [];
$cachedTables = unserialize(CACHED_TABLES);
foreach ($cachedTables as $name => $class) {
$data[$name] = Cache::get($name);
}
return $this->response($data);
}
}

View File

@ -148,19 +148,7 @@ class StartupCheck
}
// Check data has been cached
$cachedTables = [
'currencies' => 'App\Models\Currency',
'sizes' => 'App\Models\Size',
'industries' => 'App\Models\Industry',
'timezones' => 'App\Models\Timezone',
'dateFormats' => 'App\Models\DateFormat',
'datetimeFormats' => 'App\Models\DatetimeFormat',
'languages' => 'App\Models\Language',
'paymentTerms' => 'App\Models\PaymentTerm',
'paymentTypes' => 'App\Models\PaymentType',
'countries' => 'App\Models\Country',
'invoiceDesigns' => 'App\Models\InvoiceDesign',
];
$cachedTables = unserialize(CACHED_TABLES);
if (Input::has('clear_cache')) {
Session::flash('message', 'Cache cleared');
}

View File

@ -196,6 +196,7 @@ Route::group(['middleware' => 'api', 'prefix' => 'api/v1'], function()
{
Route::resource('ping', 'ClientApiController@ping');
Route::post('login', 'AccountApiController@login');
Route::get('static', 'AccountApiController@getStaticData');
Route::get('accounts', 'AccountApiController@show');
Route::resource('clients', 'ClientApiController');
Route::get('quotes/{client_id?}', 'QuoteApiController@index');
@ -487,7 +488,6 @@ if (!defined('CONTACT_EMAIL')) {
define('SOCIAL_GITHUB', 'GitHub');
define('SOCIAL_LINKEDIN', 'LinkedIn');
$creditCards = [
1 => ['card' => 'images/credit_cards/Test-Visa-Icon.png', 'text' => 'Visa'],
2 => ['card' => 'images/credit_cards/Test-MasterCard-Icon.png', 'text' => 'Master Card'],
@ -495,9 +495,23 @@ if (!defined('CONTACT_EMAIL')) {
8 => ['card' => 'images/credit_cards/Test-Diners-Icon.png', 'text' => 'Diners'],
16 => ['card' => 'images/credit_cards/Test-Discover-Icon.png', 'text' => 'Discover']
];
define('CREDIT_CARDS', serialize($creditCards));
$cachedTables = [
'currencies' => 'App\Models\Currency',
'sizes' => 'App\Models\Size',
'industries' => 'App\Models\Industry',
'timezones' => 'App\Models\Timezone',
'dateFormats' => 'App\Models\DateFormat',
'datetimeFormats' => 'App\Models\DatetimeFormat',
'languages' => 'App\Models\Language',
'paymentTerms' => 'App\Models\PaymentTerm',
'paymentTypes' => 'App\Models\PaymentType',
'countries' => 'App\Models\Country',
'invoiceDesigns' => 'App\Models\InvoiceDesign',
];
define('CACHED_TABLES', serialize($cachedTables));
function uctrans($text)
{
return ucwords(trans($text));

View File

@ -642,6 +642,7 @@ class Utils
//'Access-Control-Allow-Headers' => 'Origin, Content-Type, Accept, Authorization, X-Requested-With',
//'Access-Control-Allow-Credentials' => 'true',
'X-Total-Count' => $count,
'X-Ninja-Version' => NINJA_VERSION,
//'X-Rate-Limit-Limit' - The number of allowed requests in the current period
//'X-Rate-Limit-Remaining' - The number of remaining requests in the current period
//'X-Rate-Limit-Reset' - The number of seconds left in the current period,