ruby_ip_client 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4aa99af743da230cf8233c3a7d454f4c43d4afd0
4
+ data.tar.gz: 9127df5bc0d33c41057630f89ecb908f7652059f
5
+ SHA512:
6
+ metadata.gz: a679dd2bd92c6803aa8b193852d8c540bf761fa2d072623db42e119ffb531a70e9673444e37e23e1efd4cb5d43bd1cccdee133e82a8955b216287d57a4a60db3
7
+ data.tar.gz: 0b4dc18485b0c0d3132f2fcce6dc2d732dbb939c95425a516bd06941d1ff02ff4e977886a98bb18f8e7be931f02304700dc07ecd3b1f7b73e67c140e6567a4f2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify dependencies in ruby_ip_client.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'sinatra'
4
+ require 'ruby_ip_client/ip_callback_handler'
5
+
6
+ set :run, true
7
+
8
+ get '/' do
9
+
10
+ client = RubyIpClient::IpCallbackHandler.new
11
+
12
+ # Parses an asynchronous IP Lookup callback and returns a JSON string with the results.
13
+ # @param params
14
+ # @returns {*}
15
+ #
16
+ # Params example: {"success":true,"results":[{"context":{"id":"3ac9069dc6e9","ip":"85.10.208.227","state":"COMPLETED","storage":"ASYNC-API-2017-02","engine":"IV1","interface":"Async API","cost":"0.01000","timeStamp":"2017-02-09 22:57:33.80855+08"},"geolocation":{"country":"Germany","region":"Bavaria","countryCode":"DE","regionCode":"BY","city":"Nuremberg","zip":"90455","latitude":"49.44780","longitude":"11.06830","radius":200,"timeZone":"Europe\/Berlin","averageIncome":null,"populationDensity":null,"dmaCode":null},"network":{"connectionType":"HOSTING","asn":"24940","asnOrganization":"Hetzner Online GmbH","isp":"Hetzner Online GmbH","ispOrganization":"Hetzner Online GmbH","domain":"your-server.de","registeredCountry":"Germany","registeredCountryCode":"DE","isRoutable":true},"threatIntelligence":{"threatLevel":"VERY_HIGH","threatIntelligenceScore":"1.00000","genericBlacklistMatch":false,"proxyBlacklistMatch":false,"torBlacklistMatch":false,"vpnBlacklistMatch":false,"malwareBlacklistMatch":false,"spywareBlacklistMatch":false,"hijackBlacklistMatch":false,"crawlerBlacklistMatch":false,"botBlacklistMatch":false,"spamBotBlacklistMatch":false,"exploitBotBlacklistMatch":false,"dshieldBlacklistMatch":false}}]}
17
+ print client.parse_callback(params)
18
+
19
+ # send HTTP response body (OK)
20
+ content_type :text
21
+ return client.send_response
22
+
23
+ end
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ruby_ip_client/ip_client'
4
+
5
+ # Initializes the IP Lookup Client
6
+ # @param username - www.ip-lookups.com username
7
+ # @param password - www.ip-lookups.com password
8
+ # @constructor
9
+ client = RubyIpClient::IpClient.new(
10
+ 'username',
11
+ 'password'
12
+ )
13
+ print "\n"
14
+
15
+
16
+ # Submits a synchronous IP Lookup request. The IP is queried in real time and results presented in the response body.
17
+ # @param ip - An IPv4 or IPv6 address
18
+ # @param engine - An optional engine assignment, see: http://www.ip-lookups.com/en/data-source-engines
19
+ # @param storage - An optional storage assignment, see: http://www.ip-lookups.com/en/storages
20
+ # @returns string (JSON)
21
+ #
22
+ # 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}}}
23
+ print client.submit_sync_lookup('85.10.208.227', 'IV1', 'SDK-TEST')
24
+ print "\n\n"
25
+
26
+ # Sets the callback URL for asynchronous IP lookups. Read more about the concept of asynchronous IP lookups @ http://www.ip-lookups.com/en/asynchronous-ip-lookup-api
27
+ # @param url - callback url on your server
28
+ # @returns string (JSON)
29
+ #
30
+ # Return example: {"success":true,"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
31
+ print client.set_async_callback_url('http://user:pass@www.your-server.com/path/file')
32
+ print "\n\n"
33
+
34
+ # Submits asynchronous IP Lookups containing up to 1,000 IPs per request. Results are sent back asynchronously to a callback URL on your server.
35
+ # @param ips - A list of IPv4 or IPv6 addresses
36
+ # @param engine - An optional engine assignment, see: http://www.ip-lookups.com/en/data-source-engines
37
+ # @param storage - An optional storage assignment, see: http://www.ip-lookups.com/en/storages
38
+ # @returns string (JSON)
39
+ #
40
+ # Return example: {"success":true,"results":{"acceptedIps":[{"id":"58cc4f7c4afc","ip":"85.10.208.227"},{"id":"d40499b8605c","ip":"85.10.208.228"},{"id":"8bdc66d4ce52","ip":"85.208.221.221"}],"rejectedIps":[],"acceptedIpCount":3,"rejectedIpCount":0,"totalCount":3,"cost":0.03,"storage":"ASYNC-API-2017-02","engine":"IV1"}}
41
+ print client.submit_async_lookup(['85.10.208.227', '85.10.208.228'])
42
+ print "\n\n"
43
+
44
+ # Returns the remaining balance (EUR) in your account.
45
+ # @returns string (JSON)
46
+ #
47
+ # Return example: {"success":true,"results":{"balance":"5878.24600"}}
48
+ print client.get_balance
49
+ print "\n\n"
data/create_gem.txt ADDED
@@ -0,0 +1,2 @@
1
+ 1. rake install
2
+ 2. cd pkg/; gem push ruby_ip_client-VERSION.gem
@@ -0,0 +1,3 @@
1
+ module RubyIpClient
2
+ # Your code goes here...
3
+ end
@@ -0,0 +1,36 @@
1
+ require 'json'
2
+
3
+ module RubyIpClient
4
+ class IpCallbackHandler
5
+
6
+ # Parses an asynchronous IP Lookup callback and returns a JSON string with the results.
7
+ # @param params
8
+ # @returns {*}
9
+ #
10
+ # Params example: {"success":true,"results":[{"context":{"id":"3ac9069dc6e9","ip":"85.10.208.227","state":"COMPLETED","storage":"ASYNC-API-2017-02","engine":"IV1","interface":"Async API","cost":"0.01000","timeStamp":"2017-02-09 22:57:33.80855+08"},"geolocation":{"country":"Germany","region":"Bavaria","countryCode":"DE","regionCode":"BY","city":"Nuremberg","zip":"90455","latitude":"49.44780","longitude":"11.06830","radius":200,"timeZone":"Europe\/Berlin","averageIncome":null,"populationDensity":null,"dmaCode":null},"network":{"connectionType":"HOSTING","asn":"24940","asnOrganization":"Hetzner Online GmbH","isp":"Hetzner Online GmbH","ispOrganization":"Hetzner Online GmbH","domain":"your-server.de","registeredCountry":"Germany","registeredCountryCode":"DE","isRoutable":true},"threatIntelligence":{"threatLevel":"VERY_HIGH","threatIntelligenceScore":"1.00000","genericBlacklistMatch":false,"proxyBlacklistMatch":false,"torBlacklistMatch":false,"vpnBlacklistMatch":false,"malwareBlacklistMatch":false,"spywareBlacklistMatch":false,"hijackBlacklistMatch":false,"crawlerBlacklistMatch":false,"botBlacklistMatch":false,"spamBotBlacklistMatch":false,"exploitBotBlacklistMatch":false,"dshieldBlacklistMatch":false}}]}
11
+ def parse_callback(params)
12
+
13
+ unless params.has_key?('json')
14
+ return generate_error_result('Invalid callback parameters. Missing json payload.')
15
+ end
16
+
17
+ params['json']
18
+
19
+ end
20
+
21
+ def send_response
22
+
23
+ 'OK'
24
+
25
+ end
26
+
27
+ def generate_error_result(message)
28
+
29
+ result = {:success => false, :fieldErrors => [], :globalErrors => ["#{message}"]}
30
+ result.to_json
31
+
32
+ end
33
+
34
+ end
35
+
36
+ end
@@ -0,0 +1,150 @@
1
+ require 'rest-client'
2
+ require 'json'
3
+
4
+ module RubyIpClient
5
+
6
+ class IpClient
7
+
8
+ # Initializes the IP Lookup Client
9
+ # @param username - www.ip-lookups.com username
10
+ # @param password - www.ip-lookups.com password
11
+ # @constructor
12
+ def initialize(username, password)
13
+ @username = username
14
+ @password = password
15
+ @url = "https://www.ip-lookups.com/api"
16
+ end
17
+
18
+ # Submits a synchronous IP Lookup request. The IP is queried in real time and results presented in the response body.
19
+ # @param ip - An IPv4 or IPv6 address
20
+ # @param engine - An optional engine assignment, see: http://www.ip-lookups.com/en/data-source-engines
21
+ # @param storage - An optional storage assignment, see: http://www.ip-lookups.com/en/storages
22
+ # @returns string (JSON)
23
+ #
24
+ # 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}}}
25
+ def submit_sync_lookup(ip, engine = nil, storage = nil)
26
+
27
+ params = {
28
+ :action => 'submitSyncLookup',
29
+ :ip => ip,
30
+ :username => @username,
31
+ :password => @password
32
+ }
33
+
34
+ unless engine.nil?
35
+ params.merge!(engine: engine)
36
+ end
37
+
38
+ unless storage.nil?
39
+ params.merge!(storage: storage)
40
+ end
41
+
42
+ send_request(params)
43
+
44
+ end
45
+
46
+ # Submits asynchronous IP Lookups containing up to 1,000 IPs per request. Results are sent back asynchronously to a callback URL on your server.
47
+ # @param ips - A list of IPv4 or IPv6 addresses
48
+ # @param engine - An optional engine assignment, see: http://www.ip-lookups.com/en/data-source-engines
49
+ # @param storage - An optional storage assignment, see: http://www.ip-lookups.com/en/storages
50
+ # @returns string (JSON)
51
+ #
52
+ # Return example: {"success":true,"results":{"acceptedIps":[{"id":"58cc4f7c4afc","ip":"85.10.208.227"},{"id":"d40499b8605c","ip":"85.10.208.228"},{"id":"8bdc66d4ce52","ip":"85.208.221.221"}],"rejectedIps":[],"acceptedIpCount":3,"rejectedIpCount":0,"totalCount":3,"cost":0.03,"storage":"ASYNC-API-2017-02","engine":"IV1"}}
53
+ def submit_async_lookup(ips, engine = nil, storage = nil)
54
+
55
+ params = {
56
+ :action => 'submitAsyncLookup',
57
+ :ips => ips_to_string(ips),
58
+ :username => @username,
59
+ :password => @password
60
+ }
61
+
62
+ unless engine.nil?
63
+ params.merge!(engine: engine)
64
+ end
65
+
66
+ unless storage.nil?
67
+ params.merge!(storage: storage)
68
+ end
69
+
70
+ send_request(params)
71
+
72
+ end
73
+
74
+ # Sets the callback URL for asynchronous IP lookups. Read more about the concept of asynchronous IP lookups @ http://www.ip-lookups.com/en/asynchronous-ip-lookup-api
75
+ # @param url - callback url on your server
76
+ # @returns string (JSON)
77
+ #
78
+ # Return example: {"success":true,"results":{"url":"http:\/\/user:pass@www.your-server.com\/path\/file"}}
79
+ def set_async_callback_url(url)
80
+
81
+ send_request({
82
+ :action => 'setAsyncCallbackUrl',
83
+ :url => url,
84
+ :username => @username,
85
+ :password => @password
86
+ })
87
+
88
+ end
89
+
90
+ # Returns the remaining balance (EUR) in your account.
91
+ # @returns string (JSON)
92
+ #
93
+ # Return example: {"success":true,"results":{"balance":"5878.24600"}}
94
+ def get_balance
95
+
96
+ send_request({
97
+ :action => 'getBalance',
98
+ :username => @username,
99
+ :password => @password
100
+ })
101
+
102
+ end
103
+
104
+ private
105
+ def send_request(query)
106
+
107
+ begin
108
+ response = RestClient.get @url, :params => query
109
+ rescue => e
110
+ return generate_error_result("HTTP Status Code #{e.message}")
111
+ end
112
+
113
+ unless response.code == 200
114
+ return generate_error_result("HTTP Status Code #{response.code}")
115
+ end
116
+
117
+ response.to_str
118
+
119
+ end
120
+
121
+ private
122
+ def generate_error_result(message)
123
+
124
+ {:success => false, :fieldErrors => [], :globalErrors => ["#{message}"]}.to_json
125
+
126
+ end
127
+
128
+ def ips_to_string(ips)
129
+
130
+ string = ''
131
+ c = 0
132
+ ips.each { |ip|
133
+
134
+ if c > 0
135
+ string += ','
136
+ end
137
+
138
+ string += ip
139
+
140
+ c = c+1
141
+
142
+ }
143
+
144
+ string
145
+
146
+ end
147
+
148
+ end
149
+
150
+ end
@@ -0,0 +1,3 @@
1
+ module RubyIpClient
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'ruby_ip_client/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'ruby_ip_client'
7
+ s.version = RubyIpClient::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Velocity Made Good Ltd.']
10
+ s.email = ['service@ip-lookups.com']
11
+ s.homepage = 'http://www.ip-lookups.com'
12
+ s.summary = %q{Official HLR Lookup API Ruby SDK by www.ip-lookups.com}
13
+ s.licenses = ['Apache-2.0']
14
+ s.required_ruby_version = '>= 2.0.0'
15
+
16
+ s.add_dependency 'sinatra'
17
+ s.add_dependency 'rest-client'
18
+ s.add_dependency 'json'
19
+
20
+ s.rubyforge_project = 'ruby_ip_client'
21
+
22
+ s.files = `git ls-files`.split("\n")
23
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
24
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ s.require_paths = ['lib']
26
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_ip_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Velocity Made Good Ltd.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest-client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - service@ip-lookups.com
58
+ executables:
59
+ - test_ip_callback_handler.rb
60
+ - test_ip_client.rb
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - Gemfile
65
+ - Rakefile
66
+ - bin/test_ip_callback_handler.rb
67
+ - bin/test_ip_client.rb
68
+ - create_gem.txt
69
+ - lib/ruby_ip_client.rb
70
+ - lib/ruby_ip_client/ip_callback_handler.rb
71
+ - lib/ruby_ip_client/ip_client.rb
72
+ - lib/ruby_ip_client/version.rb
73
+ - ruby_ip_client.gemspec
74
+ homepage: http://www.ip-lookups.com
75
+ licenses:
76
+ - Apache-2.0
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: 2.0.0
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project: ruby_ip_client
94
+ rubygems_version: 2.0.14
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Official HLR Lookup API Ruby SDK by www.ip-lookups.com
98
+ test_files: []