-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolasAPI.class.php
137 lines (108 loc) · 6.16 KB
/
SolasAPI.class.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
128
129
130
131
132
133
134
135
136
137
<?php
/*
Creation Date: 21 March 2012
Author: Ian O'Keeffe
Modification History:
--------------------------
21-03-2012
This is a locConnect Solas API Class
It wraps the API calls to make component creation easier
*/
class SolasAPI {
//locConnect Solas API public functions
//***********************************************************************************************************
//Calls LocConnect to fetch a list of available jobs for a given ComponentName
public function solas_fetch_jobs($ComponentName, $locConnect){
$request = new HTTP_Request2($locConnect.'fetch_job.php',HTTP_Request2::METHOD_GET);
$request->setHeader('Accept-Charset', 'utf-8');
$url = $request->getUrl();
// set your component name here
$url->setQueryVariable('com', $ComponentName); // com = component ComponentName = LCM, MT, LKR, WFR etc... should be uppercase ASCII string (max 6 chars)
// This will get a list of pending jobs from the CNLF server and store them $jobs variable;
$response=$request->send()->getBody();
return $response;
}
//***********************************************************************************************************
//Calls LocConnect to set the status of a job via JobId and ComponentName
public function solas_set_status($ComponentName, $jobId, $status, $locConnect){
$request = new HTTP_Request2($locConnect.'set_status.php',HTTP_Request2::METHOD_GET);
$request->setHeader('Accept-Charset', 'utf-8');
$url = $request->getUrl();
// set request variables here
$url->setQueryVariable('com', $ComponentName); // com = component. ComponentName = LCM, MT, LKR, WFR etc... should be uppercase ASCII string (max 6 chars)
$url->setQueryVariable('id', $jobId); // set jobId here
$url->setQueryVariable('msg', $status); // set message to $status (processing, complete or pending)
// This will get a list of pending jobs from the CNLF server and store them $jobs variable;
$response=$request->send()->getBody();
return $response;
}
//***********************************************************************************************************
//Calls LocConnect to set the status of a job directly to 'processing' via JobId and ComponentName
public function solas_set_status_processing($ComponentName, $jobId, $locConnect){
$response = $this->solas_set_status($ComponentName, $jobId, 'processing', $locConnect); //call solas_set_status() within this class, and pass the required status
return $response;
}
//***********************************************************************************************************
//Calls LocConnect to set the status of a job directly to 'complete' via JobId and ComponentName
public function solas_set_status_complete($ComponentName, $jobId, $locConnect){
$response = $this->solas_set_status($ComponentName, $jobId, 'complete', $locConnect); //call solas_set_status() within this class, and pass the required status
return $response;
}
//***********************************************************************************************************
//Calls LocConnect to set the status of a job directly to 'pending' via JobId and ComponentName
public function solas_set_status_pending($ComponentName, $jobId, $locConnect){
$response = $this->solas_set_status($ComponentName, $jobId, 'pending', $locConnect); //call solas_set_status() within this class, and pass the required status
return $response;
}
//***********************************************************************************************************
//Calls LocConnect to request a file to be processed via JobId and ComponentName
public function solas_get_job($ComponentName, $jobId, $locConnect){
$request = new HTTP_Request2($locConnect.'get_job.php', HTTP_Request2::METHOD_GET);
$request->setHeader('Accept-Charset', 'utf-8');
$url = $request->getUrl();
// set request variables here
$url->setQueryVariable('com', $ComponentName); // com = component. ComponentName = LCM, MT, LKR, WFR etc... should be uppercase ASCII string (max 6 chars)
$url->setQueryVariable('id', $jobId); // set jobId here
// This will fetch the given job from the CNLF server and store content in $file variable;
$response=$request->send()->getBody();
return $response;
}
//***********************************************************************************************************
//Calls LocConnect to send feedback msg relating to the current JobId and ComponentName
public function solas_send_feedback($ComponentName, $jobId, $msg, $locConnect){
$request = new HTTP_Request2($locConnect.'send_feedback.php', HTTP_Request2::METHOD_GET);
$request->setHeader('Accept-Charset', 'utf-8');
$url = $request->getUrl();
// set request variables here
$url->setQueryVariable('com', $ComponentName); // com = component. ComponentName = LCM, MT, LKR, WFR etc... should be uppercase ASCII string (max 6 chars)
$url->setQueryVariable('id', $jobId); // set jobId here
$url->setQueryVariable('msg', $msg); // set message text here, not more than 250 chars
// This will fetch the given job from the CNLF server and store content in $file variable;
$response=$request->send()->getBody();
return $response;
}
//***********************************************************************************************************
//Calls LocConnect to send output data back to locConnect using current JobId and ComponentName
public function solas_send_output($ComponentName, $jobId, $data, $locConnect){
$request = new HTTP_Request2($locConnect.'send_output.php');
$request->setMethod(HTTP_Request2::METHOD_POST)
->addPostParameter('id', $jobId)
->addPostParameter('com', $ComponentName)
->addPostParameter('data', $data);
try {
$response = $request->send();
if (200 == $response->getStatus()) {
$response = $response->getBody();
} else {
$response = 'Unexpected HTTP status: '.$response->getStatus().' '.$response->getReasonPhrase();
}
} catch (HTTP_Request2_Exception $e) {
$response = 'Error: '.$e->getMessage();
}
return $response;
}
//***********************************************************************************************************
private function imPrivate() { //IOK Just for my notes
return "Hello World";
}
}