class WPML_TP_API_Request {
private $params = array( 'api_version' => self::API_VERSION );
private $has_api_response = true;
public function __construct( $url ) {
throw new InvalidArgumentException( 'Url cannot be empty' );
public function set_params( array $params ) {
$this->params = array_merge( $this->params, $params );
public function set_method( $method ) {
if ( ! in_array( $method, array( 'GET', 'POST', 'PUT', 'DELETE', 'HEAD' ), true ) ) {
throw new InvalidArgumentException( 'HTTP request method has invalid value' );
public function set_has_api_response( $has_api_response ) {
$this->has_api_response = (bool) $has_api_response;
public function get_url() {
if ( $this->get_params() ) {
list( $url, $params_used_in_path ) = $this->add_parameters_to_path( $url, $this->get_params() );
if ( 'GET' === $this->get_method() ) {
$url = $this->add_query_parameters( $params_used_in_path, $url );