1.0.23 • Published 6 years ago
pitched-api v1.0.23
pitched-api.js
Expose the Pitched API to the frontend.
Usage
Include this script before the closing body tag.
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/pitched-api/dist/pitched-api.min.js"></script>Or, if using npm
npm install pitched-apiInitialize the pitched api with your token
var pitchedapi = new PitchedApi('YOUR API TOKEN');Get Requests
This requests allow you to retrieve data from the Pitched API.
// Get all sites
pitchedapi.get('sites', function (result) {
console.log(result);
});
// Get a site by its id
pitchedapi.get('sites/id', { id: 1 }, function (result) {
console.log(result);
});
// Get all unit type groups that belong to a specific site
pitchedapi.get('sites/id/unittypegroups', { id: 1 }, function (result) {
console.log(result);
});
// Get all unit type groups
pitchedapi.get('unittypegroups', function (result) {
console.log(result);
});
// Get a unit type group by id
pitchedapi.get('unittypegroups/id', { id: 3 }, function (result) {
console.log(result);
});
// Get disabled dates for all unit type groups
pitchedapi.get('unittypegroups/disableddates', function (result) {
console.log(result);
});
// Get all unit types that belong to a specific unit type group
pitchedapi.get('unittypegroups/id/unittypes', { id: 6 }, function (result) {
console.log(result);
});
// Get disabled dates for a specific unit type group
pitchedapi.get('unittypegroups/id/disableddates', { id: 6 }, function (result) {
console.log(result);
});
// Get all unit types
pitchedapi.get('unittypes', function (result) {
console.log(result);
});
// Get a unit type by id
pitchedapi.get('unittypes/id', { id: 2 }, function (result) {
console.log(result);
});
// Get durations to populate widget. Arrival date is formatted as dd/mm/yyyy
pitchedapi.get('widget/durations', { "unit_type_group_id": 0, "arrival_date": "16/05/2020", }, function (result) {
console.log(result);
});
// Get widget config
pitchedapi.get('widget/config', function (result) {
console.log(result);
});
// Search availability
pitchedapi.get('availability/search', {
"site_id": 1,
"unit_type_group_id": 0, // 0 to search all groups
"arrival_date": "16/05/2020", // dd/mm/yyyy
"duration": 7,
"adults": 2,
"teenagers": 0, // Optional
"children": 0, // Optional
"infants": 0, // Optional
"pets": 1 // Optional
}, function (result) {
console.log(result);
});
// Get a new API token as an user role
pitchedapi.get('authenticate/user', { identity: "PITCHED_IDENTITY", username: "YOUR USERNAME", password: "YOUR PASSWORD" }, function (result) {
console.log(result);
});Events
Attach event listeners to handle any errors or unauthorized api requests .
// If any api requests come back as unauthorized, handle accordingly. You may want to generate a new JWT token using the authenticate method.
pitchedapi.on('unauthorized', function () {
// Do stuff...
});
// If any api requests come back with an error, handle accordingly
pitchedapi.on('error', function () {
// Do stuff...
});Setters
Set properties are used within the pitched api library.
// E.g. Update your api token.
pitchedapi.setToken('YOUR API TOKEN');Re-authenticate example
An example of how you could handle any unauthorized requests by generating a new API token
// If any requests come back as unauthorized we can handle it in this function...
pitchedapi.on('unauthorized', function () {
// Now we know we are unauthorized, so
// make a request to re-authenticate
// and get a new API token.
pitchedapi.get('authenticate/public', { identity: "YOUR_PITCHED_IDENTITY" }, function (result) {
// If you were succesfully authenticated
if (result.success) {
// Set the new token, any future
// requests should be authorized successfully.
pitchedapi.setToken(result.token);
}
});
});1.0.23
6 years ago
1.0.22
6 years ago
1.0.21
6 years ago
1.0.20
6 years ago
1.0.19
6 years ago
1.0.18
6 years ago
1.0.17
6 years ago
1.0.16
6 years ago
1.0.15
6 years ago
1.0.14
6 years ago
1.0.13
6 years ago
1.0.12
6 years ago
1.0.11
6 years ago
1.0.9
6 years ago
1.0.10
6 years ago
1.0.8
6 years ago
1.0.7
6 years ago
1.0.6
6 years ago
1.0.5
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.0
6 years ago