av-ip 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/av-ip.rb +86 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae8fd9bc95927a9ece40c50c06894dcbbff0fde5
4
+ data.tar.gz: bf32f066cfbedb2240f1d074791d3f881caaea64
5
+ SHA512:
6
+ metadata.gz: d58ac6b270fcc1d7fc4a977cbc4e5fd75c1cc4e2f229298c5d25efa422498d69ba6851b78de0e7f7dd61ab64ef5fb5eade0245cc7bb072e33fb60b1d2e2caac4
7
+ data.tar.gz: 1e50ef9bf8a426d60d0f20ba98f60dae8402e803ff8a75518bedf303f3ead0eb4b013adfa2bffd5a8ac0345835b6869441b7a63d05f413d7f01b21e1b5eaf89f
@@ -0,0 +1,86 @@
1
+ require 'net/https'
2
+ require 'uri'
3
+
4
+
5
+ class AVIP
6
+ def initialize(ip = '127.0.0.1', content = [])
7
+ @ip = ip
8
+ @content = content
9
+ @params = [
10
+ :format,
11
+ :ip,
12
+ :content
13
+ ]
14
+
15
+ @contents = [
16
+ :ip,
17
+ :hostname,
18
+ :city,
19
+ :region,
20
+ :country,
21
+ :loc,
22
+ :org,
23
+ :postal
24
+ ]
25
+ end
26
+
27
+ # Input options in hash form ie {:format => :json, :ip => '127.0.0.1'}
28
+ def update(param_hash)
29
+ param_hash.each do |key,value|
30
+ if @params.include?(key)
31
+ if key == :ip
32
+ @ip = value
33
+ puts "Ip changed to #{value}."
34
+ elsif key == :content
35
+ if value.length == 0
36
+ puts "Invalid Input, using all outputs"
37
+ else
38
+ content = []
39
+ value.each do |val|
40
+ if @contents.include?(val)
41
+ @content.push(val)
42
+ puts "Including: #{val}"
43
+ else
44
+ puts "#{val} is not a valid option."
45
+ end
46
+ end
47
+ end
48
+ end
49
+ else
50
+ puts "Paramater: #{key} is not a valid option."
51
+ puts "Warning: No change has been made."
52
+ end
53
+ end
54
+ end
55
+
56
+ def search(ip = nil)
57
+ if ip == nil
58
+ p_ip = @ip
59
+ else
60
+ p_ip = ip
61
+ end
62
+ uri = URI("http://ipinfo.io/#{p_ip}/#{@format}")
63
+ Net::HTTP.start(uri.host, uri.port) do |http|
64
+ request = Net::HTTP::Get.new uri
65
+ response = http.request request
66
+ res = eval(response.body )
67
+ if @content == []
68
+ return res
69
+ else
70
+ new_res = {}
71
+ res.each do |key,value|
72
+ @content.each do |con|
73
+ if key == con
74
+ new_res[key] = value
75
+ end
76
+ end
77
+ end
78
+ return new_res
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ i = AVIP.new()
85
+ i.update( { :ip => '66.87.114.81', :content => [:city,:region, :loc]} )
86
+ puts i.search
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: av-ip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Henry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-31 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple ruby wrapper for quick ip geolocation
14
+ email: Henrywalters20@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/av-ip.rb
20
+ homepage: http://rubygems.org/gems/av-ip
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.5.1
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: A lightweight ruby wrapper for ip geolocation
44
+ test_files: []