diff --git a/index.php b/index.php
index 539ea25..6d23940 100644
--- a/index.php
+++ b/index.php
@@ -1,11 +1,18 @@
\nuserName: {$resource['user']['userName']}";
echo "
\nName: {$resource['user']['firstName']}";
echo "
\nLast name: {$resource['user']['lastName']}";
@@ -13,25 +20,95 @@ echo "
\nEmail: {$resource['user']['email']}";
echo "
\nEdition: {$resource['edition']['name']}";
echo "
\nOrganization: {$resource['organization']['name']}";
+function listProjects()
+{
+ $url = '/api2/v1/projects';
+ $apiResponse = apiGet($_SESSION['token'], $url);
+ if ($apiResponse['totalPages'] > 1) {
+ //TODO: Repeat request to get other pages
+ }
+ $projects = [];
+ foreach ($apiResponse['content'] as $apiProject) {
+ $projects[] = [
+ 'uid' => $apiProject['uid'],
+ 'name' => $apiProject['name'],
+ 'status' => $apiProject['status'],
+ 'dateCreated' => $apiProject['dateCreated']
+ ];
+ }
+ return $projects;
+}
+
+function getProject(string $projectUid)
+{
+ $url = '/api2/v1/projects/'.$projectUid;
+ return apiGet($_SESSION['token'], $url);
+}
+
+function listJobs(string $projectUid)
+{
+ $url = '/api2/v1/projects/'.$projectUid.'/jobs/';
+ return apiGet($_SESSION['token'], $url);
+}
+
// we can now use the access_token as much as we want to access protected resources
+function apiGet(string $access_token, string $url)
+{
+ $curl = curl_init();
+ curl_setopt_array(
+ $curl,
+ [
+ CURLOPT_URL => BASE_URL . $url,
+ CURLOPT_HTTPHEADER => ["Authorization: Bearer {$access_token}"],
+ CURLOPT_SSL_VERIFYPEER => false,
+ CURLOPT_RETURNTRANSFER => true
+ ]
+ );
+ $response = curl_exec($curl);
+ curl_close($curl);
+ return json_decode($response, true);
+}
+
+function apiJsonPost(string $access_token, string $url, array $postFields)
+{
+ $curl = curl_init();
+ curl_setopt_array($curl, [
+ CURLOPT_URL => BASE_URL . $url,
+ CURLOPT_HTTPHEADER => ["Authorization: Bearer {$access_token}", "Content-type: application/json"],
+ CURLOPT_SSL_VERIFYPEER => false,
+ CURLOPT_POST => true,
+ CURLOPT_POSTFIELDS => json_encode($postFields),
+ CURLOPT_RETURNTRANSFER => true
+ ]);
+ $response = curl_exec($curl);
+ curl_close($curl);
+ return json_decode($response, true);
+}
+
function getResource($access_token)
{
- $test_api_url = 'https://cloud.memsource.com/web/api2/v1/auth/whoAmI';
- // $test_api_url = 'https://cloud.memsource.com/web/api2/v1/projects';
- // $test_api_url = 'https://cloud.memsource.com/web/api2/v1/projects/zFbwYXoMLoa3cJ60Vvldo2?purge=true';
+ //$test_api_url = 'https://cloud.memsource.com/web/api2/v1/auth/whoAmI';
+ //$test_api_url = 'https://cloud.memsource.com/web/api2/v1/projects';
+ // $test_api_url = 'https://cloud.memsource.com/web/api2/v1/projects/dOVoecVbGYq85VwGYkJgY0';
+ // $test_api_url = 'https://cloud.memsource.com/web/api2/v2/projects/dOVoecVbGYq85VwGYkJgY0/jobs';
+ $test_api_url = 'https://cloud.memsource.com/web/api2/v1/projects/dOVoecVbGYq85VwGYkJgY0/jobs/bilingualFile';
+ $array_content = ['jobs' => [['uid' => 'tRJYN7LHPmaS8BVL3Vx8p2']]];
+ $content = json_encode($array_content);
- $header = ["Authorization: Bearer {$access_token}"];
+ $header = ["Authorization: Bearer {$access_token}", "Content-type: application/json"];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $test_api_url,
CURLOPT_HTTPHEADER => $header,
CURLOPT_SSL_VERIFYPEER => false,
+ // CURLOPT_CUSTOMREQUEST => 'DELETE', // <-- This is how to send a DELETE request
+ CURLOPT_POST => true,
+ CURLOPT_POSTFIELDS => $content,
CURLOPT_RETURNTRANSFER => true
- // CURLOPT_CUSTOMREQUEST => 'DELETE' <-- This is how to send a DELETE request
]);
$response = curl_exec($curl);
curl_close($curl);
return json_decode($response, true);
-}
+}
\ No newline at end of file