I have the following script that I'm part way through and I'm not happy with it at all, it feels messy:
<?php
class Process {
public $search = 'http://api.themoviedb.org/2.1/Person.search/en/json/xxx/';
public $info = 'http://api.themoviedb.org/2.1/Person.getInfo/en/json/xxx/';
public function returnId($name){
return $this->returnJson($this->search . $name);
}
public function returnMovies($id){
return $this->returnJson($this->info . $id);
}
public function returnJson($url){
$raw = file_get_contents($url);
$json = json_decode($raw, true);
return $json;
}
}
$p = new Process();
$first = urlencode($_POST['first']);
$second = urlencode($_POST['second']);
$id = $p->returnId($first);
$movies = $p->returnMovies($id[0]['id']);
Now the idea is that two parameters get sent to this script and each of them run through the first API call ($search
) and then the ID field is extracted from that results and passed into the $info
URL call. The two arrays that come back from returnMovies
will be compared with each other and any matches will be popped into another array.
Now, has anyone got any way for this to be better in structure and cleanliness?
It's not finished yet but its a simple script that I'd like to tidy up before I go on.