Skip to content

Commit

Permalink
BaseURL changed & adding IP Threats endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
gre-dev committed Mar 14, 2024
1 parent 9519829 commit 019abaa
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 10 deletions.
37 changes: 29 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The official PHP library for Greip API
  
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/Greipio/php?color=brightgreen&label=Size&logo=packagist&logoColor=white)
  
![API Status](https://img.shields.io/website?down_color=orange&down_message=down&label=API%20status&up_color=brightgreen&up_message=up&url=https%3A%2F%2Fgregeoip.com)
![API Status](https://img.shields.io/website?down_color=orange&down_message=down&label=API%20status&up_color=brightgreen&up_message=up&url=https%3A%2F%greipapi.com)
  
[![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/license/apache-2-0)
  
Expand Down Expand Up @@ -57,7 +57,28 @@ $GeoIP_Response = $GeoIP->lookup("1.1.1.1");
print_r($GeoIP_Response);
```

### 2. ASN Lookup
### 2. IP Threats

Use this method to retrieve threat intelligence information associated with a given IP address.

```php
include_once __DIR__ . "/vendor/autoload.php";

// Declaring the classes we need
$config = new Greip\API\Config();
$GeoIP = new Greip\API\GeoIP();

// Setting the API Key
$config->setToken("<API-Key>");

// Sending the request and storing the output in a variable
$GeoIP_Response = $GeoIP->threats("1.1.1.1");

// Printing the response
print_r($GeoIP_Response);
```

### 3. ASN Lookup

In this method, Greip will help you lookup any given AS Number and returning all data related to it, like: name, org (the organization name), country, domain, email, phone, totalIPs, list of all routes (v4 & v6) related the given AS Number, etc.

Expand All @@ -78,7 +99,7 @@ $ASN_Response = $GeoIP->asn("AS01");
print_r($ASN_Response);
```

### 3. Country Lookup
### 4. Country Lookup

This method can help you retrieve information of the given country.

Expand All @@ -99,7 +120,7 @@ $Country_Response = $GeoIP->country("US", ["language", "timezone", "currency"]);
print_r($Country_Response);
```

### 4. Email Validation
### 5. Email Validation

This method provides an additional layer of validation for your system. While validating email syntax is important, it is not sufficient.

Expand All @@ -122,7 +143,7 @@ $Email_Response = $Fraud->email("example@domain.com");
print_r($Email_Response);
```

### 5. Phone Validation
### 6. Phone Validation

This method can be used as an extra-layer of your system for validating phone numbers. It validates phone number syntax and valid-possibility.

Expand All @@ -143,7 +164,7 @@ $Phone_Response = $Fraud->phone("000000000", "US");
print_r($Phone_Response);
```

### 6. Profanity Detection
### 7. Profanity Detection

This method can be used to detect abuse of your website/app. It’s a great way to know more about your user inputs and whether they contain profanity (bad words) or not before releasing them to the public.

Expand All @@ -164,7 +185,7 @@ $Profanity_Response = $Fraud->profanity("This is a sample text", true, false);
print_r($Profanity_Response);
```

### 7. Payment Fraud Prevention
### 8. Payment Fraud Prevention

Prevent financial losses by deploying AI-Powered modules.

Expand Down Expand Up @@ -200,7 +221,7 @@ $Payment_Response = $Fraud->payment($data);
print_r($Payment_Response);
```

### 8. IBAN Validation
### 9. IBAN Validation

This method allows you to validate International Bank Account Numbers (IBANs) and retrieve additional information about the country associated with the IBAN.

Expand Down
2 changes: 1 addition & 1 deletion src/Fraud.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Fraud extends Exception
* @var string $BaseURL Greip's base URL.
* @var string $isError Can be used AFTER MAKING A REQUEST to determine if the API returned an error.
*/
private $BaseURL = "https://gregeoip.com/";
private $BaseURL = "https://greipapi.com/";
public $isError = false;

/**
Expand Down
64 changes: 63 additions & 1 deletion src/GeoIP.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GeoIP extends Exception
* @var string $BaseURL Greip's base URL.
* @var string $isError Can be used AFTER MAKING A REQUEST to determine if the API returned an error.
*/
private $BaseURL = "https://gregeoip.com/";
private $BaseURL = "https://greipapi.com/";
public $isError = false;

/**
Expand Down Expand Up @@ -122,6 +122,68 @@ public function lookup(
}
}

/**
* IP Threats Method
*
* @param string $ip The IP Address you want to retrieve it’s threat intelligence information
* @param string $mode You pass `test` to this variable, so your account plan will not be affected while integrating the library and the API will return fake information for this case. You can set it to `live` again to back to the `production` mode.
* @see https://docs.greip.io/api-reference/endpoint/ip-geolocation/ip-lookup
*
* @return array The $ip threats intelligence information
*/
public function threats($ip, $mode = Mode::LIVE): array
{
$ip = strtoupper($ip);
$mode = strtolower($mode);

$configClass = new Config();

if (!empty($ip)) {
if (!in_array($mode, Mode::values())) {
$this->isError = true;
throw new Exception(
"The mode you specified ($mode) is unknown. You should use `live` or `test`."
);
}

$localParams = [
"ip" => $ip,
"mode" => $mode,
"source" => "PHP-SDK",
];
$ch = curl_init();
curl_setopt(
$ch,
CURLOPT_URL,
$this->BaseURL . "/threats?" . http_build_query($localParams)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"Accept: application/json",
"Authorization: Bearer " . $configClass->getToken(),
]);
$APIResponse = curl_exec($ch);
curl_close($ch);
$decodedResponse = json_decode($APIResponse, true);

if (
is_array($decodedResponse) &&
in_array("status", array_keys($decodedResponse)) &&
$decodedResponse["status"] !== "success"
) {
$this->isError = true;
}

return $decodedResponse;
} else {
$this->isError = true;
throw new Exception(
'The `$ip` parameter is required. You passed an empty value.'
);
}
}

/**
* Country Lookup Method
*
Expand Down

0 comments on commit 019abaa

Please sign in to comment.