tourcms / tourcms-php
TourCMS API wrapper for PHP
Installs: 89 041
Dependents: 1
Suggesters: 0
Security: 0
Stars: 9
Watchers: 15
Forks: 9
Open Issues: 5
Requires
- php: >=8.1
- dev-main
- v4.9.0
- v4.8.0
- v4.7.0
- v4.6.0
- v4.5.0
- v4.4.0
- v4.3.0
- v4.2.0
- v4.1.1
- v4.1.0
- v4.0.0
- v3.14.0
- v3.13.0
- v3.12.0
- v3.11.0
- v3.10.0
- v3.9.2
- v3.9.1
- v3.9.0
- v3.8.0
- v3.7.0
- v3.6.1
- v3.6.0.x-dev
- v3.6.0
- v3.5.0.x-dev
- 3.5.0
- v3.4.0.x-dev
- 3.4.0
- 3.3.0.x-dev
- 3.3.0
- dev-master / 3.2.x-dev
- v3.2.0.x-dev
- 3.2.0
- v3.1.0.x-dev
- 3.1.0
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- 1.x-dev
- v1.8.3
- v1.8.2
- v1.8.1
- v1.8
- dev-release/4.10.0
- dev-feature/TOURCMS-9676-named-tickets-fixes
- dev-feature/TOURCMS-9400-importer-get-tour-facets-api-endpoint
- dev-epic/TOURCMS-8898-tour-pickup-members-crud
- dev-feature/TOURCMS-9050-update-pickup-in-a-route-endpoint
- dev-epic/TOURCMS-7996_Universal-tour-importer
- dev-feature/TOURCMS-8372
- dev-feature/TOURCMS-7550-add-user-agent-support-to-php-wrapper-rebase
- dev-release/v4.0.0
- dev-epic/TOURCMS-8185_Show-markup-scheme-endpoint
- dev-release/3.12.0
- dev-feature/TOURCMS-7595-update-channel
- dev-release/3.11.0
- dev-release/3.9.3
- dev-feature/TOURCMS-3601
- dev-release/3.8.0
- dev-feature/TOURCMS-678_payworks_create_payment_endpoint
- dev-release/3.7.0
- dev-feature/TOURCMS-3107_listorders_build_new_booking_search_endpoint
- dev-release/3.6.1
- dev-feature/TOURCMS-3101
- dev-release/3.6.0
- dev-feature/TOURCMS-2707
- dev-release/3.5.0
- dev-feature/TOURCMS-2502_Spreedly-complete
- dev-release/3.4.0
- dev-release/3.3.0
- dev-feature/TOURCMS-1984_Method-for-endpoint-change
- dev-release/3.2.0
- dev-feature/TOURCMS-1970
- dev-feature/TOURCMS-851_US_add_documentation
This package is auto-updated.
Last update: 2024-11-03 07:04:29 UTC
README
Installation
Installing via Composer (Recommended)
- Install Composer, add
"tourcms/tourcms-php": "4.*",
to therequires
section of yourcomposer.json
: - Ensure you are including composer's
autoload.php
, alternatively includeTourCMS.php
directly.
Installing Manually
- Download the source zip, extract to your web server
- Include
TourCMS.php
in your source
Upgrading from version 1.x
If you are upgrading from version 1.x of the library the latest TourCMS.php
should be more or less a straight swap. The major change being that to adhere to PHP PSR-4 standards, the class is now namespaced. Broadly speaking there are two different ways to update existing code to account for this:
Aliasing the namespace
If you already have a global include file that includes TourCMS.php
you could add the following line immediately after TourCMS.php
is included:
use TourCMS\Utils\TourCMS as TourCMS;
Your existing code should then work as-is, for example when you create a new instance of the TourCMS class you would have:
$tourcms = new TourCMS(0, 'YOUR_PASSWORD', 'simplexml');
Using the fully qualified name
Alternatively use the fully qualified name when you create a new instance of the class:
$tourcms = new TourCMS\Utils\TourCMS(0, 'YOUR_PASSWORD', 'simplexml');
Usage
// Common configuration parameters // Marketplace ID will be 0 for Tour Operators, non-zero for Marketplace Agents // Agents can find their Marketplace ID in the API page in TourCMS settings $marketplace_id = 0; // API key will be a string, find it in the API page in TourCMS settings $api_key = "YOUR_KEY_HERE"; // Timeout will set the maximum execution time, in seconds. If set to zero, no time limit is imposed. $timeout = 0; // Channel ID represents the Tour Operator channel to call the API against // Tour Operators may have multiple channels, so enter the correct one here // Agents can make some calls (e.g. tour_search()) across multiple channels // by entering a Channel ID of 0 or omitting it, or they can restrict to a // specific channel by providing the Channel ID $channel_id = 0; // Create a new TourCMS instance // Optionally alias the namespace use TourCMS\Utils\TourCMS as TourCMS; $tourcms = new TourCMS($marketplace_id, $api_key, 'simplexml', $timeout); // 'simplexml' returns as a SimpleXMLObject // 'raw' returns the XML as as String // Set a User-Agent $tourcms->set_user_agent('Example Tours Website'); // Call the API // Here as a quick example we search for some tours $result = $tourcms->search_tours('', $channel_id); // Display the output print_r($result);
Further Examples
API documentation on tourcms.com
Each API method in the TourCMS API documentation includes full PHP sample code.
Examples in this repository
Additionally there are some examples included in this repository, to run them:
- Copy the
src/examples
directory to your web root - Rename
examples/config-example.php
toexamples/config.php
- Load your API credentials in the config file and ensure the path to
TourCMS.php
is correct - Point your web browser at the examples folder
Environment test
The library can attempt to check your local environment and API credentials, useful if you are having trouble connecting. First off make sure you are including TourCMS.php
, either via autoload or explicitly.
// Common configuration parameters // Marketplace ID will be 0 for Tour Operators, non-zero for Marketplace Agents // Agents can find their Marketplace ID in the API page in TourCMS settings $marketplace_id = 0; // API key will be a string, find it in the API page in TourCMS settings $api_key = "YOUR_KEY_HERE"; // Channel ID represents the Tour Operator channel to call the API against // Tour Operators may have multiple channels, so enter the correct one here // Agents can leave this as 0 for the test $channel_id = 0; // Create a new TourCMS instance // Optionally alias the namespace use TourCMS\Utils\TourCMS as TourCMS; $tourcms = new TourCMS($marketplace_id, $api_key, "simplexml"); // Call the environment test, the results will be displayed on the screen $tourcms->test_environment($channel_id);
Response headers
TourCMS responds with some useful information in the response headers. There is a method to retrieve the last set of response headers via the PHP wrapper.
$headers = $tourcms->get_last_response_headers(); $remaining_limit = $headers["x-ratelimit-remaining"];
Set User-Agent
Set a User-Agent header. Useful when trying to determine which application or process is making API calls.
$tourcms->set_user_agent("Example Tours Website");
Set X-Request-Identifier
Set a uuid or other id to the request. Useful for tracking/logging. Should be pseudo random / unique, e.g. UUID.
$tourcms->set_request_identifier("98b41172-4db9-464e-9db8-f31ae92ffbab");
Override base URL
By default the base URL will point to TourCMS main production environment. There is a method to override this to point at another base URL, intended for testing purposes.
$tourcms->set_base_url("https://api.example.com");