Skip to content

Commit

Permalink
Add FCC spam source
Browse files Browse the repository at this point in the history
  • Loading branch information
jfinstrom authored and tm1000 committed Jun 8, 2016
1 parent 865216a commit f1d69e1
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions sources/source-FccComplaints.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

class FccComplaints extends superfecta_base {

public $description, $source_param;
public $version_requirement = "2.11";

public function __construct() {
$this->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);
}

}

0 comments on commit f1d69e1

Please sign in to comment.