<?php

class BulkCNAM extends superfecta_base {

    public $description = "http://www.bulkcnam.com - This module provides lookups from the AsteriskCNAM.com lookup service.";
    public $version_requirement = "2.11";
    public $source_param = array(
        'API_Key' => array(
            'description' => 'API Key gotten from bulkcnam.com',
            'type' => 'text'
        )
    );

    function get_caller_id($thenumber, $run_param=array()) {

        $caller_id = null;

        if (!$this->IsValidNumber(array('US', 'CA'), $thenumber)) {
            $this->DebugPrint("Skipping Source - Not a valid US/CAN number: " . $thenumber);
        } else {
            $this->DebugPrint("Searching BulkCNAM ... ");

            $url = "http://cnam.bulkcnam.com/query-simple.php?id=" . $run_param['API_Key'] . "&did=$thenumber";
            $sname = $this->get_url_contents($url);

            if (strlen($sname) > 1) {
                $caller_id = strip_tags($sname);
            } else {
                $this->DebugPrint("not found");
            }
        }
        return($caller_id);
    }

}