Class: Hotspot::Hotspot
- Inherits:
-
Object
- Object
- Hotspot::Hotspot
- Defined in:
- lib/hl.rb
Constant Summary collapse
- @@hotspots =
Hash.new
Class Method Summary collapse
Instance Method Summary collapse
- #auth ⇒ Object
-
#connect? ⇒ Boolean
Check connection to internet.
- #get(uri) ⇒ Object
-
#info ⇒ Object
Return login url.
-
#initialize(user, password) ⇒ Hotspot
constructor
A new instance of Hotspot.
-
#login_url ⇒ Object
Get the url of login hotspot.
-
#login_url! ⇒ Object
Force login_url.
-
#params ⇒ Object
Return params of login url.
- #post(uri, query) ⇒ Object
-
#redirect?(res) ⇒ Boolean
Get the the forwarding url.
-
#uri_test ⇒ Object
Return uri test to test connect.
Constructor Details
#initialize(user, password) ⇒ Hotspot
Returns a new instance of Hotspot.
7 8 9 10 11 12 |
# File 'lib/hl.rb', line 7 def initialize(user, password) @uri_test = "http://www.example.com" @user = user @password = password login_url end |
Class Method Details
.hotspots ⇒ Object
83 84 85 |
# File 'lib/hl.rb', line 83 def self.hotspots @@hotspots end |
.inherited(klass) ⇒ Object
79 80 81 |
# File 'lib/hl.rb', line 79 def self.inherited(klass) @@hotspots[klass.name.split(/::/).last] = klass end |
Instance Method Details
#auth ⇒ Object
67 68 69 |
# File 'lib/hl.rb', line 67 def auth raise end |
#connect? ⇒ Boolean
Check connection to internet
15 16 17 18 |
# File 'lib/hl.rb', line 15 def connect? redirect = redirect? get(@uri_test) redirect == @uri_test.to_s end |
#get(uri) ⇒ Object
71 72 73 |
# File 'lib/hl.rb', line 71 def get(uri) Net::HTTP.get_response(URI(uri)) end |
#info ⇒ Object
Return login url
49 50 51 |
# File 'lib/hl.rb', line 49 def info URI.parse(login_url) end |
#login_url ⇒ Object
Get the url of login hotspot
21 22 23 24 |
# File 'lib/hl.rb', line 21 def login_url login_url! if @login_url.nil? @login_url end |
#login_url! ⇒ Object
Force login_url
27 28 29 |
# File 'lib/hl.rb', line 27 def login_url! @login_url = redirect? get(@uri_test) end |
#params ⇒ Object
Return params of login url
54 55 56 57 58 59 60 |
# File 'lib/hl.rb', line 54 def params if not info.query.nil? CGI::parse(info.query) else Hash.new end end |
#post(uri, query) ⇒ Object
75 76 77 |
# File 'lib/hl.rb', line 75 def post(uri, query) Net::HTTP.post_form(URI(uri), query) end |
#redirect?(res) ⇒ Boolean
Get the the forwarding url
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hl.rb', line 32 def redirect?(res) case res when Net::HTTPSuccess then javascript = /window\.location = \"(.*)\"/m.match(res.body) if not javascript.nil? javascript[1] else res.uri.to_s end when Net::HTTPRedirection then res['location'] else raise end end |
#uri_test ⇒ Object
Return uri test to test connect
63 64 65 |
# File 'lib/hl.rb', line 63 def uri_test @uri_test end |