Skip to content

Commit

Permalink
add method storeUser, showUser, and updateUser
Browse files Browse the repository at this point in the history
  • Loading branch information
Kresna Satya committed Nov 23, 2022
1 parent 92a681c commit 58757dd
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,48 @@ $total_users = (new Connector())->totalUsers(array(
));
```

### Store user

```php
<?php

use RistekUSDI\RBAC\Connector\Connector;

/**
* Store user
* @param $data (user entity)
*/
(new Connector())->storeUser($data);
```

### Show user

```php
<?php

use RistekUSDI\RBAC\Connector\Connector;

/**
* Show user by username
*
* */
$user = (new Connector())->showUser($username);
```

### Update user

```php
<?php

use RistekUSDI\RBAC\Connector\Connector;

/**
* Update user by username
* @param $username, $data (user entity)
* */
$user = (new Connector())->showUser($username, $data);
```

### Assigned User to Client Role

```php
Expand Down
15 changes: 15 additions & 0 deletions src/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ public function getUsers($params = array())
return (new User($this->getHost(), $this->getAccessToken()))->get($params);
}

public function storeUser($params = array())
{
return (new User($this->getHost(), $this->getAccessToken()))->store($params);
}

public function showUser($username)
{
return (new User($this->getHost(), $this->getAccessToken()))->show($username);
}

public function updateUser($username, $params = array())
{
return (new User($this->getHost(), $this->getAccessToken()))->update($username, $params);
}

public function totalUsers($params = array())
{
return (new User($this->getHost(), $this->getAccessToken()))->total($params);
Expand Down
44 changes: 44 additions & 0 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,48 @@ public function total($params = array())

return ($response['code'] === 200) ? $response['body'] : 0;
}

public function store($params = array())
{
$url = "{$this->getHost()}/api/v1/users";

$response = curl_request($url, array(
'header' => array(
"Authorization: Bearer {$this->getAccessToken()}",
'Content-Type: application/x-www-urlencoded'
),
'body' => http_build_query($params, "", "&", PHP_QUERY_RFC3986),
), 'POST');

return ($response['code'] === 200) ? $response['body'] : 0;
}

public function show($username)
{
$url = "{$this->getHost()}/api/v1/users/{$username}";

$response = curl_request($url, array(
'header' => array(
"Authorization: Bearer {$this->getAccessToken()}",
'Content-Type: application/x-www-urlencoded'
)
));

return ($response['code'] === 200) ? $response['body'] : 0;
}

public function update($username, $params = array())
{
$url = "{$this->getHost()}/api/v1/users/{$username}";

$response = curl_request($url, array(
'header' => array(
"Authorization: Bearer {$this->getAccessToken()}",
'Content-Type: application/x-www-urlencoded'
),
'body' => http_build_query($params, "", "&", PHP_QUERY_RFC3986),
), 'PATCH');

return ($response['code'] === 200) ? $response['body'] : 0;
}
}

0 comments on commit 58757dd

Please sign in to comment.