/
var
/
www
/
html
/
plugin-techloyce
/
Modules
/
SubscriptionFlowServices
/
Services
/
Upload File
HOME
<?php namespace Modules\SubscriptionFlowServices\Services; use Modules\SubscriptionFlowServices\Handlers\ApiHandler; use Modules\SubscriptionFlowServices\Services\AuthorizationService; class GeneralCrudService { public $baseUrl; public $clientID; public $clientSecret; private $apiHandler; public function setup( $baseUrl, $clientID, $clientSecret ) { $this->baseUrl = $baseUrl; $this->clientID = $clientID; $this->clientSecret = $clientSecret; $authorizationClass = new AuthorizationService($baseUrl, $clientID, $clientSecret); $accessToken = $authorizationClass->getAccessToken(); $this->apiHandler = new ApiHandler($accessToken); return $this; } public function getRecords($module, $withRelations = false) { $getRecordsEndPoint = $this->baseUrl . '/api/v1/' . $module; if ($withRelations) { return $this->apiHandler->get($getRecordsEndPoint . '/with-relations'); } else { return $this->apiHandler->get($getRecordsEndPoint); } } public function createRecord($module, $data) { $createRecordEndPoint = $this->baseUrl . '/api/v1/' . $module; return $this->apiHandler->post($createRecordEndPoint, $data); } public function updateRecord($module, $id, $data) { $updateRecordsEndPoint = $this->baseUrl . '/api/v1/' . $module . '/' . $id; return $this->apiHandler->put($updateRecordsEndPoint, $data); } public function getRecord($module, $id) { $getRecordEndPoint = $this->baseUrl . '/api/v1/' . $module . '/' . $id; return $this->apiHandler->get($getRecordEndPoint); } public function deleteRecord($module, $id) { $deleteRecordEndPoint = $this->baseUrl . '/api/v1/' . $module . '/' . $id; return $this->apiHandler->delete($deleteRecordEndPoint); } public function getRelationalRecords($module, $id, $relationalModule) { $getRecordRelationsEndPoint = $this->baseUrl . '/api/v1/' . $module . '/' . $id . '/link/' . $relationalModule; return $this->apiHandler->get($getRecordRelationsEndPoint); } public function getFilteredRecords($module, $searchField, $searchValue){ $getFitleredRecordsEndPoint = $this->baseUrl . '/api/v1/' . $module . '/search?' . $searchField . '=' . $searchValue; return $this->apiHandler->get($getFitleredRecordsEndPoint); } }