Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Deinhamer committed Jun 26, 2015
2 parents 3489f30 + eadba4d commit 9c1ebaa
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 23 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ indent_style = space
indent_size = 2
trim_trailing_whitespace = false

[*.yml]
indent_style = space
indent_size = 2

[composer.json]
indent_style = space
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- hhvm

before_install:
- composer self-update

install:
- composer install

script: phpunit tests
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Change Log

## [0.1.0] - 2015-06-25
## [Next][next]

## [0.1.1] - 2015-06-26

### Added
- Travis configuration for CI.

### Fixed
- Fix infinitely nested function calls.
- Add some missing docblock tags.
- Clean up change log.

## 0.1.0 - 2015-06-25

Initial release.

[next]: https://github.com/thasmo/vagrant.box/compare/v0.1.1...HEAD
[0.1.1]: https://github.com/thasmo/php.honeypot-blacklist/compare/v0.1.0...v0.1.1
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

A simple PHP library for querying the [Project Honeypot Http:BL API](http://www.projecthoneypot.org/httpbl_api.php).

[![Build Status](https://travis-ci.org/thasmo/php.honeypot-blacklist.svg?branch=develop)](https://travis-ci.org/thasmo/php.honeypot-blacklist)

## Usage

### Create a new instance
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thasmo/honeypot-blacklist",
"description": "",
"description": "A simple PHP library for querying the Project Honeypot Http:BL API.",
"type": "library",
"keywords": ["honeypot", "blacklist", "spam", "api", "http"],
"license": "MIT",
Expand Down
47 changes: 26 additions & 21 deletions src/Blacklist.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Blacklist {
* Default API key to use.
* @var string
*/
protected static $defaultKey = NULL;
protected static $defaultKey = NULL;

/**
* API key to use.
Expand Down Expand Up @@ -81,15 +81,15 @@ class Blacklist {
* @param string $address
* @param string $key
*/
public function __construct($address, $key = NULL) {
public function __construct($address, $key = NULL) {
$this->setAddress($address);

if(!$key) {
$key = static::getDefaultKey();
}

$this->setKey($key);
}
}

/**
* Validate an API key.
Expand Down Expand Up @@ -128,6 +128,7 @@ public static function getDefaultKey() {
/**
* Set the default API key.
* @param $key
* @return void
*/
public static function setDefaultKey($key) {
if(!static::validateKey($key)) {
Expand All @@ -139,23 +140,25 @@ public static function setDefaultKey($key) {

/**
* Reset the default API key.
*/
* @return void
*/
public static function unsetDefaultKey() {
static::$defaultKey = NULL;
}

/**
* Get the API key.
* @return string|NULL
*/
*/
public function getKey() {
return $this->key;
}

/**
* Set the API key.
* @param string $key
*/
* @return void
*/
public function setKey($key) {
if(!static::validateKey($key)) {
throw new InvalidArgumentException('API key is invalid.');
Expand All @@ -167,15 +170,16 @@ public function setKey($key) {
/**
* Get the IP address.
* @return string|NULL
*/
*/
public function getAddress() {
return $this->address;
}

/**
* Set the IP address.
* @param string $address
*/
* @return void
*/
public function setAddress($address) {
if(!static::validateAddress($address)) {
throw new InvalidArgumentException('IP address is invalid.');
Expand Down Expand Up @@ -209,7 +213,7 @@ public function getResult($key = NULL) {
* Indicate whether the IP address refers to a search engine or not.
* @param int $type
* @return bool
*/
*/
public function isSearchEngine($type = NULL) {
$this->query();

Expand All @@ -227,7 +231,7 @@ public function isSearchEngine($type = NULL) {
/**
* Indicate whether the API address is known for suspicious behavior or not.
* @return bool
*/
*/
public function isListed() {
$this->query();
return (bool) ($this->getType() > static::TYPE_SEARCH_ENGINE);
Expand All @@ -236,7 +240,7 @@ public function isListed() {
/**
* Indicate whether the IP address is suspicious or not.
* @return bool
*/
*/
public function isSuspicious() {
$this->query();
return (bool) ($this->getType() & static::TYPE_SUSPICIOUS);
Expand All @@ -245,7 +249,7 @@ public function isSuspicious() {
/**
* Indicate whether the IP address refers to a harvester or not.
* @return bool
*/
*/
public function isHarvester() {
$this->query();
return (bool) ($this->getType() & static::TYPE_HARVESTER);
Expand All @@ -254,7 +258,7 @@ public function isHarvester() {
/**
* Indicate whether the IP address refers to a spammer or not.
* @return bool
*/
*/
public function isSpammer() {
$this->query();
return (bool) ($this->getType() & static::TYPE_SPAMMER);
Expand All @@ -263,7 +267,7 @@ public function isSpammer() {
/**
* Get the IP's last activity in days.
* @return int|NULL
*/
*/
public function getActivity() {
$this->query();
return $this->getResult('activity');
Expand All @@ -272,7 +276,7 @@ public function getActivity() {
/**
* Get the IP's threat score.
* @return int
*/
*/
public function getThreat() {
$this->query();
return $this->getResult('threat');
Expand All @@ -281,7 +285,7 @@ public function getThreat() {
/**
* Get the IP's type.
* @return int
*/
*/
public function getType() {
$this->query();
return $this->getResult('type');
Expand All @@ -291,7 +295,7 @@ public function getType() {
* Check if the IP was active within the given number of days.
* @param int $days
* @return bool
*/
*/
public function isActive($days) {
$this->query();
return $days >= $this->getActivity();
Expand All @@ -301,7 +305,7 @@ public function isActive($days) {
* Check if the IP's threat score is within in the given score.
* @param int $threat
* @return bool
*/
*/
public function isThreat($threat) {
$this->query();
return $threat <= $this->getThreat();
Expand All @@ -310,7 +314,7 @@ public function isThreat($threat) {
/**
* Get the IP's search engine name if applicable.
* @return bool|FALSE
*/
*/
public function getName() {
$this->query();

Expand All @@ -334,7 +338,7 @@ public function getName() {
*/
public function query($force = FALSE) {
if($this->queried && !$force) {
return $this->getResult();
return $this->result;
}

# format address
Expand Down Expand Up @@ -405,7 +409,8 @@ protected function formatResult($result) {

/**
* Reset the state of the object.
*/
* @return void
*/
protected function reset() {
$this->result = NULL;
$this->queried = FALSE;
Expand Down

0 comments on commit 9c1ebaa

Please sign in to comment.