public_ip 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 093c969531f5c5d6f98a4a0404682a2550fa0efe
4
- data.tar.gz: 1bced70c93b53fc7aa5f32551aaac6d2033af68b
3
+ metadata.gz: c6014ac220e8ffedcb14958f6a2d32463d756a42
4
+ data.tar.gz: 1e0ddf384845fc0e4993986e015413ad4e2a644c
5
5
  SHA512:
6
- metadata.gz: 67916aa1d5d877e47237cdf15256fca7fe965f34c6b5d4e0a3bb0c4df97f8aa318f99959af4e89ad1e30b2a0e53b79ccd6c0344d5acd08ce1361c6c805e857e3
7
- data.tar.gz: 69b7d8071f94abd4b92b6e66e34f18028a3e5d5fcf69e73cfd5a2d5f084060d6e3a9c4395fac3b43af64524701381d008479b2efac01d6a149106401610414ee
6
+ metadata.gz: 494aacfe714bdbe90586a2d995c387748d1bb949df19009d9f3ed8b2c13ad215aa26caf5e0d9eae21beac1e1840fbcc76bc4b33433657dded8ba69071cac121c
7
+ data.tar.gz: 6e827fcee2fe45fe5e808815bc59ba8bf1e124ec883c7a9de8a49ebd74e3581a41643d5b75c1a0a03b403c3c4d6beba04d0452f0c63710793ea91507ee3ad21c
data/.codeclimate.yml ADDED
@@ -0,0 +1,17 @@
1
+ ---
2
+ engines:
3
+ duplication:
4
+ enabled: true
5
+ config:
6
+ languages:
7
+ - ruby
8
+ fixme:
9
+ enabled: true
10
+ rubocop:
11
+ enabled: true
12
+ ratings:
13
+ paths:
14
+ - "**.rb"
15
+ exclude_paths:
16
+ - features/**/*
17
+ - spec/**/*
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in public_ip.gemspec
4
4
  gemspec
