class Ipfinder::Ipfinder

The IPfinder library main class. @author Mohamed Ben rebia <mohamed@ipfinder.io> @see ipfinder.io @since 1.0.0

Constants

DEFAULT_API_TOKEN

Public: String The free token

DEFAULT_BASE_URL

Public: [String] DEFAULT BASE URL

DOMAIN_BY_PATH

Public: String Domain By ASN, Country,Ranges path

DOMAIN_H_PATH

Public: String Domain IP history path

DOMAIN_PATH

Public: String Domain IP path

FIREWALL_PATH

Public: String Firewall path

FORMAT

Public: String DEFAULT FORMAT

RANGES_PATH

Public: String IP Address Ranges path

STATUS_PATH

Public: String service status path

Public Class Methods

new(token = nil, baseUrl = nil) click to toggle source

Constructor

@param token [String] your token @param baseUrl [String] proxy pass @raise [IPfinderException]

# File lib/ipfinder.rb, line 61
  def initialize(token = nil, baseUrl = nil)
    if token.nil?
      @token = DEFAULT_API_TOKEN
    else
      Tokenvalidation.validate(token)
      @token = token
end

    @baseUrl = if baseUrl.nil?
                 DEFAULT_BASE_URL
               else
                 baseUrl
               end
      end

Public Instance Methods

Authentication() click to toggle source

Get details for an Your IP address. @return Your IP address data. @example

API.Authentication()
# File lib/ipfinder.rb, line 130
def Authentication
  call('', '')
end
call(path = nil, format = nil) click to toggle source

Make the call to server

@param path [String] specific path of asn, IP address, ranges, Firewall,Token status @param format [String] available format `json` `jsonp` `php` `xml` @raise [IPfinderException] @return Your IP address data. @example

API.call("google.com", 'php')
# File lib/ipfinder.rb, line 84
def call(path = nil, format = nil)
  @format = if format.nil?
              FORMAT
            else
              format
            end

  @path = if path.nil?
            ''
          else
            path
          end

  @endpoint = @baseUrl + @path

  uri = URI.parse(@endpoint)
  request = Net::HTTP::Post.new(uri)
  request.content_type = 'application/json'
  request['User-Agent'] = 'IPfinder ruby-client'
  request.body = JSON.dump(
    'token' => @token,
    'format' => @format
  )

  req_options = {
    use_ssl: uri.scheme == 'https'
  }

  response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
    http.request(request)
  end

  if response.code != '200'
    raise IPfinderException, "\nURL: #{@endpoint} => status code: #{response.code} \n" + response.body
    puts
  end

  details = JSON.parse(response.body, symbolize_names: true)

  Info.new(details)
end
getAddressInfo(path) click to toggle source

Get details for an IP address.

@param path [String] IP address. @raise [IPfinderException] @return IP address data. @example

API.getAddressInfo('(IPV4|IPV6)')
# File lib/ipfinder.rb, line 141
def getAddressInfo(path)
  Ipvalidation.validate(path)
  call(path)
end
getAsn(path) click to toggle source

Get details for an AS number.

@param path [String]AS number. @raise [IPfinderException] @return AS number data. @example

API.getAsn('AS1')
# File lib/ipfinder.rb, line 153
def getAsn(path)
  Asnvalidation.validate(path)
  call(path)
end
getDomain(path) click to toggle source

Get Domain IP @param path [String] The API supports passing in a single website name domain name @return Domain to IP data. @example

API.getDomain('google.com')
# File lib/ipfinder.rb, line 195
def getDomain(path)
  Domainvalidation.validate(path)
  call(DOMAIN_PATH + path)
end
getDomainBy(by) click to toggle source

Get list Domain By ASN, Country,Ranges

@param by [String] by The API supports passing in a single ASN,Country,Ranges @return Get list Domain By ASN, Country,Ranges @example

API.getDomain('DZ')
# File lib/ipfinder.rb, line 218
def getDomainBy(by)
  call(DOMAIN_BY_PATH + by)
end
getDomainHistory(path) click to toggle source

Get Domain History

@param path [String] The API supports passing in a single website name domain name @raise [IPfinderException] @return Domain History data. @example

API.getDomain('google.com')
# File lib/ipfinder.rb, line 207
def getDomainHistory(path)
  Domainvalidation.validate(path)
  call(DOMAIN_H_PATH + path)
end
getFirewall(by, format) click to toggle source

Get Firewall data

@param by [String] AS number, alpha-2 country only. @param format [String] formats list formats supported @raise [IPfinderException] @return Firewall data. @example

API.getFirewall("DZ",'nginx_deny')
# File lib/ipfinder.rb, line 185
def getFirewall(by, format)
  Firewallvalidation.validate(by, format)
  call(FIREWALL_PATH + by, format)
end
getRanges(path) click to toggle source

Get details for an Organization name.

@param path [String] Organization name. @return Organization name data. @example

API.getRanges('Telecom Algeria')
# File lib/ipfinder.rb, line 172
def getRanges(path)
  @urlencode = URI.encode(path)
  call(RANGES_PATH + @urlencode)
end
getStatus() click to toggle source

Get details for an API Token . @return The Token data. @example

API.getStatus()
# File lib/ipfinder.rb, line 162
def getStatus
  call(STATUS_PATH)
end