/** * @param ClientRequest $clientRequest * @return Response */ public function getResponse(ClientRequest $clientRequest) { $client = new HttpClient(); $headers = array(); foreach ($clientRequest->getHeaders() as $key => $val) { $headers[] = "{$key}: {$val}"; } switch ($clientRequest->getVerb()) { case ClientRequest::POST: $response = $client->post(array('url' => $clientRequest->getUrl(), 'content' => $clientRequest->getContent(), 'headers' => $headers)); break; case ClientRequest::DELETE: $response = $client->delete(array('url' => $clientRequest->getUrl(), 'headers' => $headers)); break; case ClientRequest::PUT: $response = $client->put(array('url' => $clientRequest->getUrl(), 'content' => $clientRequest->getContent(), 'headers' => $headers)); break; case ClientRequest::GET: default: $response = $client->get(array('url' => $clientRequest->getUrl(), 'params' => $clientRequest->getParameters(), 'headers' => $headers)); break; } if ($response instanceof \Vinelab\Http\Response) { $content = $response->content(); if (is_bool($content) || is_null($content)) { $content = ''; } $responseBag = new Response($content, $response->statusCode(), $response->headers()); return $responseBag; } else { return null; } }
public function run() { //get the subtopic and youtube videoids as array of key valur pair from config/subtopic.php //eg array('ETMA-101-1-1'=>array('fdfd','dffdf','sdsd')) $arrofsubtopicsandvideoid = Config::get('subtopic'); $arrofsubtopics = []; $i = 0; while ($i < sizeof($arrofsubtopicsandvideoid)) { //get the array of subtopics $arrofsubtopics = array_add($arrofsubtopics, $i, key($arrofsubtopicsandvideoid)); $i = $i + 1; next($arrofsubtopicsandvideoid); } //for each subtopic fetch all the videos from youtube for ($i = 0; $i < sizeof($arrofsubtopics); $i++) { $subtopic_code = $arrofsubtopics[$i]; $videoids = $arrofsubtopicsandvideoid[$subtopic_code]; //fetch all the videos title and description of a single subtopic and store in datbase for ($j = 0; $j < sizeof($videoids); $j++) { $client = new HttpClient(); $url = 'https://www.googleapis.com/youtube/v3/videos?id=' . $videoids[$j] . '&key=AIzaSyACqud0pby3FsKsbfHAUD17PSE7EBL7Yr0&part=snippet,contentDetails,statistics,status'; $response = $client->get($url); $m = $response->json(); $items = $m->items; $snippet = $items[0]->snippet; DB::table('videos')->insert(['subtopic_code' => $arrofsubtopics[$i], 'url' => 'https://www.youtube.com/watch?v=' . $videoids[$j] . '/', 'youtubevideoid' => $videoids[$j], 'title' => $snippet->title, 'description' => $snippet->description]); } } }
public function saveForm() { $client = new HttpClient(); $name = Input::get('name'); $mobile = Input::get('mobile'); $email = Input::get('email'); $message = Input::get('message'); $request = ['url' => 'http://192.168.1.124/slimapi/insertUser', 'params' => ['name' => $name, 'mobile' => $mobile, 'email' => $email, 'message' => $message]]; $response = $client->post($request); $data = $response->content(); echo $data; }
public function run() { $arrofsubtopicsandvideoid = Config::get('subtopic'); $arrofsubtopics = []; $i = 0; while ($i < sizeof($arrofsubtopicsandvideoid)) { $arrofsubtopics = array_add($arrofsubtopics, $i, key($arrofsubtopicsandvideoid)); $i = $i + 1; next($arrofsubtopicsandvideoid); } for ($i = 0; $i < sizeof($arrofsubtopics); $i++) { $subtopic_code = $arrofsubtopics[$i]; $videoids = $arrofsubtopicsandvideoid[$subtopic_code]; for ($j = 0; $j < sizeof($videoids); $j++) { $client = new HttpClient(); $url = 'https://www.googleapis.com/youtube/v3/videos?id=' . $videoids[$j] . '&key=AIzaSyACqud0pby3FsKsbfHAUD17PSE7EBL7Yr0&part=snippet,contentDetails,statistics,status'; $response = $client->get($url); $m = $response->json(); $items = $m->items; $snippet = $items[0]->snippet; DB::table('videos')->insert(['subtopic_code' => $arrofsubtopics[$i], 'url' => 'https://www.youtube.com/watch?v=' . $videoids[$j] . '/', 'youtubevideoid' => $videoids[$j], 'title' => $snippet->title, 'description' => $snippet->description]); } } }
/** * Make the api call. * * @param string $url * @param array $params * * @return stdClass */ public function get($url, $params) { $result = $this->http_client->get(compact('url', 'params')); return $result->json(); }
/** * Fetch the feed from source. * * @param string $url * * @return mixed */ public function fetch($url) { return $this->http->get(trim($url)); }