Newer
Older
/**
* The WoW Service.
*
* @var WoWServiceInterface
*/
protected $service;
/**
* Resource URL being linked to. It is the responsibility of the caller to
* url encode the path: http://$host/api/wow/$path.
/**
* An array of query key/value-pairs (without any URL-encoding) to append to
* the URL.
*
* @var array
*/
protected $query;
/**
* An array containing request headers to send as name/value pairs.
*
* @var array
*/
protected $headers;
/**
* Constructs an HttpRequest object.
*
* @param WoWServiceInterface
* A WoW Service object.
* @param string $path
* Resource URL being linked to. It is the responsibility of the caller to
* url encode the path: http://$host/api/wow/$path.
public function __construct(WoWServiceInterface $service, $path) {
$this->query = array();
$this->headers = array();
}
/**
* Configures the request with an If-Modified-Since header.
*
public function setIfModifiedSince($time) {
$this->headers['If-Modified-Since'] = gmdate("D, d M Y H:i:s T", $time);
return $this;
}
/**
* Configures the request with an API compliant locale value.
*
* @param string $language
* The language used to determine the locale to set.
*
// Prepares the query by adding a locale string if supported.
$this->query['locale'] = $locale;
}
return $this;
}
/**
* Adds a query parameter to the request.
*
* @param string $key
* The query key.
* @param string|array $value
* The query value.
*
$this->query[$key] = is_array($value) ? implode(",", $value) : $value;
return $this;
}
/**
* Executes the request.
*
// The date is used to sign the request, in the following format:
// Fri, 10 Jun 2011 20:59:24 GMT, but also to time stamp the response.
$this->headers['Date'] = gmdate("D, d M Y H:i:s T");
return $this->service->request($this->path, $this->query, $this->headers);