public function testGetModelType()
 {
     $person_configuration = ['$email' => '*****@*****.**', '$first_name' => 'nothing'];
     $this->assertSame('person', ModelFactory::getModelType($person_configuration + ['object' => 'person']));
     $this->assertSame('person', ModelFactory::getModelType($person_configuration, 'person'));
     $this->assertSame('', ModelFactory::getModelType([]));
 }
 public function assertModelMatchesConfiguration(ModelInterface $model, $configuration = array())
 {
     if (empty($configuration)) {
         $configuration = $this->configuration;
     }
     $this->assertSame($this->configuration['object'], $model->objectType);
     $this->assertSame($this->configuration['id'], $model->id);
     $this->assertSame($this->configuration['name'], $model->name);
     $this->assertSame($this->configuration['subject'], $model->subject);
     $this->assertSame($this->configuration['from_email'], $model->fromEmail);
     $this->assertSame($this->configuration['from_name'], $model->fromName);
     $template = ModelFactory::create($this->configuration['template']);
     $this->assertEquals($template, $model->template);
     $this->assertSame($this->configuration['status'], $model->status);
     $this->assertSame($this->configuration['status_id'], $model->statusId);
     $this->assertSame($this->configuration['status_label'], $model->statusLabel);
     $this->assertSame($this->configuration['sent_at'], $model->sentAt);
     $this->assertSame($this->configuration['send_time'], $model->sendTime);
     $created = new \DateTime($this->configuration['created']);
     $this->assertEquals($created, $model->created);
     $updated = new \DateTime($this->configuration['updated']);
     $this->assertEquals($updated, $model->updated);
     $this->assertEquals($this->configuration['num_recipients'], $model->numRecipients);
     $this->assertEquals($this->configuration['is_segmented'], $model->isSegmented);
     $this->assertEquals($this->configuration['campaign_type'], $model->campaignType);
     $lists = [];
     foreach ($configuration['lists'] as $list) {
         $lists[] = ModelFactory::create($list);
     }
     $this->assertEquals($lists, $model->lists);
 }
 /**
  * Register our model factory creation from JSON with the container.
  */
 protected function registerModelFactoryCreateFromJson(Container $container)
 {
     $self = $this;
     $container['model.factory.json'] = $container->factory(function ($c) use($self) {
         $json = $c['model.factory.json.params']['json'];
         $type = $c['model.factory.json.params']['type'];
         $model = ModelFactory::createFromJson($json, $type);
         $self->registerModelFactoryDefaultParams($c);
         return $model;
     });
 }
 /**
  * Create a new campaign.
  *
  * @param array $configuration
  *   An array of configuration parameters for the new campaign.
  *
  *   Allowed elements:
  *   * list_id: string
  *     The ID of the List object you will send this campaign to.
  *   * template_id: string
  *     The ID of the Email Template object that will be the content of this
  *     campaign. Note the Email Template is copied when creating this
  *     campaign, so future changes to that Email Template will not alter the
  *     content of this campaign.
  *   * from_email: string
  *     The email address your email will be sent from and will be used in the
  *     reply-to header.from_namestringThe name or label associated with the
  *     email address you're sending from.
  *   * subject: string
  *   * name (optional): string
  *     A name for this campaign. If not specified, this will default to the
  *     subject of the campaign.
  *   * use_smart_sending (optional): boolean
  *     If set, limits the number of emails sent to an individual within a
  *     short period. If not specified, defaults to True.
  *   * add_google_analytics (optional): boolean
  *     If specified, adds Google Analytics tracking tags to links. If not
  *     specified, defaults to False.
  *
  * @return CampaignModel
  *   The newly created campaign object.
  */
 public function createCampaign($configuration)
 {
     $response = $this->api->request('POST', $this->getResourcePath('campaigns'), $configuration);
     return ModelFactory::createFromJson($response->getBody()->getContents(), 'campaign');
 }
 /**
  * Add a person to an existing List.
  *
  * @param ListModel $list
  *   The ListModel for which to add the person.
  * @param PersonModel $person
  *   The PersonModel of the person to add to a List.
  * @param bool $confirm_opt_in
  *   Default to TRUE. Determines if the person should be asked to confirm
  *   subscribing to list. When TRUE the person will recieve an email with a
  *   confirmation link before zhe is added to the list. Otherwise, when FALSE
  *   the person is automatically added to the list.
  *
  * @return PersonListModel
  *   The PersonList wrapper provided by the Klaviyo API.
  */
 public function addPersonToList(ListModel $list, PersonModel $person, $confirm_opt_in = TRUE)
 {
     $options = ['email' => $person->email, 'properties' => json_encode($person), 'confirm_optin' => $confirm_opt_in ? 'true' : 'false'];
     $response = $this->api->request('POST', $this->getResourcePath("list/{$list->id}/members"), $options);
     return ModelFactory::createFromJson($response->getBody()->getContents(), 'person_list');
 }
 /**
  * Update the specified template.
  *
  * @param TemplateModel $template
  *   The template object to update.
  *
  * @return TemplateModel
  *   The updated template object.
  */
 public function updateTemplate(TemplateModel $template)
 {
     $options = ['name' => $template->name, 'html' => $template->html->saveHtml()];
     $response = $this->api->request('PUT', $this->getResourcePath("email-template/{$template->id}"), $options);
     return ModelFactory::createFromJson($response->getBody()->getContents(), 'email-template');
 }
Example #7
0
 /**
  * Retrieve a specific page from Klaviyo.
  *
  * @param int $page
  *   The page number to retrieve.
  * @param int $count
  *   The number of items per page.
  *
  * @return array
  *   An array of information that represents a page.
  */
 public function getPage($resource, $page = 0, $count = 50, $query_parameters = [])
 {
     $options = ['query' => ['page' => $page, 'count' => $count] + $query_parameters];
     $response = $this->getApi()->request('GET', $resource, $options);
     return ModelFactory::create(json_decode($response->getBody()->getContents(), TRUE), 'page');
 }