Api_Server::call( $params )

call


Parameters Parameters

$method

(Required)

$url

(Required)

$body

(Required)

$action

(Required)


Top ↑

Return Return

(mixed) $response


Source Source

File: src/core/classes/class-api-server.php

	public static function call( $params ) {

		$api = self::get_instance();

		if ( empty( $params['method'] ) ) {
			throw new \Exception( 'Request method is required', 500 );
		}

		if ( empty( $params['url'] ) ) {
			throw new \Exception( 'URL is required', 500 );
		}

		//We will log all requests here in the future

		$request = array();

		$request = $api->maybe_add_optional_params( $request, $params );

		$request = apply_filters( 'automator_call', $request, $params );

		$response = wp_remote_request(
			$params['url'],
			$request
		);

		if ( is_wp_error( $response ) ) {
			throw new \Exception( 'WordPress was not able to make a request: ' . $response->get_error_message(), 500 );
		}

		return $response;
	}