public function fetch($page = 1) { $params = $this->params; if ($this->paginate) { $params = array_merge($params, array('page' => $page)); } $response = $this->client->get($this->path(), $params); $data = $response->json(); if ($this->paginate) { $this->total = $data['total']; $this->pages = $data['pages']; $this->limit = $data['limit']; $this->currentPage = $data['current_page']; foreach ($data[static::$name] as $i => $deviceData) { $position = $i + ($this->currentPage - 1) * $this->limit; $this->setResource($position, $deviceData); } } else { $data = current($data); $this->total = count($data); foreach ($data as $i => $deviceData) { $this->setResource($i, $deviceData); } } }
/** * Retrieves a single resource * * @param M2X $client * @param string $id * @return Resource */ public static function get($client, $id) { $response = $client->get(static::$path . '/' . $id); $class = get_called_class(); return new $class($client, $response->json()); }