|
| 1 | +<?php |
| 2 | + |
| 3 | +//********************************************************************** |
| 4 | +// Add multiple new Address Book Contacts by sending a body payload |
| 5 | +// with the array of the corresponding Address parameters. |
| 6 | +//********************************************************************** |
| 7 | + |
| 8 | +namespace Route4Me; |
| 9 | + |
| 10 | +$root = realpath(dirname(__FILE__).'/../../'); |
| 11 | +require $root.'/vendor/autoload.php'; |
| 12 | + |
| 13 | +use Route4Me\Exception\ApiError; |
| 14 | +use Route4Me\V5\AddressBook\Address; |
| 15 | +use Route4Me\V5\AddressBook\AddressBook; |
| 16 | + |
| 17 | +// Set the api key in the Route4me class |
| 18 | +Route4Me::setApiKey(Constants::API_KEY); |
| 19 | + |
| 20 | +try { |
| 21 | + $ab = new AddressBook(); |
| 22 | + |
| 23 | + ///////////////////////////////////////////// |
| 24 | + // add 2 adresses from array |
| 25 | + $arr = [[ |
| 26 | + 'address_1' => '17205 RICHMOND TNPK, MILFORD, VA, 22514', |
| 27 | + 'cached_lat' => 38.024654, |
| 28 | + 'cached_lng' => 77.338814, |
| 29 | + 'address_stop_type' => 'DELIVERY', |
| 30 | + 'address_city' => 'Tbilisi Vah', |
| 31 | + 'first_name' => 'Tusha', |
| 32 | + 'last_name' => 'Grigoriani I' |
| 33 | + ], [ |
| 34 | + 'address_1' => '17205 RICHMOND TNPK, MILFORD, VA, 22514', |
| 35 | + 'cached_lat' => 38.024654, |
| 36 | + 'cached_lng' => 77.338814, |
| 37 | + 'address_stop_type' => 'DELIVERY', |
| 38 | + 'address_city' => 'Tbilisi Vah', |
| 39 | + 'first_name' => 'Tusha', |
| 40 | + 'last_name' => 'Grigoriani II' |
| 41 | + ]]; |
| 42 | + $res = $ab->addMultipleAddresses($arr); |
| 43 | + print_r($res); |
| 44 | + |
| 45 | + ///////////////////////////////////////////// |
| 46 | + // add 2 adresses from Address |
| 47 | + $arr = [ |
| 48 | + new Address('17205 Tbilisi Vah, GEORGIAN, GE, 22514', 38.024654, 77.338814, 'DELIVERY'), |
| 49 | + new Address('17206 Tbilisi Vah, GEORGIAN, GE, 22515', 38.024654, 77.338814, 'VISIT') |
| 50 | + ]; |
| 51 | + $res = $ab->addMultipleAddresses($arr); |
| 52 | + print_r($res); |
| 53 | +} catch (ApiError $e) { |
| 54 | + echo $e->getCode() . PHP_EOL; |
| 55 | + echo $e->getMessage() . PHP_EOL; |
| 56 | +} |
0 commit comments