PSA: CID Superfecta: source-Telco_Data rendered obsolete

CID Superfecta source-Telco_Data.module has been rendered obsolete by a change at TelcoData.us. The previously free XML query interface now requires an API key, which requires a paid account costing $12.50/mo - $15/mo depending upon term.

While source-Telco_Data.module could theoretically be updated to add a user-defined API key, given the monthly cost of the rate center/state queries I don’t think too many people would be interested in subscribing solely for those queries, given that CNAM dips elsewhere range from $0.002 to $0.006 each.

TelcoData.us provides services that are well worth the subscription price. It’s too bad that there isn’t a low cost “junior” account just for rate center/state queries.

1 Like

Throwing the most recent version of source-Telco_Data.module here for reference. It will be removed at some point. If anyone paying for a key want’s to update it to get it working again, let us know.

<?php

class Telco_Data extends superfecta_base {

    public $description = "http://www.telcodata.com - These listings are generally only return the geographic location of the caller, not a name.";
    public $version_requirement = "2.11";

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

        $caller_id = null;
		$number_error = false;

        $this->DebugPrint("Searching Telco Data ... : {$thenumber}");
        //check for the correct 11 digits in US/CAN phone numbers in international format.
        // country code + number
        if (strlen($thenumber) == 11) {
            if (substr($thenumber, 0, 1) == 1) {
                $thenumber = substr($thenumber, 1);
            } else {
                $number_error = true;
            }
        }
        // international dialing prefix + country code + number
        if (strlen($thenumber) > 11) {
            if (substr($thenumber, 0, 3) == '001') {
                $thenumber = substr($thenumber, 3);
            } else {
                if (substr($thenumber, 0, 4) == '0111') {
                    $thenumber = substr($thenumber, 4);
                } else {
                    $number_error = true;
                }
            }
        }
        // check for short number
        if (strlen($thenumber) < 10) {
            $number_error = true;
        }


        if (!$number_error) {
            $npa = substr($thenumber, 0, 3);
            $nxx = substr($thenumber, 3, 3);

            // check for valid area code (201 or higher)
            if ($npa < '201') {
                $number_error = true;
            } else {
                // Check for Toll-Free numbers (including future TF NPA's)
                $TFnpalist = array(
                    "800", "822", "833", "844", "855", "866", "877", "888"
                );
                if (in_array($npa, $TFnpalist)) {
                    $number_error = true;
                }
            }
        }

        if ($number_error) {
            $this->DebugPrint("Skipping Source - Toll Free or International (non-NANP) number: {$thenumber}");
        } else {
            $url = "http://www.telcodata.us/query/queryexchangexml.html?npa=$npa&nxx=$nxx";
            $value = $this->get_url_contents($url);
			
			$xml = @simplexml_load_string($value);

            if (!$xml && !isset($xml->exchangedata)) {
                $this->DebugPrint("Skipping Source - Telcodata reports invalid NPA/NXX: {$thenumber}");
            } else {
				if(isset($xml->exchangedata->ratecenter) && isset($xml->exchangedata->state)) {
	                $value = (string)$xml->exchangedata->ratecenter . ", " . (string)$xml->exchangedata->state;
	                if (strlen($value) > 2) {
	                    $caller_id = strip_tags($value);
						return($caller_id);
	                }
				}
				$this->DebugPrint("not found");
            }
        }
    }
}