1.0.0 • Published 4 years ago

pitchedapi v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

pitchedapi.js

Expose the Pitched API to the frontend.

Usage

Include this script before the closing body tag.

<script type="text/javascript" src="build/pitchedapi.min.js"></script>

Get Requests

This requests allow you to retrieve data from the pitched API.

// Initialize the api with your API token
pitchedapi.init('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6IlRlc3QiLCJyb2xlIjoiQWRtaW4iLCJuYmYiOjE1ODA5ODA4MjUsImV4cCI6MTU4MTA2NzIyNSwiaWF0IjoxNTgwOTgwODI1fQ.6Ue5r366_fdfvqyH6VxQYxzt83sdecmA9ueF_1cIYKY');

// Get all settings
pitchedapi.get('settings', function (result) {
    console.log(result);
});

// Get a setting by its id
pitchedapi.get('settings/id', { 'id': 1 }, function (result) {
    console.log(result);
});

// Get a get by its name
pitchedapi.request('settings/name', { 'name': 'SearchMaxPet'}, function (result) {
    console.log(result);
});

// Get multiple settings by their names
pitchedapi.get('settings/names', { 'names': ['SearchMaxAdult', 'SearchMaxPet'] }, function (result) {
    console.log(result);
});

// Get all sites
pitchedapi.get('sites', function (result) {
    console.log(result);
});

// Get site by ID
pitchedapi.get('sites/id', { 'id': 1 }, function (result) {
    console.log(result);
});

// Get unit type groups for 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 its id
pitchedapi.get('unittypegroups/id', { 'id': 3 }, function (result) {
    console.log(result);
});

// Get disabled dates for all unit type groups (used to disable dates on the widget datepicker)
pitchedapi.get('unittypegroups/disableddates', function (result) {
    console.log(result);
});

// Get disabled date for a specific unit type group (used to disabled dates on the widget datepicker)
pitchedapi.get('unittypegroups/id/disableddates', { 'id': 6 }, function (result) {
    console.log(result);
});

// Get all unit types that belong to a unit type group
pitchedapi.get('unittypegroups/id/unittypes', { 'id': 6 }, function (result) {
    console.log(result);
});

// Get all unit types
pitchedapi.get('unittypes', function (result) {
    console.log(result);
});

// Get a specific unit type by its id
pitchedapi.get('unittypes/id', { 'id': 2 }, function (result) {
    console.log(result);
});

// Get durations for widget by unit type group id and arrival date.
// unit type group id is optional.
pitchedapi.get('widget/durations', { "unit_type_group_id": 0, "arrival_date": "05/16/2020" }, function (result) {
    console.log(result);
});

// Get a new api token.
pitchedapi.get('token', { 'username': 'username', 'password': 'password' }, function (result) {
    pitchedapi.setProperty('token', result.token); // Set the new token
});

// Search availability
pitchedapi.get('availability/search', { 
    "site_id": 1,
	"unit_type_group_id": 0,
	"arrival_date": "05/16/2020", // mm/dd/yyyy
	"duration": 7,
	"adults": 2,
	"seniors": 0, // Optional
	"teenagers": 0, // Optional
	"children": 0, // Optional
	"infants": 0, // Optional
	"pets": 1
}, function (result) {
    console.log(result);
});

Events

// If any requests come back as unauthorized, handle accordingly
pitchedapi.on('unauthorized', function () {
    console.log('unauthorized');
});

Properties

Set or get properties are used within the plugin.

// Get any properties like so:
pitchedapi.getProperty('NAME');

// Set any propertied like so:
pitchedapi.setProperty('NAME', 'VALUE');

// E.g. set the token after generating a new one.
pitchedapi.setProperty('token', 'YOUR_TOKEN');
1.0.0

4 years ago