コード例 #1
0
 public function testAddCreateContactsActivity()
 {
     $response = self::$client->post('/');
     $activity = Activity::create($response->json());
     $this->assertInstanceOf('Ctct\\Components\\Activities\\Activity', $activity);
     $this->assertEquals("a07e1il69qzhdby44ro", $activity->id);
     $this->assertEquals("ADD_CONTACTS", $activity->type);
     $this->assertEquals(0, $activity->error_count);
     $this->assertEquals(1, $activity->contact_count);
 }
コード例 #2
0
 /**
  * Create an Remove Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
  * @param string $accessToken - Constant Contact OAuth2 access token
  * @param string $fileName - The name of the file (ie: contacts.csv)
  * @param string $contents - The contents of the file
  * @param string $lists - Comma separated list of ContactList id' to add the contacts too
  * @return \Ctct\Components\Activities\Activity
  */
 public function addRemoveContactsFromListsActivityFromFile($accessToken, $fileName, $contents, $lists)
 {
     $eol = "\r\n";
     $data = '';
     $boundary = md5(time());
     $data .= '--' . $boundary . $eol;
     $data .= 'Content-Disposition: form-data; name="file_name"' . $eol;
     $data .= 'Content-Type: text/plain' . $eol . $eol;
     $data .= $fileName . $eol;
     $data .= '--' . $boundary . $eol;
     $data .= 'Content-Disposition: form-data; name="lists"' . $eol;
     $data .= 'Content-Type: text/plain' . $eol . $eol;
     $data .= $lists . $eol;
     $data .= '--' . $boundary . $eol;
     $data .= 'Content-Disposition: form-data; name="data"' . $eol . $eol;
     $data .= $contents . $eol;
     $data .= "--" . $boundary . "--" . $eol;
     $headers = array("Authorization: Bearer {$accessToken}", "Content-Type: multipart/form-data; boundary={$boundary}");
     $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.remove_from_lists_activity');
     $url = $this->buildUrl($baseUrl);
     $response = parent::getRestClient()->post($url, $headers, $data);
     return Activity::create(json_decode($response->body, true));
 }
コード例 #3
0
 /**
  * Create a Remove Contacts Activity from a file. Valid file types are txt, csv, xls, xlsx
  * @param string $accessToken - Constant Contact OAuth2 access token
  * @param string $fileName - The name of the file (ie: contacts.csv)
  * @param string $fileLocation - The location of the file on the server, this method uses fopen()
  * @param string $lists - Comma separated list of ContactList id's to add the contacts to
  * @return Activity
  * @throws CtctException
  */
 public function addRemoveContactsFromListsActivityFromFile($accessToken, $fileName, $fileLocation, $lists)
 {
     $baseUrl = Config::get('endpoints.base_url') . Config::get('endpoints.remove_from_lists_activity');
     $request = parent::createBaseRequest($accessToken, "POST", $baseUrl);
     $request->setHeader("Content-Type", "multipart/form-data");
     $body = new PostBody();
     $body->setField("lists", $lists);
     $body->setField("file_name", $fileName);
     $body->addFile(new PostFile("data", fopen($fileLocation, 'r'), $fileName));
     $request->setBody($body);
     try {
         $response = parent::getClient()->send($request);
     } catch (ClientException $e) {
         throw parent::convertException($e);
     }
     return Activity::create($response->json());
 }