Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue where the base url was stored in a static variable. #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php"
verbose="false"
colors="false"
colors="true"
cacheResult="false">
<testsuites>
<testsuite name="Route4me PHP SDK Test Suite">
Expand Down
116 changes: 59 additions & 57 deletions src/Route4Me/Enum/Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,76 @@

class Endpoint
{
const BASE_URL = 'https://api.route4me.com';
const WH_BASE_URL = 'https://wh.route4me.com/modules';
const BASE_URL = '';
const BASE_URL_1 = 'https://api.route4me.com';
const WH_BASE_URL = '';
const WH_BASE_URL_1 = 'https://wh.route4me.com/modules';

const AVOIDANCE_ZONE = '/api.v4/avoidance.php';
const TERRITORY_V4 = '/api.v4/territory.php';
const AVOIDANCE_ZONE = self::BASE_URL_1 . '/api.v4/avoidance.php';
const TERRITORY_V4 = self::BASE_URL_1 . '/api.v4/territory.php';

const GET_ACTIVITIES = '/api/get_activities.php';
const ACTIVITY_FEED = '/api.v4/activity_feed.php';
const GET_ACTIVITIES = self::BASE_URL_1 . '/api/get_activities.php';
const ACTIVITY_FEED = self::BASE_URL_1 . '/api.v4/activity_feed.php';

const ADDRESS_V4 = '/api.v4/address.php';
const MOVE_ROUTE_DESTINATION = '/actions/route/move_route_destination.php';
const MARK_ADDRESS_DEPARTED = '/api/route/mark_address_departed.php';
const UPDATE_ADDRESS_VISITED = '/actions/address/update_address_visited.php';
const ADDRESS_V4 = self::BASE_URL_1 . '/api.v4/address.php';
const MOVE_ROUTE_DESTINATION = self::BASE_URL_1 . '/actions/route/move_route_destination.php';
const MARK_ADDRESS_DEPARTED = self::BASE_URL_1 . '/api/route/mark_address_departed.php';
const UPDATE_ADDRESS_VISITED = self::BASE_URL_1 . '/actions/address/update_address_visited.php';

const ADDRESS_BOOK_V4 = '/api.v4/address_book.php';
const ADDRESS_BOOK_GROUP = '/api.v4/address_book_group.php';
const ADDRESS_BOOK_SEARCH = '/api/address_book/get_search_group_addresses.php';
const MODIFY_CONTACT = '/api/address_book/modify_contact.php';
const ADDRESS_BOOK_V4 = self::BASE_URL_1 . '/api.v4/address_book.php';
const ADDRESS_BOOK_GROUP = self::BASE_URL_1 . '/api.v4/address_book_group.php';
const ADDRESS_BOOK_SEARCH = self::BASE_URL_1 . '/api/address_book/get_search_group_addresses.php';
//const MODIFY_CONTACT = '/api/address_book/modify_contact.php';

const GEOCODER = '/api/geocoder.php';
const JSON_GEOCODE = '/actions/upload/json-geocode.php';
const GEOCODER = self::BASE_URL_1 . '/api/geocoder.php';
//const JSON_GEOCODE = '/actions/upload/json-geocode.php';
const STREET_DATA = 'https://rapid.route4me.com/street_data/';
const STREET_DATA_ZIPCODE = 'https://rapid.route4me.com/street_data/zipcode/';
const STREET_DATA_SERVICE = 'https://rapid.route4me.com/street_data/service/';

const USER_V4 = '/api.v4/user.php';
const VERIFY_DEVICE_LICENSE = '/api/device/verify_device_license.php';
const USER_LICENSE = '/api/member/user_license.php';
const WEBINAR_REGISTER = '/actions/webinar_register.php';
const EXPIRE_SESSION = '/datafeed/session/expire_session.php';
const VALIDATE_SESSION = '/datafeed/session/validate_session.php';
const AUTHENTICATE = '/actions/authenticate.php';
const REGISTER_ACTION = '/actions/register_action.php';
const VIEW_USER_LOCATIONS = '/api/track/view_user_locations.php';
const CONFIGURATION_SETTINGS = '/api.v4/configuration-settings.php';

const OPTIMIZATION_PROBLEM = '/api.v4/optimization_problem.php';
const HYBRID_DATE_OPTIMIZATION = '/api.v4/hybrid_date_optimization.php';
const CHANGE_HYBRID_OPTIMIZATION_DEPOT = '/api/change_hybrid_optimization_depot.php';

const ORDER_V4 = '/api.v4/order.php';
const ORDER_CUSTOM_FIELDS_V4 = '/api.v4/order_custom_user_fields.php';

const ROUTE_V4 = '/api.v4/route.php';
const ROUTE_DUPLICATE = '/actions/duplicate_route.php';
const ROUTES_DELETE = '/actions/delete_routes.php';
const REOPTIMIZE_V3_2 = '/api.v3/route/reoptimize_2.php';
const ROUTES_MERGE = '/actions/merge_routes.php';
const ROUTE_SHARE = '/actions/route/share_route.php';
const ROUTE_NOTES_ADD = '/actions/addRouteNotes.php';
const STATUS_V4 = '/api.v4/status.php';

const GET_DEVICE_LOCATION = '/api/track/get_device_location.php';
const TRACK_SET = '/track/set.php';
const USER_LOCATION = '/api/track/view_user_locations.php';

const NOTE_CUSTOM_TYPES_V4 = '/api.v4/note_custom_types.php';

const ViewVehicles = '/api/vehicles/view_vehicles.php';
const VEHICLE_V4 = '/api/vehicles';
const VEHICLE_V4_API = '/api.v4/vehicle.php';
const USER_V4 = self::BASE_URL_1 . '/api.v4/user.php';
const VERIFY_DEVICE_LICENSE = self::BASE_URL_1 . '/api/device/verify_device_license.php';
const USER_LICENSE = self::BASE_URL_1 . '/api/member/user_license.php';
const WEBINAR_REGISTER = self::BASE_URL_1 . '/actions/webinar_register.php';
//const EXPIRE_SESSION = '/datafeed/session/expire_session.php';
const VALIDATE_SESSION = self::BASE_URL_1 . '/datafeed/session/validate_session.php';
const AUTHENTICATE = self::BASE_URL_1 . '/actions/authenticate.php';
const REGISTER_ACTION = self::BASE_URL_1 . '/actions/register_action.php';
const VIEW_USER_LOCATIONS = self::BASE_URL_1 . '/api/track/view_user_locations.php';
const CONFIGURATION_SETTINGS = self::BASE_URL_1 . '/api.v4/configuration-settings.php';

const OPTIMIZATION_PROBLEM = self::BASE_URL_1 . '/api.v4/optimization_problem.php';
const HYBRID_DATE_OPTIMIZATION = self::BASE_URL_1 . '/api.v4/hybrid_date_optimization.php';
const CHANGE_HYBRID_OPTIMIZATION_DEPOT = self::BASE_URL_1 . '/api/change_hybrid_optimization_depot.php';

const ORDER_V4 = self::BASE_URL_1 . '/api.v4/order.php';
const ORDER_CUSTOM_FIELDS_V4 = self::BASE_URL_1 . '/api.v4/order_custom_user_fields.php';

const ROUTE_V4 = self::BASE_URL_1 . '/api.v4/route.php';
//const ROUTE_DUPLICATE = '/actions/duplicate_route.php';
//const ROUTES_DELETE = '/actions/delete_routes.php';
const REOPTIMIZE_V3_2 = self::BASE_URL_1 . '/api.v3/route/reoptimize_2.php';
const ROUTES_MERGE = self::BASE_URL_1 . '/actions/merge_routes.php';
const ROUTE_SHARE = self::BASE_URL_1 . '/actions/route/share_route.php';
const ROUTE_NOTES_ADD = self::BASE_URL_1 . '/actions/addRouteNotes.php';
const STATUS_V4 = self::BASE_URL_1 . '/api.v4/status.php';

const GET_DEVICE_LOCATION = self::BASE_URL_1 . '/api/track/get_device_location.php';
const TRACK_SET = self::BASE_URL_1 . '/track/set.php';
const USER_LOCATION = self::BASE_URL_1 . '/api/track/view_user_locations.php';

const NOTE_CUSTOM_TYPES_V4 = self::BASE_URL_1 . '/api.v4/note_custom_types.php';

//const ViewVehicles = '/api/vehicles/view_vehicles.php';
const VEHICLE_V4 = self::WH_BASE_URL_1 . '/api/vehicles';
const VEHICLE_V4_API = self::BASE_URL_1 . '/api.v4/vehicle.php';

const TELEMATICS_VENDORS = "http://telematics.route4me.com/api/vendors.php";
const TELEMATICS_REGISTER_MEMBER = "/api.v4/telematics/register.php";
const TELEMATICS_CONNECTION = "/api.v4/telematics/connections.php";
const TELEMATICS_VENDORS_INFO = "/api.v4/telematics/vendors.php";
const TELEMATICS_REGISTER_MEMBER = self::BASE_URL_1 . "/api.v4/telematics/register.php";
const TELEMATICS_CONNECTION = self::BASE_URL_1 . "/api.v4/telematics/connections.php";
//const TELEMATICS_VENDORS_INFO = "/api.v4/telematics/vendors.php";

const MEMBER_CAPABILITIES = "/api/member/capabilities.php";
const MEMBER_CAPABILITIES = self::BASE_URL_1 . "/api/member/capabilities.php";

const SCHEDULE_CALENDAR = "/api/schedule_calendar_data.php";
const SCHEDULE_CALENDAR = self::BASE_URL_1 . "/api/schedule_calendar_data.php";
}
12 changes: 3 additions & 9 deletions src/Route4Me/Geocoding.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,14 @@ public static function reverseGeocoding($params)

