-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_asynchronous.php
127 lines (102 loc) · 4.53 KB
/
example_asynchronous.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
//dependencies and autoload
include_once( getcwd().'/autoload.php');
use Copyleaks\CopyleaksCloud;
use Copyleaks\CopyleaksProcess;
use Copyleaks\Products;
/* CREATE CONFIG INSTANCE */
$config = new \ReflectionClass('Copyleaks\Config');
$clConst = $config->getConstants();
/*
CONSTRUCT ACCEPTS 3 PARAMETER (email, api_key, type of product).
AVAILABLE PRODUCTS:
1. Businesses - Products::Businesses - https://api.copyleaks.com/businessesdocumentation
2. Education - Products::Education - https://api.copyleaks.com/academicdocumentation
3. Websites - Products::Websites - https://api.copyleaks.com/websitesdocumentation
*/
// Use the email that you used to register to Copyleaks.
// If you don't have an account yet register on https://copyleaks.com/account/register
// Your API-KEY is available at the dashboards on https://api.copyleaks.com/. Choose the dashboard of the product that you would like to use.
$email = '[email protected]';
$apiKey = 'f86560c5-2d47-4869-8a10-72e9cee401a9';
// Login to Copyleaks Cloud
try{
$clCloud = new CopyleaksCloud($email, $apiKey, Products::Businesses);
}catch(Exception $e){
echo "<Br/>Failed to connect to Copyleaks Cloud with exception: ". $e->getMessage();
die();
}
//validate login token
if(!isset($clCloud->loginToken) || !$clCloud->loginToken->validate()){
echo "<Br/><strong>Bad login credentials</strong>";
die();
}
echo "<Br/><strong>Logged in successfully</strong><Br/>";
# Get your credit balance
//$creditBalance = $clCloud->getCreditBalance(); //get credit balance
// print_r($creditBalance);
try{
// For more information about the optional headers please visit: https://api.copyleaks.com/GeneralDocumentation/RequestHeaders
$additionalHeaders = array($clConst['HTTP_CALLBACK'].': https://enp5ti346rnc.x.pipedream.net/' # For a fast testing of callbacks option we recommend to use http://requestb.in
//$clConst['IN_PROGRESS_RESULT'].': http://your.website.com/callback/results/,
//$clConst['EMAIL_CALLBACK'].': [email protected]',
//$clConst['CLIENT_CUSTOM_PREFIX'].'name: some name'
//$clConst['PARTIAL_SCAN_HEADER'],
//$clConst['COMPARE_ONLY'], # Compare files in between - available only on createByFiles
//$clConst['IMPORT_FILE_TO_DATABASE'] # Import your file to our database only
);
// Create process using one of the following option.
$process = $clCloud->createByURL("https://pdpatilall.000webhostapp.com/prasss2/index.html", $additionalHeaders);
//$process = $clCloud->createByText('<ENTER YOUR STRING HERE>',$additionalHeaders);
//$process = $clCloud->createByFile('FILE_PATH', $additionalHeaders);
//$processes = $clCloud->createByFiles(array(firstFile,
// secondFile),
// $additionalHeaders); // Array with 2 elements - the first([0]) is the successfully created processes
// the second([1]) is the error happend
//$process = $clCloud->createByOCR('IMAGE_PATH','English',$additionalHeaders);
echo "<BR/><strong>Process created!</strong> (PID = '" . $process->processId . "') - You will get notified with a callback soon";
//DELETE process example
//echo '<Br/>delete process';
//$deletedProcess = $process->delete();
//print_r($deletedProcess);
//get processes list
//$process_list = $clCloud->getProcessList();
//print_r($process_list);
//Get supported file types
//$supportedFileTypes = $clCloud->getSupportedFileTypes();
//echo "<BR/><BR/><strong>Supported File Types:</strong><BR/>";
//print_r($supportedFileTypes);
//Get OCR's(Images of text) supported languages
//$ocrSupportedLanguages = $clCloud->getSupportedOCRLanguages();
//echo "<BR/><BR/><strong>Supported OCR(Images of text only) Languages:</strong><BR/>";
//print_r($ocrSupportedLanguages);
}catch(Exception $e){
echo "<br/>Failed with exception: ". $e->getMessage();
}
//build table from PHP array
function build_table($array){
// start table
$html = '<table>';
// header row
$html .= '<tr>';
foreach($array[0] as $key=>$value){
$html .= '<th>' . $key . '</th>';
}
$html .= '</tr>';
// data rows
foreach( $array as $key=>$value){
$html .= '<tr>';
foreach($value as $key2=>$value2){
$value2 = is_array($value2) ? json_encode($value2) : $value2;
$html .= '<td>' . @$value2 . '</td>';
}
$html .= '</tr>';
}
// finish table and return it
$html .= '</table>';
return $html;
}
//print process list as HTML table
if(isset($plist,$plist['response']) && count($plist['response'])>0)
echo build_table($plist['response']);
?>