diff --git a/sources/source-FccComplaints.module b/sources/source-FccComplaints.module new file mode 100644 index 00000000..b97f24c6 --- /dev/null +++ b/sources/source-FccComplaints.module @@ -0,0 +1,53 @@ +description = "https://opendata.fcc.gov - "._("This module checks for complaints to the fcc against a given phone number"); + $this->source_param = array( + 'SPAM_Threshold' => array( + 'description' => _('Specify the number of listings required to mark a call as spam.'), + 'type' => 'number', + 'default' => 1 + ), + 'API_KEY' => array( + 'description' => _('Optional API token to allow throttling by app rather than IP'), + 'type' => 'text', + 'default' => '' + ) + ); + } + + function get_caller_id($thenumber, $run_param=array()) { + $apikey = isset($run_param['API_KEY'])?$run_param['API_KEY']:''; + $spamcount = isset($run_param['SPAM_Threshold'])?$run_param['SPAM_Threshold']:1; + $caller_id = null; + //http://stackoverflow.com/a/10741461 phone number normalization + $thenumber = preg_replace('~.*(\d{3})[^\d]{0,7}(\d{3})[^\d]{0,7}(\d{4}).*~', '$1-$2-$3', $thenumber); + if (!$this->IsValidNumber("US,CA", $thenumber)) { + $this->DebugPrint(_("Skipping Source - Non US/CAN number").": {$thenumber}"); + } else { + $this->DebugPrint(_("Searching FCC Data source...")); + + $url = "https://opendata.fcc.gov/resource/sr6c-syda.json?caller_id_number=".$thenumber; + if(!empty($apikey)){ + $url .= '&$$app_token='.$apikey; + } + $value = $this->get_url_contents($url); + $data = json_decode($value,true); + $score = count($data); + if ($score >= $spamcount) { + $this->spam = true; + $this->DebugPrint(" "._("determined to be SPAM")); + } else { + $this->DebugPrint(_("Not a SPAM caller")); + } + } + + return($caller_id); + } + +}