Refactor profileIndicator to use CCApi

Fixed: twpowertools:48
Change-Id: I9b91392e4cf06f7025941ed15f125159a9251169
diff --git a/src/injections/profileIndicator.js b/src/injections/profileIndicator.js
index ee897fe..b0c1170 100644
--- a/src/injections/profileIndicator.js
+++ b/src/injections/profileIndicator.js
@@ -1,11 +1,10 @@
+import {CCApi} from '../common/api.js';
 import {escapeUsername} from '../common/communityConsoleUtils.js';
 
 var CCProfileRegex =
     /^(?:https:\/\/support\.google\.com)?\/s\/community(?:\/forum\/[0-9]*)?\/user\/(?:[0-9]+)$/;
 var CCRegex = /^https:\/\/support\.google\.com\/s\/community/;
 
-const BASE_URL = 'https://support.google.com/s/community/api/';
-
 const OP_FIRST_POST = 0;
 const OP_OTHER_POSTS_READ = 1;
 const OP_OTHER_POSTS_UNREAD = 2;
@@ -41,45 +40,35 @@
   return false;
 }
 
-function APIRequest(action, body) {
-  var authuserPart =
-      (authuser == '0' ? '' : '?authuser=' + encodeURIComponent(authuser));
-
-  return fetch(BASE_URL + action + authuserPart, {
-           'credentials': 'include',
-           'headers': {'content-type': 'text/plain; charset=utf-8'},
-           'body': JSON.stringify(body),
-           'method': 'POST',
-           'mode': 'cors',
-         })
-      .then(res => res.json());
-}
-
 function getPosts(query, forumId) {
-  return APIRequest('ViewForum', {
-    '1': forumId,
-    '2': {
-      '1': {
-        '2': 5,
+  return CCApi(
+      'ViewForum', {
+        '1': forumId,
+        '2': {
+          '1': {
+            '2': 5,
+          },
+          '2': {
+            '1': 1,
+            '2': true,
+          },
+          '12': query,
+        },
       },
-      '2': {
-        '1': 1,
-        '2': true,
-      },
-      '12': query,
-    },
-  });
+      /* authenticated = */ true, authuser);
 }
 
 function getProfile(userId, forumId) {
-  return APIRequest('ViewUser', {
-    '1': userId,
-    '2': 0,
-    '3': forumId,
-    '4': {
-      '20': true,
-    },
-  });
+  return CCApi(
+      'ViewUser', {
+        '1': userId,
+        '2': 0,
+        '3': forumId,
+        '4': {
+          '20': true,
+        },
+      },
+      /* authenticated = */ true, authuser);
 }
 
 // Source: