Skip to content

Commit 47d7642

Browse files
authored
Merge pull request #25 from route4me/add_address_book
Added Address Book V5 API.
2 parents e5b8eb9 + b1b30b3 commit 47d7642

39 files changed

+3332
-36
lines changed

UnitTestFiles/Test/V5/AddressBookUnitTests.php

Lines changed: 673 additions & 0 deletions
Large diffs are not rendered by default.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "route4me/route4me-php",
33
"description": "Access Route4Me's logistics-as-a-service API using our PHP SDK",
44
"minimum-stability": "stable",
5-
"version": "1.2.7",
5+
"version": "1.2.8",
66
"authors": [
77
{
88
"name": "Igor Route4Me",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
//**********************************************************************
4+
// Add a new Address Book Contact by sending a body payload with
5+
// the corresponding 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 adress from array
25+
$params = [
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'
33+
];
34+
$res = $ab->addAddress($params);
35+
print_r($res);
36+
37+
/////////////////////////////////////////////
38+
// add adress from Address and array
39+
$params['address_stop_type'] = 'VISIT';
40+
$address = new Address($params);
41+
$res = $ab->addAddress($address);
42+
print_r($res);
43+
44+
/////////////////////////////////////////////
45+
// add adress from Address
46+
$address = new Address('17205 Tbilisi Vah, GEORGIAN, GE, 22514', 38.024654, 77.338814, 'DELIVERY');
47+
$res = $ab->addAddress($address);
48+
print_r($res);
49+
} catch (ApiError $e) {
50+
echo $e->getCode() . PHP_EOL;
51+
echo $e->getMessage() . PHP_EOL;
52+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
//**********************************************************************
4+
// Delete the Address Book Contacts located in the selected areas by
5+
// sending the corresponding body payload.
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\AddressBook;
15+
16+
// Set the api key in the Route4me class
17+
Route4Me::setApiKey(Constants::API_KEY);
18+
19+
try {
20+
$ab = new AddressBook();
21+
22+
$filter = [
23+
'query' => 'Tusha',
24+
'selected_areas' => [[
25+
'type' => 'circle',
26+
'value' => [
27+
'center' => [
28+
'lat' => 38.024654,
29+
'lng' => 77.338814
30+
],
31+
'distance' => 10000
32+
]
33+
]]
34+
];
35+
$res = $ab->deleteAddressesByAreas($filter);
36+
print_r($res);
37+
} catch (ApiError $e) {
38+
echo $e->getCode() . PHP_EOL;
39+
echo $e->getMessage() . PHP_EOL;
40+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
//**********************************************************************
4+
// Delete multiple Address Book Contacts by sending a body payload with
5+
// the array of the corresponding Address IDs.
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\AddressBook;
15+
16+
// Set the api key in the Route4me class
17+
Route4Me::setApiKey(Constants::API_KEY);
18+
19+
try {
20+
$ab = new AddressBook();
21+
22+
$addressIds = [96100573, 96100961];
23+
$res = $ab->deleteAddressesByIds($addressIds);
24+
print_r($res);
25+
} catch (ApiError $e) {
26+
echo $e->getCode() . PHP_EOL;
27+
echo $e->getMessage() . PHP_EOL;
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
//**********************************************************************
4+
// Export Addresses by the specified area IDs.
5+
//**********************************************************************
6+
7+
namespace Route4Me;
8+
9+
$root = realpath(dirname(__FILE__).'/../../');
10+
require $root.'/vendor/autoload.php';
11+
12+
use Route4Me\Exception\ApiError;
13+
use Route4Me\V5\AddressBook\AddressBook;
14+
15+
// Set the api key in the Route4me class
16+
Route4Me::setApiKey(Constants::API_KEY);
17+
18+
try {
19+
$ab = new AddressBook();
20+
21+
$territoryIds = [96100573, 96100961];
22+
$filename = 'test_export.csv';
23+
24+
$res = $ab->exportAddressesByAreaIds($territoryIds, $filename);
25+
print_r($res);
26+
} catch (ApiError $e) {
27+
echo $e->getCode() . PHP_EOL;
28+
echo $e->getMessage() . PHP_EOL;
29+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
//**********************************************************************
4+
// Export the Address Book Contacts located in the selected areas
5+
// by sending the corresponding body payload.
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\AddressBook;
15+
16+
// Set the api key in the Route4me class
17+
Route4Me::setApiKey(Constants::API_KEY);
18+
19+
try {
20+
$ab = new AddressBook();
21+
22+
/////////////////////////////////////////////
23+
// update adresses in circle aria
24+
$filter = [
25+
'query' => "Tusha",
26+
'bounding_box' => null,
27+
'selected_areas' => [[
28+
'type' => 'circle',
29+
'value' => [
30+
'center' => [
31+
'lat' => 38.024654,
32+
'lng' => 77.338814
33+
],
34+
'distance' => 10000
35+
]
36+
]],
37+
'filename' => 'test_export.csv'
38+
];
39+
40+
$res = $ab->exportAddressesByAreas($filter);
41+
print_r($res);
42+
} catch (ApiError $e) {
43+
echo $e->getCode() . PHP_EOL;
44+
echo $e->getMessage() . PHP_EOL;
45+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
//**********************************************************************
4+
// Export Address Book Contacts to the specified file by sending a body
5+
// payload with the array of the corresponding Address IDs.
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\AddressBook;
15+
16+
// Set the api key in the Route4me class
17+
Route4Me::setApiKey(Constants::API_KEY);
18+
19+
try {
20+
$ab = new AddressBook();
21+
22+
$addressIds = [96100573, 96100961];
23+
$filename = 'test_export.csv';
24+
25+
$res = $ab->exportAddressesByIds($addressIds, $filename);
26+
print_r($res);
27+
} catch (ApiError $e) {
28+
echo $e->getCode() . PHP_EOL;
29+
echo $e->getMessage() . PHP_EOL;
30+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
//**********************************************************************
4+
// Find an Address by sending the 'address_id' query parameter.
5+
//**********************************************************************
6+
7+
namespace Route4Me;
8+
9+
$root = realpath(dirname(__FILE__).'/../../');
10+
require $root.'/vendor/autoload.php';
11+
12+
use Route4Me\Exception\ApiError;
13+
use Route4Me\V5\AddressBook\AddressBook;
14+
15+
// Set the api key in the Route4me class
16+
Route4Me::setApiKey(Constants::API_KEY);
17+
18+
try {
19+
$ab = new AddressBook();
20+
21+
$addressId = 51111441;
22+
$res = $ab->getAddressById($addressId);
23+
print_r($res);
24+
} catch (ApiError $e) {
25+
echo $e->getCode() . PHP_EOL;
26+
echo $e->getMessage() . PHP_EOL;
27+
}

0 commit comments

Comments
 (0)