/** * Method that requesting ad trough adzerk api with given data. * More info: * @link http://help.adzerk.com/Native_Ads_API * * @param $data * @return RestClient */ public function request($data) { $request = new RestClient(array('base_url' => self::ENDPOINT, 'headers' => array('Content-Type' => 'application/json'), 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "")); // html decoder accept adzerk error messages, we need no parser here $request->register_decoder('html', function ($data) { return $data; }); $example = '{"placements":[{"divName":"div1","networkId":4161,"siteId":20022,"adTypes":[5]}],"user":{"key":"abc"}}'; $response = $request->post($this->apiUrl, json_encode($data)); return $response; }
/** * @param $method * @param $args * @return Adzerk\Wrapper * @throws Adzerk\InvalidArgumentException */ public function __call($method, $args) { $class = '\\Positivezero\\Adzerk\\Wrappers\\' . $this->firstUpper($method); if (class_exists($class)) { $request = new RestClient(array('base_url' => $this->apiUrl['v1'], 'headers' => array('X-Adzerk-ApiKey' => $this->apiKey))); // html decoder accept adzerk error messages, we need no parser here $request->register_decoder('html', function ($data) { return $data; }); return new $class($request, isset($args[0]) ? $args[0] : null, isset($args[1]) ? $args[1] : null); } throw new InvalidArgumentException($class . ' not found!'); }