Class: Hotspot::Hotspot

Inherits:
Object
  • Object
show all
Defined in:
lib/hl.rb

Direct Known Subclasses

FreeWifi, Sfr, UPPA

Constant Summary collapse

@@hotspots =
Hash.new

Class Method Summary collapse

Instance Method Summary collapse

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
    
end

Class Method Details

.hotspotsObject



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

#authObject



67
68
69
# File 'lib/hl.rb', line 67

def auth
    raise
end

#connect?Boolean

Check connection to internet

Returns:

  • (Boolean)


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

#infoObject

Return login url



49
50
51
# File 'lib/hl.rb', line 49

def info
    URI.parse()
end

#login_urlObject

Get the url of login hotspot



21
22
23
24
# File 'lib/hl.rb', line 21

def 
     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 = redirect? get(@uri_test)
end

#paramsObject

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

Returns:

  • (Boolean)


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_testObject

Return uri test to test connect



63
64
65
# File 'lib/hl.rb', line 63

def uri_test
    @uri_test
end