Moved Google Profanity API to it's own repo

It can be found at https://github.com/joshtronic/php-googleprofanity
This commit is contained in:
Josh Sherman 2014-09-23 22:19:45 -04:00
parent 67be4e0889
commit 5f2eaead10
2 changed files with 0 additions and 89 deletions

View file

@ -1,48 +0,0 @@
<?php
/**
* Google Profanity Class File for PICKLES
*
* PHP version 5
*
* Licensed under The MIT License
* Redistribution of these files must retain the above copyright notice.
*
* @author Josh Sherman <josh@gravityblvd.com>
* @copyright Copyright 2007-2014, Josh Sherman
* @license http://www.opensource.org/licenses/mit-license.html
* @package PICKLES
* @link https://github.com/joshtronic/pickles
*/
/**
* Google Profanity API Interface
*/
class API_Google_Profanity
{
/**
* Check
*
* Checks if a word is considered profanity.
*
* @usage API_Google_Profanity::check('fuck'); // returns true
* @param string $word word to check
* @param string $endpoint the endpoint to call (helps testing)
* @return boolean whether or not the word is profanity
*/
public static function check($word, $endpoint = 'http://www.wdyl.com/profanity?q=')
{
$response = json_decode(file_get_contents($endpoint . $word), true);
if ($response == null || !isset($response['response'])
|| !in_array($response['response'], ['true', 'false']))
{
throw new Exception('Invalid response from API.');
}
else
{
return $response['response'] == 'true';
}
}
}

View file

@ -1,41 +0,0 @@
<?php
class API_Google_ProfanityTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider providerFormatPhoneNumber
*/
public function testCheck($a, $b)
{
$this->assertEquals($b, API_Google_Profanity::check($a));
}
public function providerFormatPhoneNumber()
{
return [
['alpha', false],
['beta', false],
['joshtronic', false],
['god', false],
['fck', false],
['fuck', true],
['shit', true],
['cocksucker', true],
['cuntface', false], // Unsure why not...
];
}
/**
* @expectedException Exception
* @expectedExceptionMessage Invalid response from API.
*/
public function testInvalidResponse()
{
$file = SITE_PATH . 'null-';
file_put_contents($file . 'test', null);
API_Google_Profanity::check('test', $file);
}
}