You are here

public static function CleantalkHelper::api_check_response in Anti Spam by CleanTalk 7.4

Same name and namespace in other branches
  1. 7.5 src/CleantalkHelper.php \CleantalkHelper::api_check_response()

* Function checks server response * *

Parameters

string result: * @param string request_method * @return mixed (array || array('error' => true))

8 calls to CleantalkHelper::api_check_response()
CleantalkHelper::api_method_send_empty_feedback in src/CleantalkHelper.php
* Function sends empty feedback for version comparison in Dashboard * *
CleantalkHelper::api_method__get_2s_blacklists_db in src/CleantalkHelper.php
CleantalkHelper::api_method__get_account_status in src/CleantalkHelper.php
* Function gets information about account * *
CleantalkHelper::api_method__get_antispam_report_breif in src/CleantalkHelper.php
* Function gets spam statistics * *
CleantalkHelper::api_method__notice_paid_till in src/CleantalkHelper.php
* Function gets information about renew notice * *

... See full list

File

src/CleantalkHelper.php, line 576

Class

CleantalkHelper
Cleantalk's hepler class

Code

public static function api_check_response($result, $method_name = null) {

  // Errors handling
  // Bad connection
  if (empty($result)) {
    return array(
      'error' => true,
      'error_string' => 'CONNECTION_ERROR',
    );
  }

  // JSON decode errors
  $result = json_decode($result, true);
  if (empty($result)) {
    return array(
      'error' => true,
      'error_string' => 'JSON_DECODE_ERROR',
    );
  }

  // cURL error
  if (!empty($result['error'])) {
    return array(
      'error' => true,
      'error_string' => 'CONNECTION_ERROR: ' . $result['error_string'],
    );
  }

  // Server errors
  if ($result && (isset($result['error_no']) || isset($result['error_message']))) {
    return array(
      'error' => true,
      'error_string' => "SERVER_ERROR NO: {$result['error_no']} MSG: {$result['error_message']}",
      'error_no' => $result['error_no'],
      'error_message' => $result['error_message'],
    );
  }

  // Pathces for different methods
  // mehod_name = notice_validate_key
  if ($method_name == 'notice_validate_key' && isset($result['valid'])) {
    return $result;
  }

  // Other methods
  if (isset($result['data']) && is_array($result['data'])) {
    return $result['data'];
  }
}