diff --git a/do_username.services.yml b/do_username.services.yml new file mode 100644 index 0000000..a36debb --- /dev/null +++ b/do_username.services.yml @@ -0,0 +1,11 @@ +services: + do_username.http_adapter: + class: Http\Adapter\Guzzle6\Client + arguments: ['@http_client'] + do_username.do_client: + class: Hussainweb\DrupalApi\Client + arguments: ['@do_username.http_adapter'] + do_username.user_service: + class: Drupal\do_username\DrupalOrgUserInformationService + arguments: ['@do_username.do_client','@cache.data'] + \ No newline at end of file diff --git a/src/DrupalOrgUserInformationService.php b/src/DrupalOrgUserInformationService.php new file mode 100644 index 0000000..4887d2e --- /dev/null +++ b/src/DrupalOrgUserInformationService.php @@ -0,0 +1,64 @@ +client = $client; + $this->cache = $cache; + } + + /** + * Function to store user information. + */ + public function userInformation($doUsername) { + + $cid = 'do_username:user:' . $doUsername; + + // Check if the data exist. If not, retrieve, save and return. + $cachedData = $this->cache->get($cid); + if ($cachedData) { + return $cachedData->data->current(); + } + $request = new UserCollectionRequest(["name" => $doUsername]); + $userData = $this->client->getEntity($request); + $this->cache->set($cid, $userData); + return $userData->current(); + } + +}