/**
  * Get folders from the Library
  * @param string $accessToken - Constant Contact OAuth2 Access Token
  * @param array $params - array of query parameters/values to append to the request
  * @return ResultSet
  */
 public function getLibraryFolders($accessToken, array $params)
 {
     $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.library_folders');
     $url = $this->buildUrl($baseUrl, $params);
     $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
     $body = json_decode($response->body, true);
     $libraryFolders = array();
     foreach ($body['results'] as $folder) {
         $libraryFolders[] = Folder::create($folder);
     }
     return new ResultSet($libraryFolders, $body['meta']);
 }
Пример #2
0
 public static function create(array $props)
 {
     $folder = new Folder();
     $folder->id = parent::getValue($props, "id");
     $folder->name = parent::getValue($props, "name");
     foreach ($props['children'] as $child) {
         $folder->children[] = Folder::create($child);
     }
     $folder->item_count = parent::getValue($props, "item_count");
     $folder->parent_id = parent::getValue($props, "parent_id");
     $folder->level = parent::getValue($props, "level");
     return $folder;
 }
Пример #3
0
 /**
  * Get a specific Folder
  * @param string $accessToken - Constant Contact OAuth2 Access Token
  * @param string $folderId - ID of the Folder
  * @return Folder
  * @throws CtctException
  */
 public function getLibraryFolder($accessToken, $folderId)
 {
     $baseUrl = Config::get('endpoints.base_url') . Config::get(sprintf('endpoints.library_folder', $folderId));
     $request = parent::createBaseRequest($accessToken, 'GET', $baseUrl);
     try {
         $response = parent::getClient()->send($request);
     } catch (ClientException $e) {
         throw parent::convertException($e);
     }
     $body = $response->json();
     return Folder::create($body);
 }
 public function testGetLibraryFolders()
 {
     $response = self::$client->get('/')->json();
     $result = new ResultSet($response['results'], $response['meta']);
     $folders = array();
     foreach ($result->results as $folder) {
         $folders[] = Folder::create($folder);
     }
     $this->assertInstanceOf('Ctct\\Components\\ResultSet', $result);
     $this->assertEquals("b2Zmc1V0PTzmbGltaJE9Mo", $result->next);
     $this->assertInstanceOf('Ctct\\Components\\Library\\Folder', $folders[0]);
     $this->assertEquals("-5", $folders[0]->id);
     $this->assertEquals("Folder", $folders[0]->name);
     $this->assertEquals(1, $folders[0]->level);
     $childrenCount = 0;
     foreach ($folders[0]->children as $child) {
         $this->assertInstanceOf('Ctct\\Components\\Library\\Folder', $child);
         $childrenCount++;
     }
     $this->assertEquals(2, $childrenCount);
     $this->assertEquals("-7", $folders[0]->children[0]->id);
     $this->assertEquals("SubFolder", $folders[0]->children[0]->name);
     $this->assertEquals(2, $folders[0]->children[0]->level);
     $this->assertEquals(null, $folders[0]->children[0]->children);
     $this->assertEquals(0, $folders[0]->children[0]->item_count);
     $this->assertEquals("-5", $folders[0]->children[0]->parent_id);
     $this->assertEquals("2014-08-04T11:40:36.000-04:00", $folders[0]->children[0]->modified_date);
     $this->assertEquals("2014-08-04T11:40:36.000-04:00", $folders[0]->children[0]->created_date);
     $this->assertEquals(3, $folders[0]->item_count);
     $this->assertEquals("2013-09-09T14:25:44.000-04:00", $folders[0]->modified_date);
     $this->assertEquals("2013-09-09T14:25:44.000-04:00", $folders[0]->created_date);
 }
 /**
  * Creates a new Library folder
  * @param string $accessToken - Constant Contact OAuth2 token
  * @param Folder $folder
  * @return \Ctct\Components\Library\Folder - Newly created folder
  * @throws CtctException
  */
 public function createLibraryFolder($accessToken, Folder $folder)
 {
     $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.library_folders');
     $request = parent::createBaseRequest($accessToken, "POST", $baseUrl);
     $stream = Stream::factory(json_encode($folder));
     $request->setBody($stream);
     try {
         $response = parent::getClient()->send($request);
     } catch (ClientException $e) {
         throw parent::convertException($e);
     }
     $body = $response->json();
     return Folder::create($body);
 }