/**
  * Get opens for a given campaign
  * @param string $accessToken - Constant Contact OAuth2 access token
  * @param string $campaign_id - Campaign id
  * @param array $params - query params to be appended to request
  * @return ResultSet - Containing a results array of {@link OpenActivity}
  */
 public function getOpens($accessToken, $campaign_id, array $params = array())
 {
     $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_tracking_opens'), $campaign_id);
     $url = $this->buildUrl($baseUrl, $params);
     $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
     $body = json_decode($response->body, true);
     $opens = array();
     foreach ($body['results'] as $open_activity) {
         $opens[] = OpenActivity::create($open_activity);
     }
     return new ResultSet($opens, $body['meta']);
 }
 public function testGetOpens()
 {
     $response = self::$client->get('/')->json();
     $resultSet = new ResultSet($response['results'], $response['meta']);
     $openActivity = OpenActivity::create($resultSet->results[0]);
     $this->assertInstanceOf('Ctct\\Components\\ResultSet', $resultSet);
     $this->assertInstanceOf('Ctct\\Components\\Tracking\\OpenActivity', $openActivity);
     $this->assertEquals("bGltaXQ9MyZuZXh0PTEzNTQ4MTcyMTA0MzA", $resultSet->next);
     $this->assertEquals("EMAIL_OPEN", $openActivity->activity_type);
     $this->assertEquals(1100394165290, $openActivity->campaign_id);
     $this->assertEquals("86", $openActivity->contact_id);
     $this->assertEquals("*****@*****.**", $openActivity->email_address);
     $this->assertEquals("2012-12-06T13:07:11.839Z", $openActivity->open_date);
 }
 /**
  * Get opens for a given campaign
  * @param string $accessToken - Constant Contact OAuth2 access token
  * @param string $campaignId - Campaign id
  * @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.
  *      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 ResultSet - Containing a results array of {@link OpenActivity}
  * @throws CtctException
  */
 public function getOpens($accessToken, $campaignId, array $params = array())
 {
     $baseUrl = Config::get('endpoints.base_url') . sprintf(Config::get('endpoints.campaign_tracking_opens'), $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();
     $opens = array();
     foreach ($body['results'] as $open_activity) {
         $opens[] = OpenActivity::create($open_activity);
     }
     return new ResultSet($opens, $body['meta']);
 }