public function testGetLibraryFile()
 {
     $curlResponse = CurlResponse::create(JsonLoader::getLibraryFileJson(), array('http_code' => 200));
     $this->restClient->expects($this->once())->method('get')->with()->will($this->returnValue($curlResponse));
     $response = $this->libraryService->getLibraryFile("accessToken", "4");
     $this->assertInstanceOf('Ctct\\Components\\Library\\File', $response);
     $this->assertEquals("IMG_0261.JPG", $response->name);
     $this->assertEquals("4", $response->id);
     $this->assertEquals("chocolates", $response->description);
     $this->assertEquals("Images", $response->folder);
     $this->assertEquals(600, $response->height);
     $this->assertEquals(800, $response->width);
     $this->assertEquals(68825, $response->size);
     $this->assertEquals("https://origin.ih.l1.constantcontact.com/fs115/1100310339939/img/4.jpg", $response->url);
     $this->assertEquals("MyComputer", $response->source);
     $this->assertEquals("Active", $response->status);
     $this->assertInstanceOf('Ctct\\Components\\Library\\Thumbnail', $response->thumbnail);
     $this->assertEquals("https://origin.ih.l1.constantcontact.com/fs115/1100310339939/img/4.jpg", $response->thumbnail->url);
     $this->assertEquals(200, $response->thumbnail->width);
     $this->assertEquals(150, $response->thumbnail->height);
     $this->assertEquals("2013-06-19T11:36:43.000-04:00", $response->created_date);
     $this->assertEquals("2013-08-23T12:54:17.000-04:00", $response->modified_date);
     $this->assertEquals(null, $response->folder_id);
     $this->assertEquals(true, $response->is_image);
     $this->assertEquals("JPG", $response->type);
 }
