This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
/
Copy pathsample-asset.php
executable file
·82 lines (61 loc) · 2.63 KB
/
sample-asset.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
70
71
72
73
74
75
76
77
78
79
<?php
include_once('tests/UnitBootstrap.php');
use FuelSdk\ET_Client;
use FuelSdk\ET_Asset;
try {
$myclient = new ET_Client();
// Retrieve All Assets with GetMoreResults
print "Retrieve All Assets with GetMoreResults \n";
$getAsset = new ET_Asset();
$getAsset->authStub = $myclient;
$getResult = $getAsset->get();
print_r('Get Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print_r('More Results: '.($getResult->moreResults ? 'true' : 'false')."\n");
print 'Results Length(Items): '. count($getResult->results->items)."\n";
print 'Results: "\n"';
print_r($getResult->results);
print "\n---------------\n";
while ($getResult->moreResults) {
print "Continue Retrieve All Assets with GetMoreResults \n";
$getResult = $getAsset->GetMoreResults();
print_r('Get Status: '.($getResult->status ? 'true' : 'false')."\n");
print 'Code: '.$getResult->code."\n";
print 'Message: '.$getResult->message."\n";
print_r('More Results: '.($getResult->moreResults ? 'true' : 'false')."\n");
print 'Results Length(Items): '. count($getResult->results->items)."\n";
print "\n---------------\n";
}
$base64EncodedString = base64_encode("This is my file contents of a text file");
// Create a new Asset Base 64
print "Create a new Asset Base 64 \n";
$postAsset = new ET_Asset();
$postAsset->authStub = $myclient;
$postAsset->props = array("fileName" => "TestFile.txt", "mimeType" => "text/plain", "fileData" => $base64EncodedString, "displayName" => "TestFile.txt", "customerKey" => md5(uniqid()), "description" => "");
$postResponse = $postAsset->Post();
print_r('Post Status: '.($postResponse->status ? 'true' : 'false')."\n");
print 'Code: '.$postResponse->code."\n";
print 'Message: '.$postResponse->message."\n";
print 'Results Length: '. count($postResponse->results)."\n";
print 'Results: '."\n";
print_r($postResponse->results);
print "\n---------------\n";
// Create a new Asset File Path
print "Create a new Asset File Path \n";
$postAsset2 = new ET_Asset();
$postAsset2->authStub = $myclient;
$postAsset2->props = array("filePath" => $_SERVER['PWD'] . '/sample-asset-TestFilePath.txt');
$postResponse = $postAsset2->Post();
print_r('Post Status: '.($postResponse->status ? 'true' : 'false')."\n");
print 'Code: '.$postResponse->code."\n";
print 'Message: '.$postResponse->message."\n";
print 'Results Length: '. count($postResponse->results)."\n";
print 'Results: '."\n";
print_r($postResponse->results);
print "\n---------------\n";
}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>