class RubyIpClient::IpClient
Public Class Methods
Initializes the IP Lookup Client @param username - www.ip-lookups.com username @param password - www.ip-lookups.com password @constructor
# File lib/ruby_ip_client/ip_client.rb, line 12 def initialize(username, password) @username = username @password = password @url = "https://www.ip-lookups.com/api" end
Public Instance Methods
Returns the remaining balance (EUR) in your account. @returns string (JSON)
Return example: {“success”:true,“results”:{“balance”:“5878.24600”}}
# File lib/ruby_ip_client/ip_client.rb, line 94 def get_balance send_request({ :action => 'getBalance', :username => @username, :password => @password }) end
Sets the callback URL for asynchronous IP lookups. Read more about the concept of asynchronous IP lookups @ www.ip-lookups.com/en/asynchronous-ip-lookup-api @param url - callback url on your server @returns string (JSON)
Return example: {“success”:true,“results”:{“url”:“//user:pass@www.your-server.com/path/file”}}
# File lib/ruby_ip_client/ip_client.rb, line 79 def set_async_callback_url(url) send_request({ :action => 'setAsyncCallbackUrl', :url => url, :username => @username, :password => @password }) end
Submits asynchronous IP Lookups containing up to 1,000 IPs per request. Results are sent back asynchronously to a callback URL on your server. @param ips - A list of IPv4 or IPv6 addresses @param engine - An optional engine assignment, see: www.ip-lookups.com/en/data-source-engines @param storage - An optional storage assignment, see: www.ip-lookups.com/en/storages @returns string (JSON)
Return example: {“success”:true,“results”:{“acceptedIps”:,“rejectedIps”:[],“acceptedIpCount”:3,“rejectedIpCount”:0,“totalCount”:3,“cost”:0.03,“storage”:“ASYNC-API-2017-02”,“engine”:“IV1”}}
# File lib/ruby_ip_client/ip_client.rb, line 53 def submit_async_lookup(ips, engine = nil, storage = nil) params = { :action => 'submitAsyncLookup', :ips => ips_to_string(ips), :username => @username, :password => @password } unless engine.nil? params.merge!(engine: engine) end unless storage.nil? params.merge!(storage: storage) end send_request(params) end
Submits a synchronous IP Lookup request. The IP is queried in real time and results presented in the response body. @param ip - An IPv4 or IPv6 address @param engine - An optional engine assignment, see: www.ip-lookups.com/en/data-source-engines @param storage - An optional storage assignment, see: www.ip-lookups.com/en/storages @returns string (JSON)
Return example: {“success”:true,“results”:{“context”:{“id”:“7044a161c662”,“ip”:“23.105.134.61”,“state”:“COMPLETED”,“storage”:“SYNC-API-2017-02”,“engine”:“IV1”,“interface”:“Sync API”,“cost”:“0.01000”,“timeStamp”:“2017-02-18 18:27:50.267098+08”},“geolocation”:{“country”:“United States”,“region”:“Arizona”,“countryCode”:“US”,“regionCode”:“AZ”,“city”:“Phoenix”,“zip”:“85054”,“latitude”:“33.67480”,“longitude”:“-111.95190”,“radius”:1000,“timeZone”:“America/Phoenix”,“averageIncome”:null,“populationDensity”:null,“dmaCode”:753},“network”:{“connectionType”:“HOSTING”,“asn”:“15003”,“asnOrganization”:“Nobis Technology Group, LLC”,“isp”:“Nobis Technology Group, LLC”,“ispOrganization”:“Nobis Technology Group, LLC”,“domain”:“ubiquity.io”,“registeredCountry”:“United States”,“registeredCountryCode”:“US”,“isRoutable”:true},“threatIntelligence”:{“threatLevel”:“VERY_HIGH”,“threatIntelligenceScore”:“1.00000”,“genericBlacklistMatch”:true,“proxyBlacklistMatch”:true,“torBlacklistMatch”:false,“vpnBlacklistMatch”:true,“malwareBlacklistMatch”:false,“spywareBlacklistMatch”:false,“hijackBlacklistMatch”:false,“crawlerBlacklistMatch”:false,“botBlacklistMatch”:false,“spamBotBlacklistMatch”:false,“exploitBotBlacklistMatch”:false,“dshieldBlacklistMatch”:false}}}
# File lib/ruby_ip_client/ip_client.rb, line 25 def submit_sync_lookup(ip, engine = nil, storage = nil) params = { :action => 'submitSyncLookup', :ip => ip, :username => @username, :password => @password } unless engine.nil? params.merge!(engine: engine) end unless storage.nil? params.merge!(storage: storage) end send_request(params) end
Private Instance Methods
# File lib/ruby_ip_client/ip_client.rb, line 122 def generate_error_result(message) {:success => false, :fieldErrors => [], :globalErrors => ["#{message}"]}.to_json end
# File lib/ruby_ip_client/ip_client.rb, line 128 def ips_to_string(ips) string = '' c = 0 ips.each { |ip| if c > 0 string += ',' end string += ip c = c+1 } string end
# File lib/ruby_ip_client/ip_client.rb, line 105 def send_request(query) begin response = RestClient.get @url, :params => query rescue => e return generate_error_result("HTTP Status Code #{e.message}") end unless response.code == 200 return generate_error_result("HTTP Status Code #{response.code}") end response.to_str end