You are here

public function InstapageCmsPluginAPIModel::apiCall in Instapage plugin 8.3

Same name and namespace in other branches
  1. 7.3 core/models/InstapageCmsPluginAPIModel.php \InstapageCmsPluginAPIModel::apiCall()

Performs the request to Instapage app.

Parameters

string $action API action.:

array $data Data to be passed in the request.:

array $headers Headers for the request.:

string $method Request type. 'POST' ang 'GET' are allowed. Default: 'POST'.:

Return value

object $response Request response.

1 call to InstapageCmsPluginAPIModel::apiCall()
InstapageCmsPluginAPIModel::authorise in core/models/InstapageCmsPluginAPIModel.php
Authorizes the user based on email and password.

File

core/models/InstapageCmsPluginAPIModel.php, line 79

Class

InstapageCmsPluginAPIModel
Class responsible for communication with Instapage app via API.

Code

public function apiCall($action, $data = array(), $headers = array(), $method = 'POST') {
  $integration = InstapageCmsPluginConnector::getSelectedConnector()->name;
  $url = InstapageCmsPluginConnector::getURLWithSelectedProtocol(INSTAPAGE_APP_ENDPOINT . '/' . $action);
  $headers['integration'] = $integration;
  $response = InstapageCmsPluginConnector::getSelectedConnector()
    ->remoteRequest($url, $data, $headers, $method);
  InstapageCmsPluginHelper::writeDiagnostics($method . ' : ' . $url, 'API ' . $action . ' URL');
  InstapageCmsPluginHelper::writeDiagnostics($data, 'API ' . $action . ' data');
  InstapageCmsPluginHelper::writeDiagnostics($headers, 'API ' . $action . ' headers');
  InstapageCmsPluginHelper::writeDiagnostics($response, 'API ' . $action . ' response');
  return is_array($response) && isset($response['body']) ? $response['body'] : null;
}