From d4ddb1bec23a40f1bd76414033d02b766e6e811b Mon Sep 17 00:00:00 2001 From: Pedro Paiva Date: Thu, 25 Jan 2018 16:28:36 -0200 Subject: [PATCH] =?UTF-8?q?[NASA-47]=20Criar=20m=C3=A9todo=20link?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/identify.php | 30 ++++++++++++++++++++++++------ lib/Dito.php | 28 ++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/examples/identify.php b/examples/identify.php index 9e8944e..f8f9562 100644 --- a/examples/identify.php +++ b/examples/identify.php @@ -30,9 +30,27 @@ // ) // )); -$dito->track(array( - 'facebook_id' => '10202840988483394', - 'event' => array( - 'action' => 'acao-teste' - ) -)); \ No newline at end of file +// $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, +// ) +// ) +// )); \ No newline at end of file diff --git a/lib/Dito.php b/lib/Dito.php index bc88ba7..9d2b0ec 100644 --- a/lib/Dito.php +++ b/lib/Dito.php @@ -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') ); } @@ -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); } }