Skip to content

Commit

Permalink
added new API
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalyan H committed Oct 26, 2021
1 parent 15f2b6d commit 5193392
Show file tree
Hide file tree
Showing 10 changed files with 915 additions and 193 deletions.
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,109 @@ or using helper
IdpUser()->create(array());
```

# Create you SDK
Run this command to create your own sdk class.
```
php artisan make:idpdriver YourSDKName
```
Now add the class in config idpUser.php config file.

# API references
### Here all covered API references

>1. Get Wso2 IDP User by ID
```
IdpUser()->setPayload('userID')->userInfo()->get();
```
or to get only response body

```
IdpUser()
->use('wso2idp')
->setPayload('userID')
->userInfo()
->onlyBody()
->get();
```
Here -

-----

```use('yourSDK')``` `optional` set your custom SDK.

```onlyBody()``` `optional` return only response from IDP server/end API

----


```get()``` return response as `array`

```asObject()``` return response as `object`

```asJson()``` return response as `json`

----

>2. Create IDP user and get created user info
```
$response = IdpUser()->setPayload([
'first_name' => 'Kalyan',
'last_name' => 'Kalyan',
'username' => 'Kalyan4',
'email' => '[email protected]',
'mobile' => '01945602071',
'user_type' => '2',
'active' => true,
'department' => 'Kalyan',
])->create()->get();
```

>3. Update User By User ID
_you can provide single field or multiple field at the same time_

```
$response = IdpUser()->setPayload([
'id' =>'UserID',
'username' => 'Kalyan3',
'account_status' => 1,
'mobile' => '01945602071'
])->update()->get();
```
here `id` and `username` is mendatory. You can provide following field to update & create -

| Key | Details |
| ------ | ------ |
| first_name | Update `givenName` |
| last_name | [Update `familyName` |
| email | Update `emails` |
| mobile | Update `phoneNumbers` |
| user_type | Update `userType`|
| account_status | Update `accountStatus` |
| department | Update `department` |
| organization | Update `organization` |
| country | Update `country` |
| password | Update `password` |


>4. Delete single/bulk IDP User
```
$userID = 'ID';
$response = IdpUser()
->use('wso2idp')
->setPayload($userID)
->delete()
->get();
```
here - `$userID` can be single user ID or array of user ID.




## Adding new Gateway

## .env Config
Expand Down
4 changes: 2 additions & 2 deletions src/Console/MakeIdpDriverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MakeIdpDriverCommand extends GeneratorCommand
*/
protected function getStub()
{
return __DIR__.'/stubs/gateway.stub';
return __DIR__.'/stubs/sdk.stub';
}

/**
Expand All @@ -46,6 +46,6 @@ protected function getStub()
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Idps';
return $rootNamespace.'\SDK';
}
}
215 changes: 215 additions & 0 deletions src/Console/stubs/sdk.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
<?php

namespace DummyNamespace;

use Khbd\LaravelWso2IdentityApiUser\Interfaces\IDPInterface;
use Illuminate\Http\Request;

class DummyClass implements IDPInterface
{
/**
* @var array
*/
protected $settings;

/**
* @var string
*/
protected $user_id;
/**
* @var bool
*/
protected $is_success;

/**
* @var int
*/
protected $response_code;

/**
* @var mixed
*/
protected $message;


/**
* @var mixed
*/
protected $onlyBody;

/**
* @var object
*/
protected $asObject;

/**
* @var json
*/
protected $asJson;

/**
* @var object
*/
protected $data;

/**
* @var object | array
*/
protected $response;



/**
* @param $settings
*
* @throws \Exception
*/
public function __construct($settings)
{
$this->settings = (object) $settings;
}

public function userInfo($userID)
{
$AT = new Wso2IdpUsers($this->settings->base_url, $this->settings->username, $this->settings->password, $this->settings->idp_log );
$this->response = $AT->userInfo($userID);
return $this;
}

public function findUsers($userID)
{
$AT = new Wso2IdpUsers($this->settings->base_url, $this->settings->username, $this->settings->password, $this->settings->idp_log );
$this->response = $AT->findUsers($userID);
return $this;
}

/**
* @param $recipient
* @param $message
* @param null $params
*
* @return object
*/
public function create($userInfo)
{
$AT = new Wso2IdpUsers($this->settings->base_url, $this->settings->username, $this->settings->password, $this->settings->idp_log );
$this->response = $AT->create($userInfo);
return $this;
}


/**
* Update user
* @param array $userInformation
* @return mixed|void
*/
public function update(array $userInformation)
{
$AT = new Wso2IdpUsers($this->settings->base_url, $this->settings->username, $this->settings->password, $this->settings->idp_log );
$this->response = $AT->update($userInformation);
return $this;
}


public function delete( $userInformation = null)
{
$AT = new Wso2IdpUsers($this->settings->base_url, $this->settings->username, $this->settings->password, $this->settings->idp_log );
$this->response = $AT->delete($userInformation);
return $this;
}


/**
* set response type
* @return $this
*/
public function get()
{
if($this->onlyBody){
return $this->response['data'];
}
return $this->response;
}
/**
* set response type
* @return $this
*/
public function asObject()
{
if($this->onlyBody){
return (object) $this->response['data'];
}
return (object) $this->response;
}

/**
* set response type
* @return $this
*/
public function asJson()
{
if($this->onlyBody){
return json_encode ($this->response['data']);
}
return (object) $this->response;
}

/**
* set pertial response
* @return $this
*/
public function onlyBody()
{
$this->onlyBody = true;
return $this;
}

/**
* initialize the is_success parameter.
*
* @return bool
*/
public function isSuccessful(): bool
{
return $this->response['status'];
}

/**
* assign the message ID as received on the response,auto generate if not available.
*
* @return string
*/
public function getResponseMessage()
{
return $this->response['message'];
}

/**
* @return int
*/
public function getResponseCode()
{
return $this->response['code'];
}

/**
* @return mixed|string
*/
public function getUserID()
{
return $this->user_id;
}

public function fixNumber($number){
$validCheckPattern = "/^(?:\+88|01)?(?:\d{11}|\d{13})$/";
if(preg_match($validCheckPattern, $number)){
if(preg_match('/^(?:01)\d+$/', $number)){
$number = '+88' . $number;
}

return $number;
}

return false;
}
}
9 changes: 3 additions & 6 deletions src/Facades/IdpUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
namespace Khbd\LaravelWso2IdentityApiUser\Facades;

use Illuminate\Support\Facades\Facade;
use phpDocumentor\Reflection\Types\Mixed_;

/**
* @method static gateway(string $gateway)
* @method static send(string $recipient, string $message, $params = null)
* @method static bool is_successful()
* @method static getMessageID()
* @method static getBalance()
* @method static object getDeliveryReports(\Illuminate\Http\Request $request)
* @method static use(string $sdk)
* @method static setPayload($payload)
*
* @see \Khbd\LaravelWso2IdentityApiUser\IdpUser
*/
Expand Down
Loading

0 comments on commit 5193392

Please sign in to comment.