예제 #2
0
 /**
  * Make an HTTP request
  * @param $url - request url
  * @param $method - HTTP method to use for the request
  * @param array $headers - any http headers that should be included with the request
  * @param string|null $data - payload to send with the request, if any
  * @return CurlResponse
  * @throws CTCTException
  */
 private static function httpRequest($url, $method, array $headers = array(), $data = null)
 {
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $url);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_USERAGENT, "ConstantContact AppConnect PHP Library v1.1");
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
     // add data to send with request if present
     if ($data) {
         curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
     }
     $response = CurlResponse::create(curl_exec($curl), curl_getinfo($curl), curl_error($curl));
     curl_close($curl);
     // check if any errors were returned
     $body = json_decode($response->body, true);
     if (isset($body[0]) && array_key_exists('error_key', $body[0])) {
         $ex = new CtctException($response->body);
         $ex->setCurlInfo($response->info);
         $ex->setErrors($body);
         throw $ex;
     }
     return $response;
 }
 public function testGetVerifiedAddresses()
 {
     $curlResponse = CurlResponse::create(JsonLoader::getVerifiedAddressesJson(), array('http_code' => 200));
     $this->restClient->expects($this->once())->method('get')->with()->will($this->returnValue($curlResponse));
     $response = $this->accountService->getVerifiedEmailAddresses("accessToken", array());
     $this->assertInstanceOf('Ctct\\Components\\Account\\VerifiedEmailAddress', $response[0]);
     $this->assertEquals("*****@*****.**", $response[0]->email_address);
     $this->assertEquals("CONFIRMED", $response[0]->status);
 }
 public function testGetAccessToken()
 {
     $curlResponse = CurlResponse::create(JsonLoader::getAccessTokenJson(), array('http_code' => 200));
     $this->restClient->expects($this->once())->method('post')->with()->will($this->returnValue($curlResponse));
     $token = $this->ctctOAuth2->getAccessToken("fakeCode");
     $this->assertEquals("v6574b42-a5bc-4574-a87f-5c9d1202e316", $token['access_token']);
     $this->assertEquals("308874923", $token['expires_in']);
     $this->assertEquals("Bearer", $token['token_type']);
 }
 public function testSendTest()
 {
     $curlResponse = CurlResponse::create(JsonLoader::getTestSendJson(), array('http_code' => 201));
     $this->restClient->expects($this->once())->method('post')->with()->will($this->returnValue($curlResponse));
     $testSend = $this->campaignScheduleService->sendTest('access_token', "9100367935463", new TestSend());
     $this->assertInstanceOf('Ctct\\Components\\EmailMarketing\\TestSend', $testSend);
     $this->assertEquals("HTML", $testSend->format);
     $this->assertEquals("oh hai there", $testSend->personal_message);
     $this->assertEquals("*****@*****.**", $testSend->email_addresses[0]);
 }
 public function testGetContactsFromList()
 {
     $curlResponse = CurlResponse::create(JsonLoader::getContactsJson(), array('http_code' => 200));
     $this->restClient->expects($this->once())->method('get')->with()->will($this->returnValue($curlResponse));
     $response = $this->listService->getContactsFromList('access_token', 1);
     $this->assertInstanceOf("Ctct\\Components\\ResultSet", $response);
     $contact = $response->results[1];
     $this->assertEquals(231, $contact->id);
     $this->assertEquals("ACTIVE", $contact->status);
     $this->assertEquals("", $contact->fax);
     $this->assertEquals("", $contact->prefix_name);
     $this->assertEquals("Jimmy", $contact->first_name);
     $this->assertEquals("", $contact->middle_name);
     $this->assertEquals("Roving", $contact->last_name);
     $this->assertEquals("Bear Tamer", $contact->job_title);
     $this->assertEquals("Animal Trainer Pro", $contact->company_name);
     $this->assertEquals("details", $contact->source_details);
     $this->assertEquals(false, $contact->confirmed);
     $this->assertEquals("", $contact->source);
     // custom fields
     $this->assertEquals("CustomField1", $contact->custom_fields[0]->name);
     $this->assertEquals("1", $contact->custom_fields[0]->value);
     //addresses
     $this->assertEquals("Suite 101", $contact->addresses[0]->line1);
     $this->assertEquals("line2", $contact->addresses[0]->line2);
     $this->assertEquals("line3", $contact->addresses[0]->line3);
     $this->assertEquals("Brookfield", $contact->addresses[0]->city);
     $this->assertEquals("PERSONAL", $contact->addresses[0]->address_type);
     $this->assertEquals("WI", $contact->addresses[0]->state_code);
     $this->assertEquals("us", $contact->addresses[0]->country_code);
     $this->assertEquals("53027", $contact->addresses[0]->postal_code);
     $this->assertEquals("", $contact->addresses[0]->sub_postal_code);
     //notes
     $this->assertEquals(0, count($contact->notes));
     //lists
     $this->assertEquals(1, $contact->lists[0]->id);
     $this->assertEquals("ACTIVE", $contact->lists[0]->status);
     // EmailAddress
     $this->assertEquals("ACTIVE", $contact->email_addresses[0]->status);
     $this->assertEquals("NO_CONFIRMATION_REQUIRED", $contact->email_addresses[0]->confirm_status);
     $this->assertEquals("ACTION_BY_OWNER", $contact->email_addresses[0]->opt_in_source);
     $this->assertEquals("2012-06-22T10:29:09.976Z", $contact->email_addresses[0]->opt_in_date);
     $this->assertEquals("", $contact->email_addresses[0]->opt_out_date);
     $this->assertEquals("*****@*****.**", $contact->email_addresses[0]->email_address);
 }
 public function testGetAccountInfo()
 {
     $curlResponse = CurlResponse::create(JsonLoader::getAccountInfoJson(), array('http_code' => 200));
     $this->restClient->expects($this->once())->method('get')->with()->will($this->returnValue($curlResponse));
     $response = $this->accountService->getAccountInfo("accessToken");
     $this->assertInstanceOf('Ctct\\Components\\Account\\AccountInfo', $response);
     $this->assertEquals("http://www.example.com", $response->website);
     $this->assertEquals("My Company", $response->organization_name);
     $this->assertEquals("http://www.example.com", $response->website);
     $this->assertEquals("My Company", $response->organization_name);
     $this->assertEquals("US/Eastern", $response->time_zone);
     $this->assertEquals("Mary Jane", $response->first_name);
     $this->assertEquals("Doe", $response->last_name);
     $this->assertEquals("*****@*****.**", $response->email);
     $this->assertEquals("5555555555", $response->phone);
     $this->assertEquals("https://ih.constantcontact.com/fs137/1100371573368/img/90.jpg", $response->company_logo);
     $this->assertEquals("US", $response->country_code);
     $this->assertEquals("MA", $response->state_code);
 }
 public function testGetSummary()
 {
     $curlResponse = CurlResponse::create(JsonLoader::getSummary(), array('http_code' => 200));
     $this->restClient->expects($this->once())->method('get')->with()->will($this->returnValue($curlResponse));
     $summary = $this->campaignTrackingService->getSummary('access_token', 1100394165290);
     $this->assertInstanceOf('Ctct\\Components\\Tracking\\TrackingSummary', $summary);
     $this->assertEquals(15, $summary->sends);
     $this->assertEquals(10, $summary->opens);
     $this->assertEquals(10, $summary->clicks);
     $this->assertEquals(3, $summary->forwards);
     $this->assertEquals(2, $summary->unsubscribes);
     $this->assertEquals(18, $summary->bounces);
 }
 public function testAddCreateContactsActivityFromFile()
 {
     $curlResponse = CurlResponse::create(JsonLoader::getAddContactsActivity(), array('http_code' => 201));
     $this->restClient->expects($this->once())->method('post')->with()->will($this->returnValue($curlResponse));
     $activity = $this->activityService->createAddContactsActivityFromFile("access_token", 'contacts.txt', JsonLoader::getContactsTextContents(), '7');
     $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);
 }
 public function testUpdateContact()
 {
     $curlResponse = CurlResponse::create(JsonLoader::getContactJson(), array('http_code' => 200));
     $this->restClient->expects($this->once())->method('put')->with()->will($this->returnValue($curlResponse));
     $contact = $this->contactService->updateContact('access_token', new Contact(), array());
     $this->assertInstanceOf("Ctct\\Components\\Contacts\\Contact", $contact);
     $this->assertEquals(238, $contact->id);
     $this->assertEquals("ACTIVE", $contact->status);
     $this->assertEquals("555-1212", $contact->fax);
     $this->assertEquals("Mr.", $contact->prefix_name);
     $this->assertEquals("John", $contact->first_name);
     $this->assertEquals("S", $contact->middle_name);
     $this->assertEquals("Smith", $contact->last_name);
     $this->assertEquals("Software Engineer", $contact->job_title);
     $this->assertEquals("Constant Contact", $contact->company_name);
     $this->assertEquals("555-1212", $contact->home_phone);
     $this->assertEquals("555-1213", $contact->work_phone);
     $this->assertEquals("555-1214", $contact->cell_phone);
     $this->assertEquals("69f9d72b-0a5e-479d-b844-722b1da9595f", $contact->source_details);
     $this->assertEquals(false, $contact->confirmed);
     $this->assertEquals("API", $contact->source);
     // custom fields
     $this->assertInstanceOf("Ctct\\Components\\Contacts\\CustomField", $contact->custom_fields[0]);
     $this->assertEquals("CustomField1", $contact->custom_fields[0]->name);
     $this->assertEquals("3/28/2011 11:09 AM EDT", $contact->custom_fields[0]->value);
     $this->assertEquals("CustomField2", $contact->custom_fields[1]->name);
     $this->assertEquals("Site owner", $contact->custom_fields[1]->value);
     //addresses
     $this->assertInstanceOf("Ctct\\Components\\Contacts\\Address", $contact->addresses[0]);
     $this->assertEquals("1601 Trapelo Rd", $contact->addresses[0]->line1);
     $this->assertEquals("Suite 329", $contact->addresses[0]->line2);
     $this->assertEquals("Line 3", $contact->addresses[0]->line3);
     $this->assertEquals("Waltham", $contact->addresses[0]->city);
     $this->assertEquals("PERSONAL", $contact->addresses[0]->address_type);
     $this->assertEquals("MA", $contact->addresses[0]->state_code);
     $this->assertEquals("us", $contact->addresses[0]->country_code);
     $this->assertEquals("01720", $contact->addresses[0]->postal_code);
     $this->assertEquals("7885", $contact->addresses[0]->sub_postal_code);
     //notes
     $this->assertInstanceOf("Ctct\\Components\\Contacts\\Note", $contact->notes[0]);
     $this->assertEquals(1, $contact->notes[0]->id);
     $this->assertEquals("Here are some cool notes to add", $contact->notes[0]->note);
     $this->assertEquals("2012-12-03T17:09:22.702Z", $contact->notes[0]->created_date);
     //lists
     $this->assertInstanceOf("Ctct\\Components\\Contacts\\ContactList", $contact->lists[0]);
     $this->assertEquals(9, $contact->lists[0]->id);
     $this->assertEquals("ACTIVE", $contact->lists[0]->status);
     // EmailAddress
     $this->assertInstanceOf("Ctct\\Components\\Contacts\\EmailAddress", $contact->email_addresses[0]);
     $this->assertEquals("ACTIVE", $contact->email_addresses[0]->status);
     $this->assertEquals("NO_CONFIRMATION_REQUIRED", $contact->email_addresses[0]->confirm_status);
     $this->assertEquals("ACTION_BY_VISITOR", $contact->email_addresses[0]->opt_in_source);
     $this->assertEquals("2012-09-17T14:40:41.271Z", $contact->email_addresses[0]->opt_in_date);
     $this->assertEquals("2012-03-29T14:59:25.427Z", $contact->email_addresses[0]->opt_out_date);
     $this->assertEquals("*****@*****.**", $contact->email_addresses[0]->email_address);
 }
 public function testUpdateCampaign()
 {
     $curlResponse = CurlResponse::create(JsonLoader::getCampaignJson(), array('http_code' => 200));
     $this->restClient->expects($this->once())->method('put')->with()->will($this->returnValue($curlResponse));
     $campaign = $this->emailMarketingService->updateCampaign('access_token', new Campaign());
     $this->assertEquals("1100394165290", $campaign->id);
     $this->assertEquals("CampaignName-05965ddb-12d2-43e5-b8f3-0c22ca487c3a", $campaign->name);
     $this->assertEquals("CampaignSubject", $campaign->subject);
     $this->assertEquals("SENT", $campaign->status);
     $this->assertEquals("From WSPI", $campaign->from_name);
     $this->assertEquals("*****@*****.**", $campaign->from_email);
     $this->assertEquals("*****@*****.**", $campaign->reply_to_email);
     $this->assertEquals("CUSTOM", $campaign->template_type);
     $this->assertEquals("2012-12-06T18:06:05.255Z", $campaign->created_date);
     $this->assertEquals("2012-12-06T18:06:40.342Z", $campaign->last_run_date);
     $this->assertEquals(false, $campaign->is_permission_reminder_enabled);
     $this->assertEquals("", $campaign->permission_reminder_text);
     $this->assertEquals(false, $campaign->is_view_as_webpage_enabled);
     $this->assertEquals("Having trouble viewing this email?", $campaign->view_as_web_page_text);
     $this->assertEquals("Click Here", $campaign->view_as_web_page_link_text);
     $this->assertEquals("Hi", $campaign->greeting_salutations);
     $this->assertEquals("FIRST_NAME", $campaign->greeting_name);
     $this->assertEquals("", $campaign->greeting_string);
     $this->assertEquals("<html><body>Hi <a href=\"http://www.constantcontact.com\">Visit ConstantContact.com!</a> </body></html>", $campaign->email_content);
     $this->assertEquals("HTML", $campaign->email_content_format);
     $this->assertEquals("", $campaign->style_sheet);
     $this->assertEquals("<text>Something to test</text>", $campaign->text_content);
     // message footer
     $this->assertEquals("Waltham", $campaign->message_footer->city);
     $this->assertEquals("MA", $campaign->message_footer->state);
     $this->assertEquals("US", $campaign->message_footer->country);
     $this->assertEquals("WSPIOrgName", $campaign->message_footer->organization_name);
     $this->assertEquals("1601 Trapelo RD", $campaign->message_footer->address_line_1);
     $this->assertEquals("suite 2", $campaign->message_footer->address_line_2);
     $this->assertEquals("box 4", $campaign->message_footer->address_line_3);
     $this->assertEquals("", $campaign->message_footer->international_state);
     $this->assertEquals("02451", $campaign->message_footer->postal_code);
     $this->assertEquals(true, $campaign->message_footer->include_forward_email);
     $this->assertEquals("WSPIForwardThisEmail", $campaign->message_footer->forward_email_link_text);
     $this->assertEquals(true, $campaign->message_footer->include_subscribe_link);
     $this->assertEquals("WSPISubscribeLinkText", $campaign->message_footer->subscribe_link_text);
     // tracking summary
     $this->assertEquals(15, $campaign->tracking_summary->sends);
     $this->assertEquals(10, $campaign->tracking_summary->opens);
     $this->assertEquals(10, $campaign->tracking_summary->clicks);
     $this->assertEquals(3, $campaign->tracking_summary->forwards);
     $this->assertEquals(2, $campaign->tracking_summary->unsubscribes);
     $this->assertEquals(18, $campaign->tracking_summary->bounces);
     // sent to contact lists
     $this->assertEquals(1, count($campaign->sent_to_contact_lists));
     $this->assertEquals(3, $campaign->sent_to_contact_lists[0]->id);
     //click through details
     $this->assertEquals("http://www.constantcontact.com", $campaign->click_through_details[0]->url);
     $this->assertEquals("1100394163874", $campaign->click_through_details[0]->url_uid);
     $this->assertEquals(10, $campaign->click_through_details[0]->click_count);
 }