Skip to content

Commit

Permalink
Merge pull request #23 from outfree/main
Browse files Browse the repository at this point in the history
Make sortBy and sortOrder params to main concern
  • Loading branch information
aemaddin authored Jun 30, 2023
2 parents 2adc4ca + 6ef0c97 commit 14834ce
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
21 changes: 21 additions & 0 deletions config/zoho.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@
*/
'client_id' => env('ZOHO_CLIENT_ID', null),


/*
|--------------------------------------------------------------------------
| Accounts url
|--------------------------------------------------------------------------
|
| Zoho's Accounts url for OAuth process
|
*/
'accounts_url' => env('ZOHO_ACCOUNTS_URL', "https://accounts.zoho.com"),

/*
|--------------------------------------------------------------------------
| Api's Url
|--------------------------------------------------------------------------
|
| Zoho's Apis url
|
*/
'api_base_url' => env('ZOHO_API_BASE_URL', "www.zohoapis.com"),

/*
|--------------------------------------------------------------------------
| Client Secret
Expand Down
7 changes: 5 additions & 2 deletions src/Commands/ZohoAuthentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ public function __construct()
public function handle()
{
$client_id = config('zoho.client_id');
$client_domain = config('app.url').'/zoho/oauth2callback';
$client_domain = config('zoho.redirect_uri');
$accounts_url = config('zoho.accounts_url');

$scope = config('zoho.oauth_scope');
$prompt = 'consent';
$response_type = 'code';
$access_type = config('zoho.access_type');

$redirect_url = "https://accounts.zoho.com/oauth/v2/auth?scope={$scope}&prompt={$prompt}&client_id={$client_id}&response_type={$response_type}&access_type={$access_type}&redirect_uri={$client_domain}";
$redirect_url = "{$accounts_url}/oauth/v2/auth?scope={$scope}&prompt={$prompt}&client_id={$client_id}&response_type={$response_type}&access_type={$access_type}&redirect_uri={$client_domain}";
//{{accounts_url}}/oauth/v2/token?grant_type=authorization_code&client_id={{client_id}}&client_secret={{client_secret}}&redirect_uri={{redirect_uri}}&code=1000.2ba87e1464afc3ba9042acb90f4c196d.971662a877b2aa7470642ce244c41055

$this->info('Copy the following url, past on browser and hit return.');
$this->line($redirect_url);
}
Expand Down
20 changes: 15 additions & 5 deletions src/Concerns/ManagesRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,69 +22,79 @@ public function getRecord(string $record_id): Record
/**
* get the records array of given module api name
*/
public function getRecords($page = 1, $perPage = 200): array
public function getRecords($page = 1, $perPage = 200, $sortBy = 'id', $sortOrder = 'desc'): array
{
$recordOperations = new RecordOperations();
$paramInstance = new ParameterMap();

$paramInstance->add(GetRecordsParam::page(), $page);
$paramInstance->add(GetRecordsParam::perPage(), $perPage);
$paramInstance->add(GetRecordsParam::sortBy(), $sortBy);
$paramInstance->add(GetRecordsParam::sortOrder(), $sortOrder);

return $this->handleRecordResponse(
$recordOperations->getRecords($this->module_api_name, $paramInstance)
);
}

public function searchRecordsByCriteria(string $criteria, $page = 1, $perPage = 200): array
public function searchRecordsByCriteria(string $criteria, $page = 1, $perPage = 200, $sortBy = 'id', $sortOrder = 'desc'): array
{
$recordOperations = new RecordOperations();
$paramInstance = new ParameterMap();

$paramInstance->add(SearchRecordsParam::criteria(), $criteria);
$paramInstance->add(GetRecordsParam::page(), $page);
$paramInstance->add(GetRecordsParam::perPage(), $perPage);
$paramInstance->add(GetRecordsParam::sortBy(), $sortBy);
$paramInstance->add(GetRecordsParam::sortOrder(), $sortOrder);

return $this->handleRecordResponse(
$recordOperations->searchRecords($this->module_api_name, $paramInstance)
);
}

public function searchRecordsByWord(string $word, $page = 1, $perPage = 200): array
public function searchRecordsByWord(string $word, $page = 1, $perPage = 200, $sortBy = 'id', $sortOrder = 'desc'): array
{
$recordOperations = new RecordOperations();
$paramInstance = new ParameterMap();

$paramInstance->add(SearchRecordsParam::word(), $word);
$paramInstance->add(GetRecordsParam::page(), $page);
$paramInstance->add(GetRecordsParam::perPage(), $perPage);
$paramInstance->add(GetRecordsParam::sortBy(), $sortBy);
$paramInstance->add(GetRecordsParam::sortOrder(), $sortOrder);

return $this->handleRecordResponse(
$recordOperations->searchRecords($this->module_api_name, $paramInstance)
);
}

public function searchRecordsByPhone(string $phone, $page = 1, $perPage = 200): array
public function searchRecordsByPhone(string $phone, $page = 1, $perPage = 200, $sortBy = 'id', $sortOrder = 'desc'): array
{
$recordOperations = new RecordOperations();
$paramInstance = new ParameterMap();

$paramInstance->add(SearchRecordsParam::phone(), $phone);
$paramInstance->add(GetRecordsParam::page(), $page);
$paramInstance->add(GetRecordsParam::perPage(), $perPage);
$paramInstance->add(GetRecordsParam::sortBy(), $sortBy);
$paramInstance->add(GetRecordsParam::sortOrder(), $sortOrder);

return $this->handleRecordResponse(
$recordOperations->searchRecords($this->module_api_name, $paramInstance)
);
}

public function searchRecordsByEmail(string $email, $page = 1, $perPage = 200): array
public function searchRecordsByEmail(string $email, $page = 1, $perPage = 200, $sortBy = 'id', $sortOrder = 'desc'): array
{
$recordOperations = new RecordOperations();
$paramInstance = new ParameterMap();

$paramInstance->add(SearchRecordsParam::email(), $email);
$paramInstance->add(GetRecordsParam::page(), $page);
$paramInstance->add(GetRecordsParam::perPage(), $perPage);
$paramInstance->add(GetRecordsParam::sortBy(), $sortBy);
$paramInstance->add(GetRecordsParam::sortOrder(), $sortOrder);

return $this->handleRecordResponse(
$recordOperations->searchRecords($this->module_api_name, $paramInstance)
Expand Down

0 comments on commit 14834ce

Please sign in to comment.