From 38d4db8a3fc054d59fadc255983384755c01d605 Mon Sep 17 00:00:00 2001 From: Marc Michalsky forumZFD Date: Thu, 12 Nov 2020 13:52:14 +0100 Subject: [PATCH] twingle api batch size as parameter --- CRM/TwingleCampaign/BAO/TwingleApiCall.php | 8 ++++++-- api/v3/TwingleSync/Post.php | 11 ++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/CRM/TwingleCampaign/BAO/TwingleApiCall.php b/CRM/TwingleCampaign/BAO/TwingleApiCall.php index c46631b..60ce8a5 100644 --- a/CRM/TwingleCampaign/BAO/TwingleApiCall.php +++ b/CRM/TwingleCampaign/BAO/TwingleApiCall.php @@ -26,11 +26,15 @@ class TwingleApiCall { * * @param $apiKey * + * @param int $limit + * Limit for the number of events that should get requested per call to the + * Twingle API + * * @throws API_Exception */ - public function __construct($apiKey) { + public function __construct($apiKey, int $limit = 20) { $this->apiKey = $apiKey; - $this->limit = CRM_Core_BAO_Setting::getItem('', 'twingle_request_size'); + $this->limit = $limit; // Get organisation id $curl = curl_init($this->protocol . 'organisation' . $this->baseUrl); diff --git a/api/v3/TwingleSync/Post.php b/api/v3/TwingleSync/Post.php index 9676d06..3aadb97 100644 --- a/api/v3/TwingleSync/Post.php +++ b/api/v3/TwingleSync/Post.php @@ -27,6 +27,13 @@ function _civicrm_api3_twingle_sync_Post_spec(array &$spec) { 'api.required' => 0, 'description' => E::ts('The key to access the Twingle API'), ]; + $spec['limit'] = [ + 'name' => 'limit', + 'title' => E::ts('Limit'), + 'type' => CRM_Utils_Type::T_INT, + 'api.required' => 0, + 'description' => E::ts('Limit for the number of events that should get requested per call to the Twingle API'), + ]; $spec['is_test'] = [ 'name' => 'is_test', 'title' => E::ts('Test'), @@ -59,7 +66,9 @@ function civicrm_api3_twingle_sync_Post(array $params) { $apiKey = empty($params['twingle_api_key']) ? CRM_Core_BAO_Setting::getItem('', 'twingle_api_key') : $params['twingle_api_key']; - $twingleApi = new TwingleApiCall($apiKey); + // If function call does not provide a limit, set a default value + $limit = empty($params['limit']) ?? 20; + $twingleApi = new TwingleApiCall($apiKey, $limit); // Get all projects from Twingle $projects = $twingleApi->getProject();