/** * Retrieves the lists via Sendinblue API and updates the data in DB. * @return string */ function get_sendinblue_lists($api_key, $name) { $lists = array(); if (!function_exists('curl_init')) { return __('curl_init is not defined ', 'rapidology'); } if (!class_exists('Mailin')) { require_once RAD_RAPIDOLOGY_PLUGIN_DIR . 'subscription/sendinblue-v2.0/mailin.php'; } $mailin = new Mailin('https://api.sendinblue.com/v2.0', $api_key); $page = 1; $page_limit = 50; $all_lists = array(); $need_request = true; while (true == $need_request) { $lists_array = $mailin->get_lists($page, $page_limit); $all_lists = array_merge($all_lists, $lists_array); if (50 > count($lists_array)) { $need_request = false; } else { $page++; } } if (!empty($all_lists)) { if (isset($all_lists['code']) && 'success' === $all_lists['code']) { $error_message = 'success'; if (!empty($all_lists['data']['lists'])) { foreach ($all_lists['data']['lists'] as $single_list) { $lists[$single_list['id']]['name'] = $single_list['name']; $total_contacts = isset($single_list['total_subscribers']) ? $single_list['total_subscribers'] : 0; $lists[$single_list['id']]['subscribers_count'] = $total_contacts; $lists[$single_list['id']]['growth_week'] = $this->calculate_growth_rate('sendinblue_' . $single_list['id']); } } $this->update_account('sendinblue', $name, array('api_key' => esc_html($api_key), 'lists' => $lists, 'is_authorized' => esc_html('true'))); } else { $error_message = $all_lists['message']; } } else { $error_message = __('Invalid API key or something went wrong during Authorization request', 'rapidology'); } return $error_message; }
/** get lists in SendinBlue */ static function get_lists() { $access_key = SIB_Manager::$access_key; $mailin = new Mailin(SIB_Manager::sendinblue_api_url, $access_key); $data = array(); $list_response = $mailin->get_lists($data); $lists = array(); // check response if (!is_array($list_response)) { return $lists; } if ($list_response['code'] != 'success') { return $lists; } $response_data = $list_response['data']; if (!is_array($response_data)) { return $lists; } // get lists from response if (isset($response_data) && is_array($response_data)) { foreach ($response_data as $list) { $lists[] = array('id' => $list['id'], 'name' => $list['name']); } } return $lists; }
/** get lists in SendinBlue */ static function get_lists() { $access_key = SIB_Manager::$access_key; $secret_key = SIB_Manager::$secret_key; $mailin = new Mailin('https://api.sendinblue.com/v1.0', $access_key, $secret_key); $list_response = $mailin->get_lists(); $lists = array(); // check response if (!is_array($list_response)) { return $lists; } if ($list_response['code'] != 'success') { return $lists; } $response_data = $list_response['data']; if (!is_array($response_data)) { return $lists; } // get lists from response foreach ($response_data as $list) { $lists[] = array('id' => $list['id'], 'name' => $list['name']); } return $lists; }