Skip to content

Commit

Permalink
Merge pull request #1 from ditointernet/NASA-47
Browse files Browse the repository at this point in the history
[NASA-47] Criar método link
  • Loading branch information
pdropaiva authored Feb 2, 2018
2 parents c980982 + d4ddb1b commit 5fdcd63
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
30 changes: 24 additions & 6 deletions examples/identify.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,27 @@
// )
// ));

$dito->track(array(
'facebook_id' => '10202840988483394',
'event' => array(
'action' => 'acao-teste'
)
));
// $dito->track(array(
// 'facebook_id' => '10202840988483394',
// 'event' => array(
// 'action' => 'acao-teste'
// )
// ));

// $dito->identify(array(
// 'id' => 3123123321,
// 'name' => 'Pedro Paiva',
// 'email' => 'pedro.paiva@dito.com.br',
// 'data' => array(
// 'cargo' => 'Desenvolvedor'
// )
// ));

// $dito->link(array(
// 'id' => 3123123321,
// 'accounts' => array(
// 'portal' => array(
// 'id' => 10202840988483394,
// )
// )
// ));
28 changes: 26 additions & 2 deletions lib/Dito.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function track($options = array()){

if(!isset($id)){
return array(
'error' => array('message' => 'Missing the user id param. See the available options here: http://developers.dito.com.br/docs/sdks/ruby')
'error' => array('message' => 'Missing the user id param. See the available options here: http://developers.dito.com.br/docs/php-sdk')
);
}

Expand All @@ -151,30 +151,54 @@ public function track($options = array()){
return $this->request('post', 'events', '/users/'. $id, $params);
}

public function link($options = array()) {
$credentials = $this->generateIDAndIDType($options);
$id = $credentials['id'];
$idType = $credentials['idType'];
$networkName = $credentials['networkName'];

if(!isset($id)){
return array(
'error' => array('message' => 'Missing the user id param. See the available options here: http://developers.dito.com.br/docs/php-sdk')
);
}

$params = array('accounts' => json_encode($options['accounts']));
if(isset($idType)) $params['id_type'] = $idType;
if(isset($networkName)) $params['network_name'] = $networkName;

return $this->request('post', 'login', "/users/{$id}/link", $params);
}

private

function generateIDAndIDType($options = array()){
if(isset($options['reference'])){
$id = $options['reference'];
$idType = nil;
$networkName = nil;
}
else if(isset($options['facebook_id'])){
$id = $options['facebook_id'];
$idType = 'facebook_id';
$networkName = 'fb';
}
else if(isset($options['google_plus_id'])){
$id = $options['google_plus_id'];
$idType = 'google_plus_id';
$networkName = 'pl';
}
else if(isset($options['twitter_id'])){
$id = $options['twitter_id'];
$idType = 'twitter_id';
$networkName = 'tw';
}
else if(isset($options['id'])){
$id = $options['id'];
$idType = 'id';
$networkName = 'pt';
}

return array('id' => $id, 'idType' => $idType);
return array('id' => $id, 'idType' => $idType, 'networkName' => $networkName);
}
}

0 comments on commit 5fdcd63

Please sign in to comment.