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 e12ab86 commit 9b7a8b3
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The official Ruby Gem of Greip API
 
[![License: MIT](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/license/apache-2-0)
 
![API Status](https://img.shields.io/website?down_color=orange&down_message=down&label=API%20status&up_color=green&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=green&up_message=up&url=https%3A%2F%greipapi.com)

---

Expand Down Expand Up @@ -58,7 +58,22 @@ puts data

```

### 2. Bulk IP Lookup Method
### 2. IP Threats Method

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

```ruby
require 'greip'

access_token = 'your-api-key-goes-here'
handler = Greip.create(access_token)
data = handler.threats({ ip: "1.1.1.1", mode: "live" })

puts data

```

### 3. Bulk IP Lookup Method

You can use this method to retrieve the information of multiple IP addresses (no need to use the Lookup method inside a loop).

Expand All @@ -73,7 +88,7 @@ data = handler.bulk_lookup({ ips: ["1.1.1.1", "2.2.2.2"], params: ["security", "
puts data
```

### 3. ASN Lookup Method
### 4. ASN Lookup Method

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 @@ -88,7 +103,7 @@ data = handler.asn({ asn: "AS01", mode: "live" })
puts data
```

### 4. Profanity Detection Method
### 5. Profanity Detection Method

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 @@ -103,7 +118,7 @@ data = handler.profanity({ text: "This is just a normal text", lang: "EN", mode:
puts data
```

### 5. Country Lookup Method
### 6. Country Lookup Method

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

Expand All @@ -118,7 +133,7 @@ data = handler.country({ countryCode: "PS", params: ["timezone", "currency"], la
puts data
```

### 6. Email Validation Method
### 7. Email Validation Method

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

Expand All @@ -133,7 +148,7 @@ data = handler.email_validation({ email: "[email protected]", mode: "live" })
puts data
```

### 7. Phone Validation Method
### 8. Phone Validation Method

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 @@ -148,7 +163,7 @@ data = handler.phone_validation({ phone: "1234567890", countryCode: "TR", mode:
puts data
```

### 8. Payment Fraud Prevention Method
### 9. Payment Fraud Prevention Method

Prevent financial losses by deploying AI-Powered modules.

Expand Down Expand Up @@ -225,7 +240,7 @@ data = handler.payment_fraud({ data: payload })
puts data
```

### 9. IBAN Validation Method
### 10. IBAN Validation Method

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

Expand Down
29 changes: 29 additions & 0 deletions lib/greip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,35 @@ def lookup(options)
parsed_response["data"]
end

def threats(options)
ip = options[:ip] || ""
mode = (options[:mode] || "live").downcase

# Validate the ip variable
raise StandardError, ErrorMessages::IP unless ip.length > 5

# Validate the mode variable
mode != "live" && mode != "test" && (raise StandardError, ErrorMessages::MODE)

url = URI(BASE_URL + "/threats?ip=#{ip}&mode=#{mode}&source=Ruby-Gem")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = (url.scheme == "https")

request = Net::HTTP::Get.new(url)
request["Authorization"] = "Bearer #{@token}"

response = http.request(request)

raise StandardError, "Error: #{response.code} - #{response.message}" unless response.code == "200"

parsed_response = JSON.parse(response.body)

raise StandardError, "Error: #{parsed_response["description"]}" unless parsed_response["status"] == "success"

parsed_response["data"]
end

def bulk_lookup(options)
ips = options[:ips] || []
params = options[:params] || []
Expand Down
2 changes: 1 addition & 1 deletion lib/greip/constants.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Greip
BASE_URL = "https://gregeoip.com"
BASE_URL = "https://greipapi.com"

AVAILABLE_LANGUAGES = %w[EN AR DE FR ES JA ZH RU].freeze
AVAILABLE_GEOIP_PARAMS = %w[location security timezone currency device].freeze
Expand Down
2 changes: 1 addition & 1 deletion lib/greip/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Greip
VERSION = "1.1.1"
VERSION = "1.2.0"
end

0 comments on commit 9b7a8b3

Please sign in to comment.