/** * Get a set of campaigns * @param string $accessToken - Constant Contact OAuth2 access token * @param array $params - query params to be appended to the request * @return ResultSet */ public function getCampaigns($accessToken, array $params = null) { $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.campaigns'); $url = $this->buildUrl($baseUrl, $params); $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken)); $body = json_decode($response->body, true); $campaigns = array(); foreach ($body['results'] as $contact) { $campaigns[] = Campaign::createSummary($contact); } return new ResultSet($campaigns, $body['meta']); }
/** * Get a set of campaigns * @param string $accessToken - Constant Contact OAuth2 access token * @param array $params - associative array of query parameters and values to append to the request. * Allowed parameters include: * limit - Specifies the number of results displayed per page of output, from 1 - 500, default = 50. * modified_since - ISO-8601 formatted timestamp. * next - the next link returned from a previous paginated call. May only be used by itself. * @return ResultSet * @throws CtctException */ public function getCampaigns($accessToken, array $params = array()) { $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.campaigns'); $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl); if ($params) { $query = $request->getQuery(); foreach ($params as $name => $value) { $query->add($name, $value); } } try { $response = parent::getClient()->send($request); } catch (ClientException $e) { throw parent::convertException($e); } $body = $response->json(); $campaigns = array(); foreach ($body['results'] as $contact) { $campaigns[] = Campaign::createSummary($contact); } return new ResultSet($campaigns, $body['meta']); }