lundi 27 août 2018

Pattern for downloading data

The API call return data that has a following structure: {id:"z", "data":{},previous:"y"} I want to: a) download 20 records b) do it in a way that I can report/catch errors, basically best practice c) how would you unit test it ?

So far I have a following pseudo code

int max_records = 20 
var results =[Record]()

func get_results(id){
   if results.count == 20{
      //stop
   }
   else{
       //URL, Session download code
       download(result,error){
       if (error){
            //should I throw error here?
        }else{
            //recursive call 
             get_results(record.id)
      }
   }

    }

}

Aucun commentaire:

Enregistrer un commentaire