5
+
6
+ gem 'codeclimate-test-reporter', '~> 0.4.8', group: :test, require: nil
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # PublicIp
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/pedrocarrico/public_ip.png)](http://travis-ci.org/pedrocarrico/public_ip) [![Dependency Status](https://gemnasium.com/pedrocarrico/public_ip.png?travis)](https://gemnasium.com/pedrocarrico/public_ip) [![Gem Version](https://badge.fury.io/rb/public_ip.png)](http://badge.fury.io/rb/public_ip) [![Code Climate](https://codeclimate.com/github/pedrocarrico/public_ip/badges/gpa.svg)](https://codeclimate.com/github/pedrocarrico/public_ip)
3
+ [![Build Status](https://secure.travis-ci.org/pedrocarrico/public_ip.png)](http://travis-ci.org/pedrocarrico/public_ip) [![Dependency Status](https://gemnasium.com/pedrocarrico/public_ip.png?travis)](https://gemnasium.com/pedrocarrico/public_ip) [![Gem Version](https://badge.fury.io/rb/public_ip.png)](http://badge.fury.io/rb/public_ip) [![Code Climate](https://codeclimate.com/github/pedrocarrico/public_ip/badges/gpa.svg)](https://codeclimate.com/github/pedrocarrico/public_ip) [![Test Coverage](https://codeclimate.com/github/pedrocarrico/public_ip/badges/coverage.svg)](https://codeclimate.com/github/pedrocarrico/public_ip/coverage)
4
4
 
5
5
  Ever questioned what is your public internet IP and you've forgotten how to do it.
6
6
  Instead of remembering every service that you can query to get your public internet IP you can use this gem.
data/bin/public_ip CHANGED
@@ -10,7 +10,7 @@ class App
10
10
 
11
11
  main do |service|
12
12
  if options['list-services']
13
- list_of_services = PublicIp.list_services.map do |service_symbol, service_class|
13
+ list_of_services = PublicIp.list_services.sort.map do |service_symbol, service_class|
14
14
  "#{service_symbol} (#{service_class.uri})"
15
15
  end.join("\n")
16
16
 
data/lib/public_ip.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require 'public_ip/service/registry'
2
2
  require 'public_ip/service/registrable'
3
3
  require 'public_ip/service/simple'
4
+ require 'public_ip/service/parsed_html'
4
5
  require 'public_ip/service/plain'
5
6
  require 'public_ip/service/matched_expression'
7
+ require 'public_ip/service/json_type'
6
8
 
7
9
  require 'public_ip/version'
8
10
 
@@ -0,0 +1,13 @@
1
+ module PublicIp
2
+ module Service
3
+ class IpAPI < JsonType
4
+ def self.uri
5
+ URI('http://ip-api.com/json')
6
+ end
7
+
8
+ def self.parse_json(json_data)
9
+ json_data['query']
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ require 'nokogiri'
2
+
3
+ module PublicIp
4
+ module Service
5
+ class IpChicken < ParsedHTML
6
+ def self.uri
7
+ URI('http://www.ipchicken.com/')
8
+ end
9
+
10
+ def self.parse_ip_address(response_body)
11
+ parsed_html = Nokogiri::HTML(response_body).css('table:nth-of-type(2) p:nth-of-type(2) b')
12
+ parsed_html.text.match(/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}/)[0]
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ module PublicIp
2
+ module Service
3
+ class Ipify < JsonType
4
+ def self.uri
5
+ URI('http://api.ipify.org/?format=json')
6
+ end
7
+
8
+ def self.parse_json(json_data)
9
+ json_data['ip']
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ require 'json'
2
+
3
+ module PublicIp
4
+ module Service
5
+ class JsonType < Simple
6
+ extend PublicIp::Service::Registrable
7
+
8
+ def self.parse_json(_json_data)
9
+ fail 'Not implemented'
10
+ end
11
+
12
+ def self.ip
13
+ response = perform_request
14
+
15
+ parse_json(JSON.parse(response.body.strip))
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ require 'nokogiri'
2
+
3
+ module PublicIp
4
+ module Service
5
+ class MxToolbox < ParsedHTML
6
+ def self.uri
7
+ URI('http://mxtoolbox.com/WhatIsMyIP/')
8
+ end
9
+
10
+ def self.parse_ip_address(response_body)
11
+ Nokogiri::HTML(response_body).css('#ctl00_ContentPlaceHolder1_hlIP').text
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module PublicIp
2
+ module Service
3
+ class ParsedHTML < Simple
4
+ extend PublicIp::Service::Registrable
5
+
6
+ def self.ip
7
+ response = perform_request
8
+
9
+ parse_ip_address(response.body)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require 'nokogiri'
2
+
3
+ module PublicIp
4
+ module Service
5
+ class PrivateInternetAccess < ParsedHTML
6
+ def self.uri
7
+ URI('https://www.privateinternetaccess.com/pages/whats-my-ip/')
8
+ end
9
+
10
+ def self.parse_ip_address(response_body)
11
+ Nokogiri::HTML(response_body).css('.ipbox-footer ul li:first-of-type span').text.strip
12
+ end
13
+ end
14
+ end
15
+ end
@@ -29,7 +29,9 @@ module PublicIp
29
29
  def self.perform_request
30
30
  Timeout.timeout(PublicIp::TIMEOUT_IN_SECS) do
31
31
  request = Net::HTTP::Get.new(uri, headers)
32
- Net::HTTP.start(uri.host, uri.port) { |http| http.request(request) }
32
+ http = Net::HTTP.new(uri.host, uri.port)
33
+ http.use_ssl = (uri.scheme == 'https')
34
+ http.request(request)
33
35
  end
34
36
  end
35
37
  end
@@ -0,0 +1,19 @@
1
+ require 'nokogiri'
2
+
3
+ module PublicIp
4
+ module Service
5
+ class WhatIsMyIp < ParsedHTML
6
+ def self.uri
7
+ URI('https://www.whatismyip.com/')
8
+ end
9
+
10
+ def self.headers
11
+ { 'User-Agent' => 'Chrome' }
12
+ end
13
+
14
+ def self.parse_ip_address(response_body)
15
+ Nokogiri::HTML(response_body).css('.ip div').text
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module PublicIp
2
+ module Service
3
+ class WtfIsMyIp < JsonType
4
+ def self.uri
5
+ URI('http://wtfismyip.com/json')
6
+ end
7
+
8
+ def self.parse_json(json_data)
9
+ json_data['YourFuckingIPAddress']
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module PublicIp
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/public_ip.gemspec CHANGED
@@ -24,6 +24,7 @@ DESCRIPTION
24
24
  spec.require_paths = ['lib']
25
25
 
26
26
  spec.add_dependency 'methadone', '~> 1.9.2'
27
+ spec.add_dependency 'nokogiri', '~> 1.6.7'
27
28
 
28
29
  spec.add_development_dependency 'bundler', '~> 1.10'
29
30
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: public_ip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pedro Carriço
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-04 00:00:00.000000000 Z
11
+ date: 2016-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: methadone
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.9.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.7
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.7
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +147,7 @@ executables:
133
147
  extensions: []
134
148
  extra_rdoc_files: []
135
149
  files:
150
+ - ".codeclimate.yml"
136
151
  - ".gitignore"
137
152
  - ".rspec"
138
153
  - ".rubocop.yml"
@@ -153,17 +168,25 @@ files:
153
168
  - lib/public_ip/service/i_can_haz_ip.rb
154
169
  - lib/public_ip/service/ident_me.rb
155
170
  - lib/public_ip/service/ifconfig_me.rb
171
+ - lib/public_ip/service/ip_api.rb
172
+ - lib/public_ip/service/ip_chicken.rb
156
173
  - lib/public_ip/service/ip_echo.rb
157
174
  - lib/public_ip/service/ip_info.rb
158
175
  - lib/public_ip/service/ip_ogre.rb
176
+ - lib/public_ip/service/ipify.rb
177
+ - lib/public_ip/service/json_type.rb
159
178
  - lib/public_ip/service/matched_expression.rb
179
+ - lib/public_ip/service/mx_toolbox.rb
180
+ - lib/public_ip/service/parsed_html.rb
160
181
  - lib/public_ip/service/plain.rb
182
+ - lib/public_ip/service/private_internet_access.rb
161
183
  - lib/public_ip/service/registrable.rb
162
184
  - lib/public_ip/service/registry.rb
163
185
  - lib/public_ip/service/simple.rb
164
186
  - lib/public_ip/service/smart_ip.rb
165
- - lib/public_ip/service/untitled
187
+ - lib/public_ip/service/what_is_my_ip.rb
166
188
  - lib/public_ip/service/what_is_my_ip_address.rb
189
+ - lib/public_ip/service/wtf_is_my_ip.rb
167
190
  - lib/public_ip/version.rb
168
191
  - public_ip.gemspec
169
192
  homepage: https://github.com/pedrocarrico/public_ip
File without changes