public function testModelCreation()
 {
     $this->assertInstanceOf(EmptyModel::class, ModelFactory::create([]));
     $person_configuration = ['$email' => '*****@*****.**', '$first_name' => 'nothing'];
     $person = ModelFactory::create($person_configuration, 'person');
     $this->assertInstanceOf(PersonModel::class, $person);
     $person_json = ModelFactory::createFromJson(json_encode($person_configuration), 'person');
     $this->assertInstanceOf(PersonModel::class, $person_json);
     $this->assertEquals($person, $person_json);
     $person_1 = ModelFactory::callModelCreationMethod('create', $person_configuration, 'person');
     $this->assertInstanceOf(PersonModel::class, $person_1);
     $this->assertEquals($person, $person_1);
     $person_json_1 = ModelFactory::callModelCreationMethod('createFromJson', json_encode($person_configuration), 'person');
     $this->assertInstanceOf(PersonModel::class, $person_json_1);
     $this->assertEquals($person_json, $person_json_1);
 }
예제 #2
0
 /**
  * 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;
     });
 }
예제 #3
0
 /**
  * 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');
 }
예제 #4
0
 /**
  * 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');
 }
예제 #5
0
 /**
  * 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');
 }