Module: WifiLogin

Defined in:
lib/wifi_login.rb,
lib/wifi_login/version.rb,
lib/wifi_login/provider.rb,
lib/wifi_login/providers/docomo.rb

Defined Under Namespace

Modules: Provider, Providers Classes: Error

Constant Summary collapse

AIRPORT_CMD =
'/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -I'
VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.credential(ssid) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/wifi_login.rb', line 34

def self.credential(ssid)
  pit = Pit.get(ssid)
  id = pit['id']
  password = pit['password']
  unless (id && password)
    raise WifiLogin::Error.new("credential is not found. please run `pit set #{ssid}`.") 
  end
  [id, password]
end

.loginObject



18
19
20
21
22
# File 'lib/wifi_login.rb', line 18

def self.
  ssid = self.ssid
  id, password = credential(ssid)
  provider(ssid).(id, password)
end

.provider(ssid) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/wifi_login.rb', line 24

def self.provider(ssid)
  provider_name = WifiLogin::Providers.constants.find {|provider|
    provider.downcase.to_s == ssid.downcase
  }
  unless provider_name
    raise WifiLogin::Error.new("provider is not found for SSID: #{ssid}")
  end
  WifiLogin::Providers.const_get(provider_name).new
end

.providersObject



14
15
16
# File 'lib/wifi_login.rb', line 14

def self.providers
  @@providers ||= {}
end

.ssidObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/wifi_login.rb', line 44

def self.ssid
  status, stdout, stderr = systemu AIRPORT_CMD
  if status.exitstatus != 0
    raise WifiLogin::Error.new("faild to exec #{cmd}")
  end

  ssid_line = stdout.each_line.find {|line| line.match(/^\s+SSID:/) }
  unless ssid_line
    raise WifiLogin::Error.new("not found SSID (disable wi-fi?)")
  end
  ssid_line.chomp.split(': ')[1]
end