/**
  * Get sends for a given campaign
  * @param string $accessToken - Constant Contact OAuth2 access token
  * @param string $campaignId - Campaign id
  * @param Array $params - query params to be appended to request
  * @return TrackingActivity - Containing a results array of {@link SendActivity}
  */
 public function getSends($accessToken, $campaignId, array $params = array())
 {
     $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_tracking_sends'), $campaignId);
     $url = $this->buildUrl($baseUrl, $params);
     $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
     $body = json_decode($response->body, true);
     $sends = array();
     foreach ($body['results'] as $send_activity) {
         $sends[] = SendActivity::create($send_activity);
     }
     return new ResultSet($sends, $body['meta']);
 }
 public function testGetSends()
 {
     $response = self::$client->get('/')->json();
     $resultSet = new ResultSet($response['results'], $response['meta']);
     $sendActivity = SendActivity::create($resultSet->results[0]);
     $this->assertInstanceOf('Ctct\\Components\\ResultSet', $resultSet);
     $this->assertInstanceOf('Ctct\\Components\\Tracking\\SendActivity', $sendActivity);
     $this->assertEquals("bGltaXQ9MyZuZXh0PTEzNTQ4MTcyMTA0MzA", $resultSet->next);
     $this->assertEquals("EMAIL_SEND", $sendActivity->activity_type);
     $this->assertEquals(1100394165290, $sendActivity->campaign_id);
     $this->assertEquals("55", $sendActivity->contact_id);
     $this->assertEquals("*****@*****.**", $sendActivity->email_address);
     $this->assertEquals("2012-12-06T18:06:50.650Z", $sendActivity->send_date);
 }
 /**
  * Get sends for a given campaign
  * @param string $accessToken - Constant Contact OAuth2 access token
  * @param string $campaignId - Campaign id
  * @param Array $params = array() - 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.
  *      created_since - Used to retrieve a list of events since the date and time specified (in ISO-8601 format).
  *      next - the next link returned from a previous paginated call. May only be used by itself.
  * @return TrackingActivity - Containing a results array of {@link SendActivity}
  * @throws CtctException
  */
 public function getSends($accessToken, $campaignId, array $params = array())
 {
     $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_tracking_sends'), $campaignId);
     $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();
     $sends = array();
     foreach ($body['results'] as $send_activity) {
         $sends[] = SendActivity::create($send_activity);
     }
     return new ResultSet($sends, $body['meta']);
 }