Fix Exetel Traffic import
This commit is contained in:
parent
90190bb301
commit
f6751e7a63
30
app/Classes/External/Supplier.php
vendored
30
app/Classes/External/Supplier.php
vendored
@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
abstract class Supplier
|
||||
@ -35,33 +36,29 @@ abstract class Supplier
|
||||
}
|
||||
|
||||
Log::debug(sprintf('%s:Supplier [%d], fetch data for [%s]...',self::LOGKEY,$this->o->id,$this->o->stats_lastupdate),['m'=>__METHOD__]);
|
||||
$result = Cache::remember('Supplier:'.$this->o->id.$this->o->stats_lastupdate,86400,function() {
|
||||
$key = 'Supplier:'.$this->o->id.$this->o->stats_lastupdate;
|
||||
$result = Cache::remember($key,86400,function() {
|
||||
$client = $this->getClient();
|
||||
|
||||
$result = $client->request('POST',null,[
|
||||
'query'=>[
|
||||
$this->login_user_field=>$this->o->stats_username,
|
||||
$this->login_pass_field=>$this->o->stats_password,
|
||||
$this->date_field=>$this->o->stats_lastupdate->format('Y-m-d'),
|
||||
],
|
||||
/*
|
||||
'headers' => [
|
||||
'Accept'=>'application/json',
|
||||
],
|
||||
*/
|
||||
$response = Http::get($this->o->stats_url,[
|
||||
$this->login_user_field => $this->o->stats_username,
|
||||
$this->login_pass_field => $this->o->stats_password,
|
||||
$this->date_field => $this->o->stats_lastupdate->format('Y-m-d'),
|
||||
]);
|
||||
|
||||
$api_remain = Arr::get($result->getHeader('X-RateLimit-Remaining'),0);
|
||||
$api_reset = Arr::get($result->getHeader('X-RateLimit-Reset'),0);
|
||||
// @todo These API rate limiting is untested.
|
||||
$api_remain = $response->header('X-RateLimit-Remaining');
|
||||
$api_reset = $response->header('X-RateLimit-Reset');
|
||||
|
||||
if ($api_remain === 0 AND $api_reset) {
|
||||
Log::notice(sprintf('%s:API Throttle [%d].',self::LOGKEY,$api_reset),['m'=>__METHOD__]);
|
||||
Cache::put('api_throttle',$api_reset,now()->addSeconds($api_reset));
|
||||
}
|
||||
|
||||
//dd($response->header('Content-Type'),$response->headers());
|
||||
// Assume the supplier provides an ASCII output for text/html
|
||||
if (preg_match('#^text/html;#',$x=Arr::get($result->getHeader('Content-Type'),'0'))) {
|
||||
return collect(explode("\n",$result->getBody()->getContents()))->filter();
|
||||
if (preg_match('#^text/html;#',$x=$response->header('Content-Type'))) {
|
||||
return collect(explode("\n",$response->body()))->filter();
|
||||
|
||||
} else {
|
||||
Log::error(sprintf('%s:Havent handled header type [%s]',self::LOGKEY,$x),['m'=>__METHOD__]);
|
||||
@ -94,7 +91,6 @@ abstract class Supplier
|
||||
{
|
||||
$fields = collect(explode(',',$line))->filter();
|
||||
$this->_columns = $expect;
|
||||
|
||||
if ($this->_columns->diff($fields)->count()) {
|
||||
abort('500','Missing columns in data: '.join('|',$this->_columns->diff($fields)->toArray()).' got: '.join('|',$fields));
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ The traffic import today, had mismatching records. A request to have those login
|
||||
@component('mail::table')
|
||||
| ID |
|
||||
| - |
|
||||
@foreach ($aso->traffic_mismatch($date) as $o)
|
||||
@foreach ($aso->trafficMismatch($date) as $o)
|
||||
| {{ $o->service }}
|
||||
@endforeach
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user