Skip to content

Commit

Permalink
changes in method names
Browse files Browse the repository at this point in the history
  • Loading branch information
marekgach committed Aug 14, 2015
1 parent 132b653 commit 7729835
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 43 deletions.
7 changes: 4 additions & 3 deletions README.md
Expand Up @@ -22,9 +22,10 @@ Here is an example on how to use it:
$chat->disableSendEmailTranscript();
$chat->enableRating('advanced', true);
$chat->setBoxPosition('left', 'side', 20, 120);
$chat->setUserBasicInformation('Johny Depp', 'johny@depp.com');
$chat->addUserExtraInformation('orderTotal', 'Total orders', 150);
$chat->addUserExtraInformation('lastOrder', 'Last ordered', '2015-07-09');
$chat->setName('Johny Depp');
$chat->setEmail('johny@depp.com');
$chat->setVariable('orderTotal', 'Total orders', 150);
$chat->setVariable('lastOrder', 'Last ordered', '2015-07-09');
$chat->setGoogleAnalytics('UA-123456');
$data = $chat->render();
```
37 changes: 17 additions & 20 deletions src/Smartsupp/ChatGenerator.php
Expand Up @@ -15,12 +15,6 @@
*/
class ChatGenerator
{
/**
* @var array Values which are allowed for language param.
*/
protected $allowed_languages = array('en', 'fr', 'es', 'de', 'ru', 'cs', 'sk', 'pl', 'hu', 'cn', 'da', 'nl', 'it',
'pt', 'hi', 'ro', 'no');

/**
* @var array Values which are allowed for ratingType param.
*/
Expand Down Expand Up @@ -52,7 +46,7 @@ class ChatGenerator
protected $cookie_domain = null;

/**
* @var string Chat language. Can have any value from $this->allowed_language.
* @var string Chat language.
*/
protected $language = 'en';

Expand Down Expand Up @@ -150,11 +144,6 @@ public function __construct($key = null)
*/
public function setLanguage($language)
{
if (!in_array($language, $this->allowed_languages)) {
throw new \Exception("Language $language is not allowed value. You can use only one of values: " .
implode(', ', $this->allowed_languages) . ".");
}

$this->language = $language;
}

Expand Down Expand Up @@ -225,16 +214,24 @@ public function enableRating($rating_type = 'simple', $rating_comment = false)
}

/**
* You can send basic information about web visitors from your database to Smartsupp (name, email). So your visitors
* won't be anonymous and your chat agents will see info about every visitor, enabling agents to better focus on VIP
* visitors and provide customized answers.
* You can send visitor name. So your visitors won't be anonymous and your chat agents will see info about every
* visitor, enabling agents to better focus on VIP visitors and provide customized answers.
*
* @param $name User name.
* @param $email User e-mail address.
* @param string $name
*/
public function setUserBasicInformation($name, $email)
public function setName($name)
{
$this->name = $name;
}

/**
* You can send visitor email. So your visitors won't be anonymous and your chat agents will see info about every
* visitor, enabling agents to better focus on VIP visitors and provide customized answers.
*
* @param string $name
*/
public function setEmail($email)
{
$this->email = $email;
}

Expand All @@ -245,7 +242,7 @@ public function setUserBasicInformation($name, $email)
* @param $label Parameter label.
* @param $value Parameter value.
*/
public function addUserExtraInformation($id, $label, $value)
public function setVariable($id, $label, $value)
{
$variable = array('id' => $id, 'label' => $label, 'value' => $value);

Expand All @@ -262,7 +259,7 @@ public function addUserExtraInformation($id, $label, $value)
* @param int $offset_y Offset from top.
* @throws \Exception When params are not correct.
*/
public function setBoxPosition($align_x = 'right', $align_y = 'bottom', $offset_x = 10, $offset_y = 100)
public function setAlign($align_x = 'right', $align_y = 'bottom', $offset_x = 10, $offset_y = 100)
{
if (!in_array($align_x, $this->allowed_align_x)) {
throw new \Exception("AllignX value $align_x is not allowed value. You can use only one of values: " .
Expand Down
33 changes: 13 additions & 20 deletions tests/ChatGeneratorTest.php
Expand Up @@ -77,7 +77,7 @@ public function test_widget_badParam()

public function test_setBoxPosition()
{
$this->chat->setBoxPosition('left', 'side', 20, 120);
$this->chat->setAlign('left', 'side', 20, 120);

$this->assertEquals('left', self::getPrivateField($this->chat, 'align_x'));
$this->assertEquals('side', self::getPrivateField($this->chat, 'align_y'));
Expand All @@ -91,7 +91,7 @@ public function test_setBoxPosition()
*/
public function test_setBoxPosition_badParam()
{
$this->chat->setBoxPosition('foo', 'side', 20, 120);
$this->chat->setAlign('foo', 'side', 20, 120);
}

/**
Expand All @@ -100,13 +100,13 @@ public function test_setBoxPosition_badParam()
*/
public function test_setBoxPosition_badParam2()
{
$this->chat->setBoxPosition('left', 'foo', 20, 120);
$this->chat->setAlign('left', 'foo', 20, 120);
}

public function test_addUserExtraInformation()
public function test_setVariable()
{
$this->chat->addUserExtraInformation('userId', 'User ID', 123);
$this->chat->addUserExtraInformation('orderedPrice', 'Ordered Price in Eshop', '128 000');
$this->chat->setVariable('userId', 'User ID', 123);
$this->chat->setVariable('orderedPrice', 'Ordered Price in Eshop', '128 000');

$this->assertEquals(
array(
Expand All @@ -119,7 +119,8 @@ public function test_addUserExtraInformation()

public function test_setUserBasicInformation()
{
$this->chat->setUserBasicInformation('Johny Depp', 'johny@depp.com');
$this->chat->setName('Johny Depp');
$this->chat->setEmail('johny@depp.com');

$this->assertEquals('Johny Depp', self::getPrivateField($this->chat, 'name'));
$this->assertEquals('johny@depp.com', self::getPrivateField($this->chat, 'email'));
Expand Down Expand Up @@ -178,15 +179,6 @@ public function test_setLanguage()
$this->assertEquals('cs', self::getPrivateField($this->chat, 'language'));
}

/**
* @expectedException \Exception
* @expectedExceptionMessage Language us is not allowed value. You can use only one of values: en, fr, es, de, ru, cs, sk, pl, hu, cn, da, nl, it, pt, hi, ro, no.
*/
public function test_setLanguage_badParam()
{
$this->chat->setLanguage('us');
}

/**
* @expectedException \Exception
* @expectedExceptionMessage At least KEY param must be set!
Expand Down Expand Up @@ -235,11 +227,12 @@ public function test_render_allParams()
$this->chat->setCookieDomain('.foo.bar');
$this->chat->disableSendEmailTranscript();
$this->chat->enableRating('advanced', true);
$this->chat->setBoxPosition('left', 'side', 20, 120);
$this->chat->setAlign('left', 'side', 20, 120);
$this->chat->setWidget('button');
$this->chat->setUserBasicInformation('Johny Depp', 'johny@depp.com');
$this->chat->addUserExtraInformation('orderTotal', 'Total orders', 150);
$this->chat->addUserExtraInformation('lastOrder', 'Last ordered', '2015-07-09');
$this->chat->setName('Johny Depp');
$this->chat->setEmail('johny@depp.com');
$this->chat->setVariable('orderTotal', 'Total orders', 150);
$this->chat->setVariable('lastOrder', 'Last ordered', '2015-07-09');
$this->chat->setGoogleAnalytics('UA-123456', array('cookieDomain' => '.foo.bar'));
$this->chat->hideWidget();

Expand Down

0 comments on commit 7729835

Please sign in to comment.