Allmyles PHP SDK¶
Summary¶
The Allmyles PHP SDK is a PHP package aiming to simplify integration of the Allmyles API into PHP projects. The SDK is designed to be as forgiving as possible, often accepting multiple types as input, handling conversion between different (at least somewhat sensible) types automatically.
You can find the project’s source on GitHub.
Installation¶
Just add this in your composer.json file and run composer install
:
"require": {"allmyles/allmyles-sdk-php": "1.*"}
Or, if for some reason you can’t use a package manager, you can also just download the SDK’s source in a ZIP archive from GitHub and handle your dependencies manually. You really shouldn’t be doing that, though.
Example Code¶
The allmyles-sdk-php repository contains several examples in /doc/examples/. You might want to try those to get a general feel for how the SDK and the ticketing process work in general before you delve into the details down below.
There’s code for three different ways to use the API—these are completely intercompatible, though. We recommend you to read through the simple booking flow first, as that contains everything you need to successfully create a ticket. The complex flow is kind of a showcase for all the advanced ways you can use the API, you will most likely not need everything from there. (It might be a good idea to start reading the API Reference once you’re about to start experimenting with these advanced features.)
The raw examples take a lot of responsibility off the shoulders of the SDK; the requests are written more or less manually in those. This should be used by advanced users who don’t feel comfortable deferring the task of crafting the requests to the SDK, and would rather build arrays themselves instead of using the SDK’s query classes. Raw requests might also come in handy if the Allmyles API has new features deployed that aren’t supported by the SDK just yet.
Initialization¶
Initialization is done by creating an Allmyles\Client
object
with the API access details given as arguments. Each request will be made via a
method call to this object.
Initialization will look something like this:
$allmyles = new Allmyles\Client('https://api.allmyles.com/v2.0', 'api-key');
API Reference¶
-
class
Allmyles\
Client
¶ -
__construct
($baseUrl, $authKey)¶ Initializes your Allmyles client.
Parameters: - $baseUrl (string) – The URL of the Allmyles API you’re using
(ex.
https://api.allmyles.com/v2.0)
. - $authKey (string) – Your API key for the Allmyles API.
Returns: A
Client
object.- $baseUrl (string) – The URL of the Allmyles API you’re using
(ex.
-
searchFlight
($parameters[, $async = true, $session = null])¶ Sends a flight search request to the Allmyles API.
Parameters: - $parameters (mixed) – This should be either a
Flights\SearchQuery
object, or an associative array containing the raw data to be sent off based on the Search API docs. - $async (boolean) – Whether the SDK should defer asyncronosity to your code or not. Setting this to false will make the method call block until a search response arrives (which can take around 30-40 seconds.) If it’s true you will need to periodically call the response’s retry method yourself until the results arrive.
- $session (string) – If you want to manually set the session cookie for the workflow, specify it here. The SDK automatically handles sessions, though, so feel free to leave this out.
Returns: A
Curl\Response
object. CallingCurl\Response::get()
on this returns an array ofFlights\FlightResult
objects.- $parameters (mixed) – This should be either a
-
searchHotel
($parameters[, $session = null])¶ Sends a hotel search request to the Allmyles API.
Parameters: - $parameters (mixed) – This should be either a
Hotels\SearchQuery
object, or an associative array containing the raw data to be sent off based on the Search API docs. - $session (string) – If you want to manually set the session cookie for the workflow, specify it here. The SDK automatically handles sessions, though, so feel free to leave this out.
Returns: A
Curl\Response
object. CallingCurl\Response::get()
on this returns an array ofHotels\Hotel
objects.- $parameters (mixed) – This should be either a
-
searchCar
($parameters[, $session = null])¶ Sends a car search request to the Allmyles API.
Parameters: - $parameters (mixed) – This should be either a
Cars\SearchQuery
object, or an associative array containing the raw data to be sent off based on the Search API docs. - $session (string) – If you want to manually set the session cookie for the workflow, specify it here. The SDK automatically handles sessions, though, so feel free to leave this out.
Returns: A
Curl\Response
object. CallingCurl\Response::get()
on this returns an array ofCars\Car
objects.- $parameters (mixed) – This should be either a
-
searchLocations
($parameters[, $session = null])¶ Sends a masterdata search request to the Allmyles API.
Parameters: - $parameters (array) – This should be an associative array containing the raw data to be sent off based on the Search API docs.
- $session (string) –
Returns: An associative array containing the location search results.
-
retrieveMasterdata
($repo[, $session = null])¶ Sends a masterdata retrieval request to the Allmyles API.
Parameters: - $repo (string) – This should be the name of one of the data repos served by Allmyles (ex. ‘airports’).
- $session (string) –
Returns: A
Curl\Response
object. CallingCurl\Response::get()
on this returns an array.
Warning
The methods below are only documented for the sake of completeness. Only use them if you really, really need to. The methods of the
Flights\Combination
class handle using all these automatically.-
getFlightDetails
($bookingId[, $session = null])¶ Gets the details of the given booking ID from the Allmyles API. In almost all cases, this should not be directly called, use
Flights\Combination::getDetails()
instead.Parameters: - $bookingId (string) –
- $session (string) –
Returns: A
Curl\Response
object.
-
bookFlight
($parameters[, $session = null])¶ Sends a book request to the Allmyles API. In almost all cases, this should not be directly called, use
Flights\Combination::book()
instead.Parameters: - $parameters (array) –
- $session (string) –
Returns: A
Curl\Response
object.
-
addPayuPayment
($parmaeters[, $session = null])¶ Sends a PayU transaction ID to the Allmyles API to confirm that payment was successful. In almost all cases, this should not be directly called, use
Flights\Combination::addPayuPayment()
instead.Parameters: - $parameters (array) – Contains ‘payuId’ and ‘basket’
- $session (string) –
Returns: A
Curl\Response
object.
-
createFlightTicket
($bookingId[, $session = null])¶ Gets a ticket for the given booking ID from the Allmyles API. In almost all cases, this should not be directly called, use
Flights\Combination::createTicket()
instead.Parameters: - $bookingId (string) –
- $session (string) –
Returns: A
Curl\Response
object.
-
getHotelDetails
($hotel)¶ Gets the details of the given hotel from the Allmyles API. In almost all cases, this should not be directly called, use
Hotels\Hotel::getDetails()
instead.Parameters: - $hotel (object) – This should be a
Hotels\Hotel
object
Returns: A
Curl\Response
object.- $hotel (object) – This should be a
-
getHotelRoomDetails
($room)¶ Gets the details of the given room from the Allmyles API. In almost all cases, this should not be directly called, use
Hotels\Room::getDetails()
instead.Parameters: - $room (object) – This should be a
Hotels\Room
object
Returns: A
Curl\Response
object.- $room (object) – This should be a
-
bookHotel
($parameters[, $session = null])¶ Sends a book request to the Allmyles API. In almost all cases, this should not be directly called, use
Hotels\Room::book()
instead.Parameters: - $parameters (array) –
- $session (string) –
Returns: A
Curl\Response
object.
-
getCarDetails
($bookingId[, $session = null])¶ Gets the details of the given car from the Allmyles API. In almost all cases, this should not be directly called, use
Cars\Car::getDetails()
instead.Parameters: - $bookingId (object) – A string, one of the vehicle_id values for the search results.
Returns: A
Curl\Response
object.
-
bookCar
($parameters[, $session = null])¶ Sends a book request to the Allmyles API. In almost all cases, this should not be directly called, use
Cars\Car::book()
instead.Parameters: - $parameters (array) –
- $session (string) –
Returns: A
Curl\Response
object.
-
-
class
Allmyles\Curl\
Response
¶ A response from the Allmyles API. Methods that are for internal use only are excluded from this documentation (such as
__construct()
.)-
get
()¶ Processes the received response, and returns the processed result.
Returns: Varies per call, check the notes next to the return values in this documentation to find out what get()
will return.
-
retry
()¶ Retries the request that resulted in this response. This comes in handy when making async calls.
Returns: A new Curl\Response
object.
-
-
class
Allmyles\Flights\
SearchQuery
¶ This is the object you can pass to a
Allmyles\Client::searchFlight()
call to simplify searching.-
__construct
($fromLocation, $toLocation, $departureDate[, $returnDate = null])¶ Starts building a search query. Searches for a one way flight if no
$returnDate
is given.Parameters: - $fromLocation (string) – A location’s three letter IATA code.
- $toLocation (string) – A location’s three letter IATA code.
- $departureDate (mixed) – Either an ISO formatted timestamp, or a
DateTime
object. - $returnDate (mixed) – Either an ISO formatted timestamp, or a
DateTime
object.
Returns: A
SearchQuery
object.
-
addPassengers
($adt[, $chd = 0, $inf = 0])¶ Adds the number of passengers to your search query. This is required for your search request to go through.
Parameters: - $adt (integer) – The number of adults wanting to travel.
- $chd (integer) – The number of children wanting to travel.
- $inf (integer) – The number of infants wanting to travel.
-
addProviderFilter
($providerType)¶ Adds a filter to your query that restricts the search to a specific provider.
Parameters: - $providerType (string) – The provider to filter to. Use the following contants:
-
constant
PROVIDER_ALL
¶
All providers
-
constant
PROVIDER_TRADITIONAL
¶
Traditional flights only
-
constant
PROVIDER_LOWCOST
¶
LCC flights only
-
addAirlineFilter
($airlines)¶ Adds a filter to your query that restricts the search to specific airlines.
Parameters: - $providerType (mixed) – Either a two letter IATA airline code as a string, or an array of multiple such strings.
-
-
class
Allmyles\Flights\
FlightResult
¶ -
property
combinations
¶ An associative array of booking ID to
Combination
key-value pairs.Contains the combinations the passenger can choose from in this result.
-
property
breakdown
¶ An associative array.
Contains a breakdown of fares per passenger type. See Breakdown.
-
property
totalFare
¶ A
Common\Price
object.Contains the fare total to the best of our knowledge at this point.
-
property
-
class
Allmyles\Flights\
Combination
¶ This is the bookable entity, and these methods are where most of the magic happens.
-
property
flightResult
¶ A
FlightResult
object.Contains the parent flight result.
-
property
bookingId
¶ A string.
Contains the booking ID associated with this combination.
-
property
providerType
¶ A string.
Contains the provider that returned this result.
-
property
serviceFee
¶ A
Common\Price
object.Contains the service fee for this combination.
-
getDetails
()¶ Sends the flight details request for this flight.
Returns: A Curl\Response
object. CallingCurl\Response::get()
on this returns an associative array with the response from the Allmyles API in it. See Details.
-
book
($parameters)¶ Sends the book request for this flight.
Parameters: Returns: Either
true
when booking LCC, or aCurl\Response
object for traditional flights. CallingCurl\Response::get()
on this returns an associative array with the response from the Allmyles API in it. See Booking.
-
addPayuPayment
($payuId)¶ Sends the PayU transaction ID to confirm that payment for the ticket has been completed for this flight.
Parameters: - $payuId (string) – The PayU transaction ID to confirm payment with.
Returns: true
-
property
-
class
Allmyles\Flights\
Leg
¶ -
property
combination
¶ A
Combination
object.Contains the parent combination.
-
property
length
¶ A
DateInterval
objectContains the length of the leg in hours and minutes.
-
property
-
class
Allmyles\Flights\
Segment
¶ -
-
property
airline
¶ A string.
Contains the two character IATA code of the affiliated airline.
-
property
flightNumber
¶ A string.
Contains the flight’s number.
-
property
availableSeats
¶ An integer.
Contains the number of seats left at this price.
-
property
cabin
¶ A string.
Contains which cabin the passenger will get a ticket to on this segment.
-
property
-
class
Allmyles\Flights\
Stop
¶ -
-
property
time
¶ A
DateTime
objectContains the time of the arrival or departure.
-
property
airport
¶ A string.
Contains the three letter IATA code of the airport where the arrival or departure is going to take place.
-
property
terminal
¶ A string, or
null
.Contains the terminal of the airport where the arrival or departure is going to take place, or
null
if the airport only has one terminal.
-
property
-
class
Allmyles\Flights\
BookQuery
¶ This is the object you can pass to a
Flights\Combination::book()
call to simplify booking.-
__construct
([$passengers = null, $contactInfo = null, $billingInfo = null])¶ Starts building a book query.
Parameters: Returns: A
BookQuery
object.
-
addPassengers
($passengers)¶ Adds passengers to your book query.
Parameters: - $passengers (array) – Either an associative array containing data based on Passenger in the API docs, or an array of multiple such arrays.
-
-
class
Allmyles\Hotels\
SearchQuery
¶ This is the object you can pass to a
Allmyles\Client::searchHotel()
call to simplify searching.-
__construct
($location, $arrivalDate, $leaveDate[, $occupants = 1])¶ Starts building a search query.
Parameters: - $location (string) – A location’s three letter IATA code.
- $arrivalDate (mixed) – Either an ISO formatted date (ex. 2014-12-24),
or a
DateTime
object. - $leaveDate (mixed) – Either an ISO formatted date (ex. 2014-12-24),
or a
DateTime
object. - $occupants (integer) – The number of occupants looking for a hotel.
Returns: A
SearchQuery
object.
-
-
class
Allmyles\Hotels\
BookQuery
¶ This is the object you can pass to a
Flights\Combination::book()
call to simplify booking.-
__construct
([$occupants = null, $contactInfo = null, $billingInfo = null])¶ Starts building a book query.
Parameters: Returns: A
BookQuery
object.
-
addOccupants
($occupants)¶ Adds occupants to your book query.
Parameters: - $occupants (array) – Either an associative array containing data based on Passenger in the API docs, or an array of multiple such arrays.
-
-
class
Allmyles\Hotels\
Hotel
¶ This contains data about entire hotels.
-
property
hotelId
¶ A string.
-
property
hotelName
¶ A string.
-
property
chainName
¶ A string.
-
property
thumbnailUrl
¶ A string.
Contains a link to a small image representing this hotel.
-
property
stars
¶ An integer.
Contains the amount of stars this hotel has been awarded.
-
property
priceRange
¶ A
Common\PriceRange
object.- Contains the available rates for this hotel (for the cheapest and the most
- expensive room).
-
property
location
¶ A
Common\Location
object.Contains the coordinates of the hotel.
-
property
amenities
¶ An associative array, maps strings to booleans.
Contains whether the hotel has any of the listed amenities.
- restaurant
- bar
- laundry
- room_service
- safe_deposit_box
- parking
- swimming
- internet
- gym
- air_conditioning
- business_center
- meeting_rooms
- spa
- pets_allowed
-
property
-
class
Allmyles\Hotels\
Room
¶ This contains data about a room in a hotel.
-
property
hotelId
¶ A string.
-
property
bookingId
¶ A string.
-
property
price
¶ A
Common\Price
object.Contains the total price for this room. Make sure to take the values of the two attributes below into consideration when working with this value.
-
property
priceVaries
¶ A boolean.
- If this is true, then the hotel has a different rate for at least one of
- the nights. The given price is the rate of the most expensive day.
-
property
priceScope
¶ A string.
Either ‘day’, or ‘trip’. The given price covers this scope.
-
property
stars
¶ An integer.
Contains the amount of stars this hotel has been awarded.
-
property
traits
¶ An associative array.
Contains the traits of the given room, including the category, bed/shower availability, whether smoking is allowed, and whether it is a suite.
-
property
bed
¶ A string.
Specifies the type of the bed in the room. Can be one of the values below.
- single
- double
- twin
- king size
- queen size
- pullout
- water bed
-
property
description
¶ A string.
Contains a short text about the room.
-
property
rules
¶ An associative array.
Contains each rule type listed below with the relevant text, or a relevant boolean value.
Keys: ‘cancellation’, ‘notes’, ‘needs_guarantee’, ‘needs_deposit’
Available only after
Room::getDetails()
has been called.
-
property
charge
¶ A
Common\Price
object.Contains the amount that needs to be charged on the guest’s credit card to book this room.
Available only after
Room::getDetails()
has been called.
-
property
includes
¶ An array of strings.
Contains what services or extras are included in the price.
Available only after
Room::getDetails()
has been called.
-
property
quantity
¶ An integer.
Contains the amount left to be booked of this room.
-
getDetails
()¶ Sends the hotel room details request for this room and updates the object with new attributes.
Returns: The currently used Allmyles\Hotels\Room
object.
-
addPayuPayment
($payuId)¶ Sends the PayU transaction ID to confirm that payment for the room has been completed.
Does not need to be called if the required charge was zero
Parameters: - $payuId (string) – The PayU transaction ID to confirm payment with.
Returns: true
-
property
-
class
Allmyles\Cars\
SearchQuery
¶ This is the object you can pass to a
Allmyles\Client::searchCar()
call to simplify searching.-
__construct
($location, $startDate, $endDate)¶ Starts building a search query.
Parameters: - $location (string) – An airport’s three letter IATA code.
- $startDate (mixed) – Either an ISO formatted date (ex. 2014-12-24),
or a
DateTime
object. - $endDate (mixed) – Either an ISO formatted date (ex. 2014-12-24),
or a
DateTime
object.
Returns: A
SearchQuery
object.
-
-
class
Allmyles\Cars\
BookQuery
¶ This is the object you can pass to a
Cars\Car::book()
call to simplify booking.-
__construct
([$persons = null, $contactInfo = null, $billingInfo = null])¶ Starts building a book query.
Parameters: Returns: A
BookQuery
object.
-
addPersons
($persons)¶ Adds people to your book query.
Parameters: - $persons (array) – Either an associative array containing data based on Person in the API docs, or an array of multiple such arrays.
-
-
class
Allmyles\Cars\
Car
¶ This contains data about cars. See explanation of field values in the API docs, in the Car chapter’s Search section.
-
property
vehicleId
¶ A string.
-
property
price
¶ A
Common\Price
object.
-
property
vendor
¶ A
Cars\Vendor
object.
-
property
isAvailable
¶ A boolean value.
-
property
isUnlimited
¶ A boolean value.
-
property
overageFee
¶ An associative array.
Keys are ‘includedDistance’ as an integer, ‘unit’ as a string, and ‘price’ as a
Common\Price
object.
-
property
traits
¶ An associative array.
-
getDetails
($parameters)¶ Sends the car details request for this hotel.
Returns: A Curl\Response
object. CallingCurl\Response::get()
on this returns an associative array with the response from the Allmyles API (see Details.)
-
property
-
class
Allmyles\Cars\
Vendor
¶ This contains data about a vendor.
-
property
id
¶ A string.
This is what Allmyles identifies the vendor by internally.
-
property
name
¶ A string.
-
property
code
¶ A string.
-
searchCars
()¶ Sends a search request that will return more results from this vendor.
Returns: A Curl\Response
object. CallingCurl\Response::get()
on this returns a new array ofCars\Car
objects.
-
property
-
class
Allmyles\Common\
Price
¶ -
property
amount
¶ A floating point number.
Contains the amount of money in the given currency that the price entails.
-
property
currency
¶ A string.
Contains the currency that the amount is in.
-
property
-
class
Allmyles\Common\
PriceRange
¶ -
property
minimum
¶ A floating point number.
- Contains the minimum amount of money in the given currency that the price
- range entails.
-
property
maximum
¶ A floating point number.
- Contains the maximum amount of money in the given currency that the price
- range entails.
-
property
currency
¶ A string.
Contains the currency that the amounts are in.
-
property