Skip to content

Commit

Permalink
Merge pull request #2 from fabianocouto/master
Browse files Browse the repository at this point in the history
Class internationalization
  • Loading branch information
fabianocouto authored Apr 19, 2017
2 parents c6b4c2b + 1d69654 commit 25d908a
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
54 changes: 45 additions & 9 deletions RDStation/RDStation.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,33 @@ private function __apiURL($api = 'conversions') {
}
}

/**
* TRANSLATE LEAD DATA
*
* @return void
*/
private function __translateLeadData() {

$data = array('identifier' => 'identificador',
'name' => 'nome',
'title' => 'cargo',
'company' => 'empresa',
'phone' => 'telefone',
'cell_phone' => 'celular',
'state' => 'estado',
'city' => 'cidade');

foreach ($this->__leadData as $key => $value) {

if (isset($data[$key])) {

unset($this->__leadData[$key]);

$this->__leadData[$data[$key]] = $value;
}
}
}

/**
* SET LEAD EMAIL
*
Expand Down Expand Up @@ -223,9 +250,8 @@ public function setApiToken($apiToken) {
*
* Default Lead Data:
*
* identificador, nome, cargo, empresa, cargo
* telefone, celular, estado, cidade, website
* twitter, c_utmz, traffic_source, cliente_id, tags
* identifier, name, title, company, phone, cell_phone, city, state
* website, twitter, c_utmz, traffic_source, cliente_id, tags
*
* Custom lead data can be set end send to RD Station
*
Expand All @@ -245,11 +271,11 @@ public function setLeadData($param, $value) {
*
* Required Lead Data
*
* identificador (Identifier of the conversion event)
* identifier (Identifier of the conversion event)
*
* Optional Lead Data
*
* nome, cargo, empresa, cargo, telefone, celular, estado, cidade
* name, title, company, phone, cell_phone, city, state
* website, twitter, c_utmz, traffic_source, cliente_id, tags
*
* Custom lead data can be set end send to RD Station
Expand All @@ -270,14 +296,16 @@ public function sendLead() {
throw new \Exception("Lead email must be setted!");
}

if (!isset($this->__leadData['identificador'])) {
throw new \Exception("Lead data 'identificador' must be setted!");
if (!isset($this->__leadData['identifier'])) {
throw new \Exception("Lead data 'identifier' must be setted!");
}

/////////////////////////////////////////////////////////////////////
// PREPARE DATA COLLECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

$this->__translateLeadData();

$this->__leadData['token_rdstation'] = $this->__apiToken;
$this->__leadData['email'] = $this->__leadEmail;

Expand All @@ -293,7 +321,7 @@ public function sendLead() {
*
* Optional Lead Data
*
* nome, cargo, empresa, cargo, telefone, celular, estado, cidade
* name, title, company, phone, cell_phone, city, state
* website, twitter, c_utmz, traffic_source, cliente_id, tags
*
* Custom lead data can be set end send to RD Station
Expand All @@ -318,6 +346,8 @@ public function updateLead() {
// PREPARE DATA COLLECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

$this->__translateLeadData();

$leadData = array();
$leadData['auth_token'] = $this->__apiPrivateToken;
$leadData['lead'] = $this->__leadData;
Expand Down Expand Up @@ -362,6 +392,8 @@ public function sendLeadTags() {
// PREPARE DATA COLLECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

$this->__translateLeadData();

$this->__leadData['auth_token'] = $this->__apiPrivateToken;

/////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -406,6 +438,8 @@ public function updateLeadStage() {
// PREPARE DATA COLLECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

$this->__translateLeadData();

$lead = array();

if (isset($this->__leadData['lifecycle_stage'])) {
Expand Down Expand Up @@ -465,6 +499,8 @@ public function updateLeadStatus() {
// PREPARE DATA COLLECTION //////////////////////////////////////////
/////////////////////////////////////////////////////////////////////

$this->__translateLeadData();

$this->__leadData['email'] = $this->__leadEmail;

/////////////////////////////////////////////////////////////////////
Expand All @@ -473,4 +509,4 @@ public function updateLeadStatus() {

return $this->__request('POST', 'generic');
}
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ require_once(dirname(__FILE__) . '/init.php');

$rdStation = new \RDStation\RDStation('LEAD_EMAIL');
$rdStation->setApiToken('RD_TOKEN');
$rdStation->setLeadData('identificador', 'event-identifier');
$rdStation->setLeadData('nome', 'Fabiano Couto');
$rdStation->setLeadData('identifier', 'event-identifier');
$rdStation->setLeadData('name', 'Fabiano Couto');

// You can set all RD Station default fields and add custom fields as you want
// Read more about on http://ajuda.rdstation.com.br/hc/pt-br
Expand Down
10 changes: 5 additions & 5 deletions examples/sendLead.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
$rdStation = new \RDStation\RDStation('LEAD_EMAIL');
$rdStation->setApiToken('RD_TOKEN');

$rdStation->setLeadData('identificador', 'event-identifier');
$rdStation->setLeadData('nome' , 'Fabiano Couto');
$rdStation->setLeadData('cargo' , 'Webdeveloper');
$rdStation->setLeadData('cidade' , 'Rio de Janeiro');
$rdStation->setLeadData('estado' , 'RJ');
$rdStation->setLeadData('identifier', 'event-identifier');
$rdStation->setLeadData('name' , 'Fabiano Couto');
$rdStation->setLeadData('title' , 'Systems Analyst');
$rdStation->setLeadData('city' , 'Natal');
$rdStation->setLeadData('state' , 'RN');

$response = $rdStation->sendLead();

Expand Down
8 changes: 4 additions & 4 deletions examples/updateLead.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
$rdStation = new \RDStation\RDStation('LEAD_EMAIL');
$rdStation->setApiPrivateToken('RD_PRIVATE_TOKEN');

$rdStation->setLeadData('nome' , 'Fabiano Couto');
$rdStation->setLeadData('cargo' , 'Webdeveloper');
$rdStation->setLeadData('cidade' , 'Rio de Janeiro');
$rdStation->setLeadData('estado' , 'RJ');
$rdStation->setLeadData('name' , 'Fabiano Couto');
$rdStation->setLeadData('title', 'Webdeveloper');
$rdStation->setLeadData('city' , 'Rio de Janeiro');
$rdStation->setLeadData('state', 'RJ');

$response = $rdStation->updateLead();

Expand Down

0 comments on commit 25d908a

Please sign in to comment.