<?php use Emc\ListPoints; /* Example of use for EnvListPoints class * Load a list of parcel points around a given address */ require_once '../config/autoload.php'; require_once EMC_PARENT_DIR . 'layout/header.php'; $lib = new ListPoints(); $params = array('collecte' => 'exp', 'pays' => 'FR', 'cp' => '75011', 'ville' => 'PARIS'); $lib->getListPoints(array('SOGP_RelaisColis', 'MONR_CpourToi'), $params); // Display the parcel points if (!$lib->curl_error && !$lib->resp_error) { $week_days = array(1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday', 7 => 'Sunday'); ?> <h3>API ListPoints</h3> <div class="row"> <table class="table table-hover table-striped table-bordered"> <tr> <th>Carrier</th> <th>Code</th> <th>Name</th> <th>Address</th> <th>City</th> <th>Postal code</th> <th>Country</th> <th>Phone</th> <th>Description</th> <th>Calendar</th> </tr> <?php
function test_ListPoints() { $result = default_value(); $start = microtime_float(); /* Initialisation */ $env = new ListPoints(); $params = array('pays' => 'FR', 'cp' => '75011', 'ville' => 'PARIS'); $env->getListPoints(array('SOGP_RelaisColis', 'MONR_CpourToi'), $params); /* Reception test */ if ($env->curl_error) { $result['reception'] = max($result['reception'], ERROR); $result['reception_info'][count($result['reception_info'])] = 'Error while sending the query'; } elseif ($env->resp_error) { $result['reception'] = max($result['reception'], ERROR); $result['reception_info'][count($result['reception_info'])] = 'Invalid query : ' . $userData["api_key"]; foreach ($env->resp_errors_list as $message) { $result['reception_info'][count($result['reception_info'])] = $message['message']; } } else { $result['reception'] = max($result['reception'], OK); $result['reception_info'][count($result['reception_info'])] = 'Reception time : ' . (microtime_float() - $start) . 's'; } /* Additionals test */ /* Test for the result structure */ $result['additionals'][0]['name'] = 'Structure'; $result['additionals'][0]['state'] = OK; if (count($env->list_points) == 0) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '$list_points array is empty'; } else { foreach ($env->list_points as $i => $carrier) { foreach ($carrier['points'] as $x => $content) { if (!isset($content['code'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"code" not defined in $list_points[' . $i . '][' . $x . '] array'; } if (!isset($content['name'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"name" not defined in $list_points[' . $i . '][' . $x . '] array'; } if (!isset($content['address'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"address" not defined in $list_points[' . $i . '][' . $x . '] array'; } if (!isset($content['city'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"city" not defined in $list_points[' . $i . '][' . $x . '] array'; } if (!isset($content['zipcode'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"zipcode" not defined in $list_points[' . $i . '][' . $x . '] array'; } if (!isset($content['country'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"country" not defined in $list_points[' . $i . '][' . $x . '] array'; } if (!isset($content['description'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"description" not defined in $list_points[' . $i . '][' . $x . '] array'; } if (!isset($content['schedule'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], ERROR); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"schedule" not defined in $list_points[' . $i . '][' . $x . '] array'; } elseif (count($content['schedule']) != 7) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"schedule" should contains 7 days info, but contains ' . count($content['schedule']) . ' instead'; } if (isset($content['schedule'])) { foreach ($content['schedule'] as $j => $day) { if (!isset($day['weekday'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"weekday" not defined in $list_points[' . $i . '][' . $x . ']["schedule"][' . $j . '] array'; } if (!isset($day['open_am'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"open_am" not defined in $list_points[' . $i . '][' . $x . ']["schedule"][' . $j . '] array'; } if (!isset($day['close_am'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"close_am" not defined in $list_points[' . $i . '][' . $x . ']["schedule"][' . $j . '] array'; } if (!isset($day['open_pm'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"open_pm" not defined in $list_points[' . $i . '][' . $x . ']["schedule"][' . $j . '] array'; } if (!isset($day['close_pm'])) { $result['additionals'][0]['state'] = max($result['additionals'][0]['state'], WARNING); $result['additionals'][0]['info'][count($result['additionals'][0]['info'])] = '"close_pm" not defined in $list_points[' . $i . '][' . $x . ']["schedule"][' . $j . '] array'; } } } } } } $result['duration'] = microtime_float() - $start; return $result; }