How To Deal With Recursive Calls To Api And Json Data

I need to call an API that returns JSON.

It limits to 100 records each time.

$params = "start_rec = 0, num_max = 100";

So I call GET

$jsonObject = GET($url, $params);

if the response->count > $num_max I need to

$start_rec=100

call fcn again

Not sure how to handle the recursion and the json merging the data.

Any suggestions?

Thanks very much !





public function getJson($url, $params) // $params = array()

	{

	return $jsonObject = Yii::app()->curl->setOption(CURLOPT_HTTPHEADER, $auth)->get($url, $params);

	}


public function actionGetData($service) // $params = array()

	{

public $start_rec = 0;

public $num_max = 100;

public $rec = 0;

$params = "start_rec = 0, num_max = 100";


   $jsonObject = $this->getJson($url, $params);

   $obj = json_decode($jsonObject);

   $status = $obj->response->status;

   if ($status == "OK") {

	$count = $obj->response->count;		// total records in set to be returned 	

	$start_rec = $obj->response->start_rec;	

	if ( $count < $num_max)

           $num_max = $count;

	if ( $rec < $count ) {		

          for ($i=$start_rec; $i<$start_rec+$num_max; $i++) {

		$id = $obj->response->categories[$i]->id;

		$name = $obj->response->categories[$i]->name;

	   }	  

            $start_rec = $start_rec + $i;

            $rec = $rec + i;

            $params = "start_rec = $start_rec, num_max = $num_max";

            $jsonObject = $this->getJson($url, $params);

            if ( $count < $num_max)

                $num_max = $count;

	}

}



I have many services (api’s) that I need to call.

Not sure how to make a generic function to deal with the json arrays.

Each JSON has it’s own structure, so I can reference array elements by name

using as example

               &#036;id = &#036;obj-&gt;response-&gt;category[&#036;i]-&gt;id;

Could I create a model for each (service) JSON?

Can I map a json (or a model of it) into a CDataProvider?

What are the downsides of trying to get several hundred records vs. doing a fetch of just some?