Utilities
Make sure to replace [TT LAN IP]!
[TT LAN IP]
in the example code provided is what should be replaced by what the local area network (LAN) assigned address of the Table Tracker gateway. (e.g. 192.168.1.232, 10.0.1.13, 192.168.0.324)Please note that the code examples provided are only meant to provide an idea of what making a HTTP request to the API looks like.
GET /api/v1/statistics/{?target_time}
Return the order statistics for the current day.
Parameters
Name | Description | Details |
---|---|---|
target_time | The target delivery time for an order in seconds. | number, optional default: 300 |
Request
// get statistics (GET http://[TT LAN IP]:8000/api/v1/statistics)
$.ajax({
url: "http://[TT LAN IP]:8000/api/v1/statistics",
type: "GET",
data:{
"target_time":"300",
},
headers:{
"Authorization":"Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==",
"Content-Type":"application/json",
},
})
.done(function(data, textStatus, jqXHR) {
console.log("HTTP Request Succeeded: " + jqXHR.status);
console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log("HTTP Request Failed");
})
.always(function() {
/* ... */
});
import java.io.IOException;
import org.apache.http.client.fluent.*;
public class SendRequest
{
public static void main(String[] args) {
sendRequest();
}
private static void sendRequest() {
// get statistics (GET )
try {
// Create request
Content content = Request.Get("http://[TT LAN IP]:8000/api/v1/statistics?target_time=300")
// Add headers
.addHeader("Authorization", "Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==")
.addHeader("Content-Type", "application/json")
// Fetch request and return content
.execute().returnContent();
// Print content
System.out.println(content);
}
catch (IOException e) { System.out.println(e); }
}
}
// get statistics (GET http://10.0.1.2:8000/api/v1/statistics)
NSURL* URL = [NSURL URLWithString:@"http://[TT LAN IP]:8000/api/v1/statistics"];
NSDictionary* URLParams = @{
@"target_time": @"300",
};
URL = NSURLByAppendingQueryParameters(URL, URLParams);
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = @"GET";
// Headers
[request addValue:@"Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==" forHTTPHeaderField:@"Authorization"];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
// Connection
NSURLConnection* connection = [NSURLConnection connectionWithRequest:request delegate:nil];
[connection start];
/*
* Utils: Add this section before your class implementation
*/
/**
This creates a new query parameters string from the given NSDictionary. For
example, if the input is @{@"day":@"Tuesday", @"month":@"January"}, the output
string will be @"day=Tuesday&month=January".
@param queryParameters The input dictionary.
@return The created parameters string.
*/
static NSString* NSStringFromQueryParameters(NSDictionary* queryParameters)
{
NSMutableArray* parts = [NSMutableArray array];
[queryParameters enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
NSString *part = [NSString stringWithFormat: @"%@=%@",
[key stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding],
[value stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]
];
[parts addObject:part];
}];
return [parts componentsJoinedByString: @"&"];
}
/**
Creates a new URL by adding the given query parameters.
@param URL The input URL.
@param queryParameters The query parameter dictionary to add.
@return A new NSURL.
*/
static NSURL* NSURLByAppendingQueryParameters(NSURL* URL, NSDictionary* queryParameters)
{
NSString* URLString = [NSString stringWithFormat:@"%@?%@",
[URL absoluteString],
NSStringFromQueryParameters(queryParameters),
];
return [NSURL URLWithString:URLString];
}
curl -X "GET" "http://[TT LAN IP]:8000/api/v1/statistics?target_time=300" \
-H "Authorization: Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==" \
-H "Content-Type: application/json"
# Install the Python Requests library:
# `pip install requests`
import requests
def send_request():
# get statistics (GET http://[TT LAN IP]:8000/api/v1/statistics)
try:
r = requests.get(
url="http://[TT LAN IP]:8000/api/v1/statistics",
params = {
"target_time":"300",
},
headers = {
"Authorization":"Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==",
"Content-Type":"application/json",
},
)
print('Response HTTP Status Code : {status_code}'.format(status_code=r.status_code))
print('Response HTTP Response Body : {content}'.format(content=r.content))
except requests.exceptions.RequestException as e:
print('HTTP Request failed')
Response 200 (application/json)
{
"status": 200,
"averageSeconds": 1809.5,
"exceededToday": 0,
"ordersToday": 2.0,
"targetTime": 200.0,
"percentGoal": 50.0
}
GET /api/v1/register/{?http_client}
Register a callback URL to be notified when an active order is modified. This is useful when you have more than one interface modifying orders. The payload in the POST
will be a typical order summary.
Parameters
Name | Description | Details |
---|---|---|
http_client | The URL to invoke when an active order is modified. | string, required |
Request
// Register Http Client (GET http://[TT LAN IP]:8000/api/v1/register)
$.ajax({
url: "http://[TT LAN IP]:8000/api/v1/register",
type: "GET",
data:{
"http_client":"http://10.0.1.18:8989/v1/notify",
},
headers:{
"Authorization":"Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==",
"Content-Type":"application/json",
},
})
.done(function(data, textStatus, jqXHR) {
console.log("HTTP Request Succeeded: " + jqXHR.status);
console.log(data);
})
.fail(function(jqXHR, textStatus, errorThrown) {
console.log("HTTP Request Failed");
})
.always(function() {
/* ... */
});
import java.io.IOException;
import org.apache.http.client.fluent.*;
public class SendRequest
{
public static void main(String[] args) {
sendRequest();
}
private static void sendRequest() {
// Register Http Client (GET )
try {
// Create request
Content content = Request.Get("http://[TT LAN IP]:8000/api/v1/register?http_client=http://10.0.1.18:8989/v1/notify")
// Add headers
.addHeader("Authorization", "Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==")
.addHeader("Content-Type", "application/json")
// Fetch request and return content
.execute().returnContent();
// Print content
System.out.println(content);
}
catch (IOException e) { System.out.println(e); }
}
}
// Register Http Client (GET http://[TT LAN IP]:8000/api/v1/register)
NSURL* URL = [NSURL URLWithString:@"http://[TT LAN IP]:8000/api/v1/register"];
NSDictionary* URLParams = @{
@"http_client": @"http://10.0.1.18:8989/v1/notify",
};
URL = NSURLByAppendingQueryParameters(URL, URLParams);
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = @"GET";
// Headers
[request addValue:@"Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==" forHTTPHeaderField:@"Authorization"];
[request addValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
// Connection
NSURLConnection* connection = [NSURLConnection connectionWithRequest:request delegate:nil];
[connection start];
/*
* Utils: Add this section before your class implementation
*/
/**
This creates a new query parameters string from the given NSDictionary. For
example, if the input is @{@"day":@"Tuesday", @"month":@"January"}, the output
string will be @"day=Tuesday&month=January".
@param queryParameters The input dictionary.
@return The created parameters string.
*/
static NSString* NSStringFromQueryParameters(NSDictionary* queryParameters)
{
NSMutableArray* parts = [NSMutableArray array];
[queryParameters enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
NSString *part = [NSString stringWithFormat: @"%@=%@",
[key stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding],
[value stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]
];
[parts addObject:part];
}];
return [parts componentsJoinedByString: @"&"];
}
/**
Creates a new URL by adding the given query parameters.
@param URL The input URL.
@param queryParameters The query parameter dictionary to add.
@return A new NSURL.
*/
static NSURL* NSURLByAppendingQueryParameters(NSURL* URL, NSDictionary* queryParameters)
{
NSString* URLString = [NSString stringWithFormat:@"%@?%@",
[URL absoluteString],
NSStringFromQueryParameters(queryParameters),
];
return [NSURL URLWithString:URLString];
}
curl -X "GET" "http://[TT LAN IP]:8000/api/v1/register?http_client=http://10.0.1.18:8989/v1/notify" \
-H "Authorization: Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==" \
-H "Content-Type: application/json"
# Install the Python Requests library:
# `pip install requests`
import requests
def send_request():
# Register Http Client (GET http://[TT LAN IP]:8000/api/v1/register)
try:
r = requests.get(
url="http://[TT LAN IP]:8000/api/v1/register",
params = {
"http_client":"http://10.0.1.18:8989/v1/notify",
},
headers = {
"Authorization":"Basic MGE5YWViNDQtNjU0Yy00NGRjLWFhMjYtNjA5YWQzMTg2NTRkOg==",
"Content-Type":"application/json",
},
)
print('Response HTTP Status Code : {status_code}'.format(status_code=r.status_code))
print('Response HTTP Response Body : {content}'.format(content=r.content))
except requests.exceptions.RequestException as e:
print('HTTP Request failed')
Response 200 (application/json)
{
"status": 200,
"message": "Registered client at: http://10.0.1.18:8989/v1/notify"
}
Response 404 (application/json)
(If unable to reach HTTP server.)
{
"status": 404,
"message": "Client not responding at [CALLBACK_URL]"
}
Example payload sent to registered listeners
{
"elapsedTime": 9,
"uuid": "147e7ccd-c17f-45b4-b5d4-bf14e9c0e244",
"seq": 196, "created": "2015-05-05T13:40:09",
"orderType": "ON_PREMISE",
"locationName": "22",
"state": "located",
"stateStarted": "2015-05-05T13:40:18",
"type": "ORDER_MODIFIED",
"name": "66"
}
Updated less than a minute ago