-
Notifications
You must be signed in to change notification settings - Fork 1
/
GetAllTargets.php
executable file
·69 lines (47 loc) · 1.99 KB
/
GetAllTargets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
require_once 'HTTP/Request2.php';
require_once 'SignatureBuilder.php';
// See the Vuforia Web Services Developer API Specification - https://developer.vuforia.com/resources/dev-guide/retrieving-target-cloud-database
// The GetAllTargets sample demonstrates how to query a single target by target id.
class GetAllTargets{
//Server Keys
private $access_key = "cd6b724d3b520cc072ddfb826e6cf7ea62835179";
private $secret_key = "3d2387ec9d4fcbfdd8a565f9f002fc5427bd9efc";
private $url = "https://vws.vuforia.com";
private $requestPath = "/targets";// . $targetId;
private $request;
function GetAllTargets(){
$this->requestPath = $this->requestPath;
$this->execGetAllTargets();
}
private function execGetAllTargets(){
$this->request = new HTTP_Request2();
$this->request->setMethod( HTTP_Request2::METHOD_GET );
$this->request->setConfig(array(
'ssl_verify_peer' => false
));
$this->request->setURL( $this->url . $this->requestPath );
// Define the Date and Authentication headers
$this->setHeaders();
try {
$response = $this->request->send();
if (200 == $response->getStatus()) {
echo $response->getBody();
} else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase(). ' ' . $response->getBody();
}
} catch (HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
}
private function setHeaders(){
$sb = new SignatureBuilder();
$date = new DateTime("now", new DateTimeZone("GMT"));
// Define the Date field using the proper GMT format
$this->request->setHeader('Date', $date->format("D, d M Y H:i:s") . " GMT" );
// Generate the Auth field value by concatenating the public server access key w/ the private query signature for this request
$this->request->setHeader("Authorization" , "VWS " . $this->access_key . ":" . $sb->tmsSignature( $this->request , $this->secret_key ));
}
}
?>