From 624f801693a991aa23ce2bcc2d16f49018fec140 Mon Sep 17 00:00:00 2001
From: Arjun Kumar <manav_kumar1@yahoo.com>
Date: Sun, 8 Sep 2024 15:44:28 +0530
Subject: [PATCH] Issue #3472829 by manav: Removed debugging code.

---
 src/Controller/TodoistapiTasks.php | 37 ++++++++++++++----------------
 1 file changed, 17 insertions(+), 20 deletions(-)

diff --git a/src/Controller/TodoistapiTasks.php b/src/Controller/TodoistapiTasks.php
index 3667ace..09a77ca 100644
--- a/src/Controller/TodoistapiTasks.php
+++ b/src/Controller/TodoistapiTasks.php
@@ -55,43 +55,40 @@ class TodoistapiTasks extends ControllerBase {
       ['data' => $this->t('Task'), 'field' => 'content'],
       ['data' => $this->t('Task added date'), 'field' => 'description'],
       ['data' => $this->t('Task due date'), 'field' => 'created_at'],
+      ['data' => $this->t('Complete status'), 'field' => 'is_completed'],
 			['data' => $this->t('Action'), 'field' => 'created_at']
     ];
 
-    // $result =  [
-    //   ['number' => '1', 'alpha' => 'aaa', 'random' => '912cv21'],
-    //   ['number' => '2', 'alpha' => 'bbb', 'random' => '0kuykuh'],
-    //   ['number' => '3', 'alpha' => 'ccc', 'random' => '0kuykuh'],
-    //   ['number' => '4', 'alpha' => 'ddd', 'random' => '0kuykuh'],
-    //   ['number' => '5', 'alpha' => 'eee', 'random' => '0kuykuh'],
-    //   ['number' => '6', 'alpha' => 'fff', 'random' => '0kuykuh'],
-    // ];
+    //Prepare bearer token
+    $bearer_token = 'Bearer ' . \Drupal::config('todoist_api.settings')
+    ->get('access_token');
 
-    $options = ['headers' => ['Authorization' => 'Bearer a0dc04e0c04e0e19ac7621cd5385f5111920bf2f']];
+    //Get end-point Url
+    $end_point = \Drupal::config('todoist_api.settings')->get('api_endpoints')
+     . 'tasks';
+    $options = ['headers' => ['Authorization' => $bearer_token]];
 
-    $request = $this->httpClient->request('GET', 'https://api.todoist.com/rest/v2/tasks', $options);
+    //Fetch data
+    $request = $this->httpClient->request('GET', $end_point, $options);
+
+    //Get response data
     $response_data = json_decode($request->getBody()->getContents(), TRUE);
-    //dump($response_data);
-    //die;
 
+    //Prepare table rows
     $rows = [];
     foreach ($response_data as $row) {
       $created_date = (new \DateTime($row['created_at']))->getTimestamp();
-      //dump($row);
+
       $rows[] = ['data' => [
 				$row['content'],
 				$row['description'],
-				$created_date
-				]
+				date('j D M, Y', $created_date),
+        $row['is_completed'] ? 'Complete' : 'Uncomplete'
+        ]
 			];
     }
-		//dump($rows);
 
     // Build the table for the nice output.
-    $build = [
-      '#markup' => '<p>' . $this->t('The layout here is a themed as a table
-           that is sortable by clicking the header name.') . '</p>',
-    ];
     $build['tablesort_table'] = [
       '#theme' => 'table',
       '#header' => $header,
-- 
GitLab