<?php

function decodeSignedRequest($signedRequest){
	list($encodedData, $encodedSignature) = explode('.', $signedRequest, 2);
	$jsonStr = base64_decode($encodedData);
	return json_decode($jsonStr, true);
}


function getRequest($url, $client_id, $access_token){
	$curl = curl_init();
	curl_setopt_array($curl, array(
	  CURLOPT_URL => $url,
	  CURLOPT_RETURNTRANSFER => true,
	  CURLOPT_ENCODING => "",
	  CURLOPT_MAXREDIRS => 10,
	  CURLOPT_TIMEOUT => 30,
	  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
	  CURLOPT_CUSTOMREQUEST => "GET",
	  CURLOPT_HTTPHEADER => array(
		"Accept: application/json",
		"Connection: keep-alive",
		"Content-Type: application/json",
		"X-Auth-Client: ".$client_id,
		"X-Auth-Token: ".$access_token,
		"cache-control: no-cache"
	  ),
	));
	$response = curl_exec($curl);
	$err = curl_error($curl);
	curl_close($curl);
	$response	= json_decode($response,true);
	return $response;
}