php - REST API wrapper design -
i'm writing wrapper (adapter pattern) number of rest calls. i'm trying decide how response object should able do.
class job { private $xml; public function __construct(simplexmlelement $xml) { $this->xml = $xml; } public function getname() { return $this->xml->name; } public function getid() { return $this->xml->id; } ... ... ... } class restmanager { private $client; public function __construct(guzzle $client) { $this->client = $client } public function getjobbyname($name) { $job = $this->client->get('/query/job/' . $name); return new job($job->asxmlobj()) } }
so have similar above. once have job object want additional information such as, list of items in job. requires server call should ask job items
class job { private $manager; ... ... public function addmanager(restmanager $manager) { $this->manager = $manager; } public function getitems() { return $this->manager->getjobitems($this); } }
or ask restmanager directly?
class restmanager { ... ... public function getjobitems(job $job) { return $this->client->get('/job/' . $job->getid() . '/items'); } }
Comments
Post a Comment