Beispiel #1
0
	public function do_request($data)
	{
		$config = Config::getInstance();
		$url = $config->get('api', 'url');
		$api = $this->get_api();

		if (!$api) {
			return;
		}

		if (!$config->get('api', 'inner')) {
			$url .= '/' . str_replace('_', '/', $api);

			if (function_exists('igbinary_serialize')) {
				$data['format'] = 'igbinary';
				$data = igbinary_serialize($data);
				$url .= '?f=igbinary';
			} else {
				$data['format'] = 'json';
				$data = json_encode($data, JSON_NUMERIC_CHECK);
				$url .= '?f=json';
			}

			$response = Http::post($url, $data);

			if (empty($response)) {
				throw new Error('No response: ' . $url);
			}

			if (function_exists('igbinary_unserialize')) {
				$response = igbinary_unserialize($response);
			} else {
				$response = json_decode($response, true);
			}
		} else {
			$class = 'Otaku\Api\Api' . implode('', array_map('ucfirst',
					explode('_', $api)));
			$api_request = new ApiRequestInner($data);
			$worker = new $class($api_request);
			$response = $worker->process_request()->get_response();
		}

		$this->process_response($response);
	}