/** * The vast majority of the custom find types actually follow the same format * so there was little point explicitly writing them all out. Instead, if the * method corresponding to the custom find type doesn't exist, the options are * applied to the model's request property here and then we just call * parent::find('all') to actually trigger the request and return the response * from the API. * * In addition, if you try to fetch a timeline that supports paging, but you * don't specify paging params, you really want all tweets in that timeline * since time imemoriam. But twitter will only return a maximum of 200 per * request. So, we make multiple calls to the API for 200 tweets at a go, for * subsequent pages, then merge the results together before returning them. * * Twitter's API uses a count parameter where in CakePHP we'd normally use * limit, so we also copy the limit value to count so we can use our familiar * params. * * @param string $type * @param array $options * @return mixed */ public function find($type, $options = array()) { if (!empty($options['limit']) && empty($options['count'])) { $options['count'] = $options['limit']; } if ((empty($options['page']) || empty($options['count'])) && array_key_exists($type, $this->allowedFindOptions) && in_array('page', $this->allowedFindOptions[$type]) && in_array('count', $this->allowedFindOptions[$type])) { $options['page'] = 1; $options['count'] = 200; $results = array(); while (($page = $this->find($type, $options)) != false) { $results = array_merge($results, $page); $options['page']++; } return $results; } if (method_exists($this, '_find' . Inflector::camelize($type))) { return parent::find($type, $options); } $this->request['uri']['path'] = '1/statuses/' . Inflector::underscore($type); if (array_key_exists($type, $this->allowedFindOptions)) { $this->request['uri']['query'] = array_intersect_key($options, array_flip($this->allowedFindOptions[$type])); } if (in_array($type, $this->findMethodsRequiringAuth)) { $this->request['auth'] = true; } return parent::find('all', $options); }