Integration/FourleafIntegration.php
public function doEnhancement(Lead $lead)
    {
        $persist = false;
        if (!empty($lead)) {
            $algo  = $lead->getFieldValue('fourleaf_algo');
            $email = $lead->getEmail();

            if ($algo || !$email) {
                return false;
            }

            $keys = $this->getKeys();

            // @todo - Update to use Guzzle.
            $options = [
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_URL            => $keys['url'].'?ident='.$lead->getEmail(),
                CURLOPT_HTTPHEADER     => [
                    "X-Fourleaf-Id: $keys[id]",
                ],
                CURLOPT_CONNECTTIMEOUT => 2,
                CURLOPT_TIMEOUT        => 3,
            ];

            try {
                $ch = curl_init();
                curl_setopt_array($ch, $options);
                $response = curl_exec($ch);
                curl_close($ch);
            } catch (\Exception $e) {
                $this->handleEnchancerException('FourLeaf', $e);
                $this->logger->error($e->getMessage());

                return false;
            }

            $response = json_decode($response, true);

            if ('ok' === $response['message']) {
                $this->applyCost($lead);
                $data           = $response['data'];
                $allowedAliases = $this->getEnhancerFieldArray();
                unset($data['md5']);
                $data['low_intel'] = (bool) strcasecmp($response['data']['low_intel'], 'false');
                foreach ($data as $key => $value) {
                    $alias = 'fourleaf_'.str_replace('user_', '', $key);
                    if (isset($allowedAliases[$alias])) {
                        $default = $lead->getFieldValue($alias);
                        $lead->addUpdatedField($alias, $value, $default);
                    }
                }
                $persist = true;
            }
        }

        return $persist;
    }
public function doEnhancement(Lead $lead)
    {
        $persist = false;
        if (!empty($lead)) {
            $algo  = $lead->getFieldValue('fourleaf_algo');
            $email = $lead->getEmail();

            if ($algo || !$email) {
                return false;
            }

            $keys = $this->getKeys();

            // @todo - Update to use Guzzle.
            $options = [
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_URL            => $keys['url'].'?ident='.$lead->getEmail(),
                CURLOPT_HTTPHEADER     => [
                    "X-Fourleaf-Id: $keys[id]",
                ],
                CURLOPT_CONNECTTIMEOUT => 2,
                CURLOPT_TIMEOUT        => 3,
            ];

            try {
                $ch = curl_init();
                curl_setopt_array($ch, $options);
                $response = curl_exec($ch);
                curl_close($ch);
            } catch (\Exception $e) {
                $this->handleEnchancerException('FourLeaf', $e);
                $this->logger->error($e->getMessage());

                return false;
            }

            $response = json_decode($response, true);

            if ('ok' === $response['message']) {
                $this->applyCost($lead);
                $data           = $response['data'];
                $allowedAliases = $this->getEnhancerFieldArray();
                unset($data['md5']);
                $data['low_intel'] = (bool) strcasecmp($response['data']['low_intel'], 'false');
                foreach ($data as $key => $value) {
                    $alias = 'fourleaf_'.str_replace('user_', '', $key);
                    if (isset($allowedAliases[$alias])) {
                        $default = $lead->getFieldValue($alias);
                        $lead->addUpdatedField($alias, $value, $default);
                    }
                }
                $persist = true;
            }
        }

        return $persist;
    }
@param Lead $lead

@return bool