You are here

public static function InstapageCmsPluginHelper::checkResponse in Instapage plugin 8.3

Same name and namespace in other branches
  1. 7.3 core/InstapageCmsPluginHelper.php \InstapageCmsPluginHelper::checkResponse()

Checks Instapage API response.

Parameters

object $response Response object.:

string $message A message to store in debug log or display to user after checking.:

bool $print If message should be shown to user a a system message.:

Return value

bool Returns true on success, false on failure.

9 calls to InstapageCmsPluginHelper::checkResponse()
InstapageCmsPluginAjaxController::deletePage in core/InstapageCmsPluginAjaxController.php
Deletes a page from DB.
InstapageCmsPluginAjaxController::getLandingPages in core/InstapageCmsPluginAjaxController.php
Gets the landing pages stored in the DB.
InstapageCmsPluginAjaxController::getStats in core/InstapageCmsPluginAjaxController.php
Gets the stats of landing pages from local cache or from app, if cache is not present / invalid.
InstapageCmsPluginAjaxController::loadEditPage in core/InstapageCmsPluginAjaxController.php
Loads edit page.
InstapageCmsPluginAjaxController::loadListPages in core/InstapageCmsPluginAjaxController.php
Loads listing page.

... See full list

File

core/InstapageCmsPluginHelper.php, line 340

Class

InstapageCmsPluginHelper
Helper containing commonly used static functions.

Code

public static function checkResponse($response, $message = '', $print = true) {
  if (is_null($response)) {
    $msgText = InstapageCmsPluginConnector::lang('Can\'t decode API response. %s', $message);
    if ($print) {
      echo self::formatJsonMessage($msgText, 'ERROR');
    }
    else {
      self::writeDiagnostics($msgText, 'message');
    }
    return false;
  }
  if (!$response->success) {
    $text = isset($response->message) ? $response->message : '';
    if ($print) {
      if ($text) {
        echo self::formatJsonMessage(InstapageCmsPluginConnector::lang($text), 'ERROR');
      }
      else {
        echo self::formatJsonMessage(InstapageCmsPluginConnector::lang('API returned an error. %s', $message), 'ERROR');
      }
    }
    else {
      self::writeDiagnostics($text, 'message');
    }
    return false;
  }
  return true;
}