public static function getStreetData($params)
{
Route4Me::setBaseUrl(Endpoint::STREET_DATA);

$allPathFields = ['pk', 'offset', 'limit'];

$url_query = Route4Me::generateUrlPath($allPathFields, $params);

$query = [];

$response = Route4Me::makeRequst([
'url' => $url_query,
'url' => Endpoint::STREET_DATA . $url_query,
'method' => 'GET',
'query' => $query,
]);
Expand All @@ -63,16 +61,14 @@ public static function getStreetData($params)

public static function getZipCode($params)
{
Route4Me::setBaseUrl(Endpoint::STREET_DATA_ZIPCODE);

$allPathFields = ['zipcode', 'offset', 'limit'];

$url_query = Route4Me::generateUrlPath($allPathFields, $params);

$query = [];

$response = Route4Me::makeRequst([
'url' => $url_query,
'url' => Endpoint::STREET_DATA_ZIPCODE . $url_query,
'method' => 'GET',
'query' => $query,
]);
Expand All @@ -82,16 +78,14 @@ public static function getZipCode($params)

public static function getService($params)
{
Route4Me::setBaseUrl(Endpoint::STREET_DATA_SERVICE);

$allPathFields = ['zipcode', 'housenumber', 'offset', 'limit'];

$url_query = Route4Me::generateUrlPath($allPathFields, $params);

$query = [];

$response = Route4Me::makeRequst([
'url' => $url_query,
'url' => Endpoint::STREET_DATA_SERVICE . $url_query,
'method' => 'GET',
'query' => $query,
]);
Expand Down
15 changes: 15 additions & 0 deletions src/Route4Me/Members/MemberConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ public function __construct()
Route4Me::setBaseUrl(Endpoint::BASE_URL);
}

public static function fromArray(array $params)
{
$memberConfiguration = new self();

foreach ($params as $key => $value) {
if (property_exists($memberConfiguration, $key)) {
$memberConfiguration->{$key} = $value;
} else {
throw new BadParam("Correct parameter must be provided. Wrong Parameter: $key");
}
}

return $memberConfiguration;
}

/*
* Create new member configuration key-value pair.
* @param array $params
Expand Down
8 changes: 0 additions & 8 deletions src/Route4Me/TelematicsGateway/TelematicsConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ class TelematicsConnection extends \Route4Me\Common
*/
public function createTelematicsConnection($apiToken, $params)
{
Route4Me::setBaseUrl(Endpoint::BASE_URL);

$excludeFields = ['id', 'connection_token'];

$allBodyFields = Route4Me::getObjectProperties(new TelematicsConnectionParameters(), $excludeFields);
Expand All @@ -191,8 +189,6 @@ public function createTelematicsConnection($apiToken, $params)
*/
public function deleteTelematicsConnection($apiToken, $connectionToken)
{
Route4Me::setBaseUrl(Endpoint::BASE_URL);

$result = Route4Me::makeRequst([
'url' => Endpoint::TELEMATICS_CONNECTION,
'method' => 'DELETE',
Expand All @@ -213,8 +209,6 @@ public function deleteTelematicsConnection($apiToken, $connectionToken)
*/
public function getTelematicsConnections($apiToken)
{
Route4Me::setBaseUrl(Endpoint::BASE_URL);

$result = Route4Me::makeRequst([
'url' => Endpoint::TELEMATICS_CONNECTION,
'method' => 'GET',
Expand All @@ -235,8 +229,6 @@ public function getTelematicsConnections($apiToken)
*/
public function getTelematicsConnection($apiToken, $connectionToken)
{
Route4Me::setBaseUrl(Endpoint::BASE_URL);

$result = Route4Me::makeRequst([
'url' => Endpoint::TELEMATICS_CONNECTION,
'method' => 'GET',
Expand Down
6 changes: 1 addition & 5 deletions src/Route4Me/TelematicsGateway/TelematicsVendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ class TelematicsVendor extends Common
*/
public static function GetTelematicsVendors($params)
{
Route4Me::setBaseUrl(Endpoint::TELEMATICS_VENDORS);

$allQueryFields = ['vendor_id', 'is_integrated', 'page', 'per_page', 'country', 'feature', 'search', 'vendors'];

$vendors = Route4Me::makeRequst([
'url' => '',
'url' => Endpoint::TELEMATICS_VENDORS,
'method' => 'GET',
'query' => Route4Me::generateRequestParameters($allQueryFields, $params),
]);
Expand Down Expand Up @@ -139,8 +137,6 @@ public static function GetRandomVendorID($offset, $limit)
*/
public static function RegisterTelematicsMember($params)
{
Route4Me::setBaseUrl(Endpoint::BASE_URL);

$allQueryFields = ['member_id', 'api_key'];

$vendors = Route4Me::makeRequst([
Expand Down
4 changes: 1 addition & 3 deletions src/Route4Me/TelematicsVendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ class TelematicsVendor extends Common

public static function GetTelematicsVendors($params)
{
Route4Me::setBaseUrl(Endpoint::TELEMATICS_VENDORS);

$allQueryFields = ['vendor_id', 'is_integrated', 'page', 'per_page', 'country', 'feature', 'search', 'vendors'];

$vendors = Route4Me::makeRequst([
'url' => '',
'url' => Endpoint::TELEMATICS_VENDORS,
'method' => 'GET',
'query' => Route4Me::generateRequestParameters($allQueryFields, $params),
]);
Expand Down
Loading