/** * Load a resource from the API. * * The parameter is the id of the resource. E.g., /v2/contacts/2093385 would be loaded by passing 2093385 * to the method. * * @param int $resource_id */ public function load($resource_id) { $resource_url = sprintf(static::FETCH_ENDPOINT, $resource_id); $response = Transport::get($this->getFullEndpoint($resource_url), $this->getAuthHeaders()); $response_obj = json_decode($response->body); $this->url = $resource_url; $this->loadData($response_obj); }
/** * Return all customers. An array indexed by email. Contact objects as values. * * @return array */ public function all() { $customer_map = array(); $customer_page = 1; do { $all_customers = Transport::get(sprintf("%s?per_page=100&page=%d", $this->getFullEndpoint(self::CREATE_ENDPOINT), $customer_page), $this->getAuthHeaders()); $all_customers_json = json_decode($all_customers->body); $page_customer_count = count($all_customers_json->contacts); foreach ($all_customers_json->contacts as $contact) { if (isset($contact->email)) { $contact_data = new \stdClass(); $contact_data->contact = $contact; $contact_obj = new Contact($this->config); $contact_obj->loadData($contact_data); $contact_obj->url = $this->getResourcePathFromUrl($contact->url); $customer_map[$contact->email] = $contact_obj; } } $customer_page++; } while ($page_customer_count > 0); return $customer_map; }