From 60c5e49eb39553cba8652fc8f4955d7b7206d409 Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Sat, 22 Jun 2019 19:05:42 -0300 Subject: [PATCH 1/2] Removing old files that were used just for test --- config.ini.TEMPLATE | 12 ----- index.php | 117 -------------------------------------------- oauth.php | 66 ------------------------- 3 files changed, 195 deletions(-) delete mode 100644 config.ini.TEMPLATE delete mode 100644 index.php delete mode 100644 oauth.php diff --git a/config.ini.TEMPLATE b/config.ini.TEMPLATE deleted file mode 100644 index a52f07d..0000000 --- a/config.ini.TEMPLATE +++ /dev/null @@ -1,12 +0,0 @@ - -; \ No newline at end of file diff --git a/index.php b/index.php deleted file mode 100644 index dfb3fed..0000000 --- a/index.php +++ /dev/null @@ -1,117 +0,0 @@ - 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); -} - -function downloadBilingualFiles(string $projectUid, array $jobsUid, string $filename) -{ - $url = '/api2/v1/projects/'.$projectUid.'/jobs/bilingualFile?format=MXLF'; - foreach ($jobsUid as $key => $jobUid) { - $postFields[] = ['uid' => $jobUid]; - } - return apiDownloadFile($_SESSION['token'], $url, ['jobs' => $postFields], $filename); -} - -// 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, array $extraHeader = []) -{ - $header = array_merge( - ["Authorization: Bearer {$access_token}", 'Content-type: application/json'], - $extraHeader - ); - $curl = curl_init(); - curl_setopt_array( - $curl, - [ - CURLOPT_URL => BASE_URL . $url, - CURLOPT_HTTPHEADER => $header, - 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 apiDownloadFile($access_token, string $url, array $postFields, string $filename) -{ - $file = fopen($filename, 'w+'); - $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_TIMEOUT => 500, - CURLOPT_FILE => $file, - CURLOPT_FOLLOWLOCATION => true, - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => json_encode($postFields) - ]); - $response = curl_exec($curl); - curl_close($curl); - return $response; -} \ No newline at end of file diff --git a/oauth.php b/oauth.php deleted file mode 100644 index a2f015f..0000000 --- a/oauth.php +++ /dev/null @@ -1,66 +0,0 @@ -here, copy the code, and paste it into the box below.

"; -} - -// step I, J - turn the authorization code into an access token, etc. -function getAccessToken($authorization_code) -{ - global $token_url, $client_id, $client_secret, $callback_uri; - - $authorization = base64_encode("$client_id:$client_secret"); - $header = ["Authorization: Basic {$authorization}", 'Content-Type: application/x-www-form-urlencoded']; - $content = "grant_type=authorization_code&code=$authorization_code&redirect_uri=$callback_uri"; - - $curl = curl_init(); - curl_setopt_array($curl, [ - CURLOPT_URL => $token_url, - CURLOPT_HTTPHEADER => $header, - CURLOPT_SSL_VERIFYPEER => false, - CURLOPT_RETURNTRANSFER => true, - CURLOPT_POST => true, - CURLOPT_POSTFIELDS => $content - ]); - $response = curl_exec($curl); - $objectResponse = json_decode($response); - curl_close($curl); - - if ($response === false) { - echo 'Failed', curl_error($curl); - } elseif (isset($objectResponse->error)) { - echo "Error:
$authorization_code $response"; - } - return $objectResponse->access_token; -} From 7d21979193e56a3a5ed1a5096a6bca5a43510e60 Mon Sep 17 00:00:00 2001 From: Bruno Fontes Date: Sat, 22 Jun 2019 19:12:55 -0300 Subject: [PATCH 2/2] README.md: adding info about List Project --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 7bfbfeb..8e40e51 100644 --- a/README.md +++ b/README.md @@ -35,5 +35,22 @@ $token = $memsource->oauth()->getAccessToken($authCode, $client_id, $client_secr Safely store this `$token` with the related user data and use it on any +## Project + +### Project list + +To list all projects... + +```php +$memsource = new \BrunoFontes\Memsource(); +$projectList = $memsource->project()->listProjects; +``` + +To use filters, add the API filter as parĂ¢meter: + +```php +$projectList = $memsource->project()->listProjects(['name' => 'Project X']); +``` + ## Bilingual Files