titech-pubnet-auth 0.1.4 → 0.1.5

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.
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
+ # Titech-Pubnet-Auth
1
2
  ## これはなに?
2
3
 
3
4
  東工大の titech-pubnet の認証を自動で行なうための gem です。
4
5
 
5
6
  Mac OS X Mountain Lion, Ruby1.9.3 で動作確認済みです。たぶん Ruby1.9 じゃないと動きません。
6
7
 
7
- titech-pubnet の認証の仕様に依存しているため、仕様が変われば動かなくなるかもしれません。その時はこの gem をバージョンアップして対応するかもしれません。主に以下のようなものの内容に依存していると思います。
8
+ titech-pubnet の認証の仕様に依存しているため、仕様が変われば動かなくなるかもしれません。主に以下のようなものの内容に依存していると思います。
8
9
 
9
10
  - 認証ページのドメイン
10
11
  - 認証ページのフォーム
@@ -30,7 +31,6 @@ gem のインストール [^1]
30
31
 
31
32
  $ titech-pubnet-auth
32
33
 
33
-
34
34
  デーモンとして起動
35
35
 
36
36
  $ titech-pubnet-auth -d
@@ -45,15 +45,4 @@ gem のインストール [^1]
45
45
  1. 「システム環境設定」→「ユーザとグループ」→「ログイン項目」に起動スクリプト`titech-pubnet-auth-daemon`を追加(`$ which titech-pubnet-auth-daemon`とかで場所を調べて、Finder上で⌘gでパス指定して移動できる)。
46
46
  2. (デフォルトだとプロセス終了時にターミナル.appが閉じない。これが煩わしい場合、)ターミナルを起動して、「環境設定」→「設定タブ」→「シェル」で、「シェルの終了時」の動作を「ウィンドウを閉じる」にする。
47
47
 
48
- ## TODO
49
-
50
- - ライセンス明示
51
- - 連絡先明示
52
- - 接続確認のサンプル増やしたい
53
- - Notification Center 使う
54
- - パスワードを暗号化して保管
55
- - 正しいやり方調べる
56
- - Logger
57
- - テスト
58
-
59
48
  [^1]: 依存している gem の一つである nokogiri(XMLパーサー)が native extension を使っていて必要なものが無いと install で失敗するかも。http://nokogiri.org/tutorials/installing_nokogiri.html を参照。
@@ -1,13 +1,16 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
+ OS_X = RbConfig::CONFIG["target_os"].downcase =~ /^darwin/
5
+
4
6
  $:.unshift File.expand_path('../lib', File.dirname(__FILE__))
5
7
  require 'titech_pubnet_auth'
6
8
  require 'optparse'
9
+ require 'terminal-notifier' if OS_X
7
10
 
8
11
  opt = OptionParser.new
9
12
 
10
- interval = 3
13
+ interval = TitechPubnetAuth::INTERVAL
11
14
  opt.on('-i','--interval=SECONDS','Specify the polling interval.[3]'){|v|
12
15
  interval = v.to_i
13
16
  }
@@ -29,6 +32,7 @@ opt.on('-c','--config','Set your username and password.'){
29
32
 
30
33
  opt.parse!(ARGV)
31
34
 
35
+
32
36
  if configure
33
37
  puts 'Please type your username:'
34
38
  username = gets.strip
@@ -54,10 +58,14 @@ end
54
58
  pubnet_auth = TitechPubnetAuth.new
55
59
  loop do
56
60
  begin
61
+ mputs_with_notify = ->(auth,is_success){
62
+ mputs auth, is_success
63
+ TerminalNotifier.notify(nil,:title => 'Titech Punet Auth',:subtitle => 'Connected!') if OS_X and is_success
64
+ }
65
+
57
66
  mputs 'network_available?', pubnet_auth.network_available?
58
67
  mputs 'is_connected?', pubnet_auth.is_connected? if pubnet_auth.network_available?
59
- mputs 'auth', pubnet_auth.auth if pubnet_auth.network_available? and not pubnet_auth.is_connected?
60
-
68
+ mputs_with_notify 'auth' if pubnet_auth.network_available? and not pubnet_auth.is_connected?
61
69
  rescue => e
62
70
  p e
63
71
  ensure
@@ -0,0 +1,3 @@
1
+ ---
2
+ username: 10B14180
3
+ password: gnomedf4
@@ -15,17 +15,17 @@ class TitechPubnetAuth
15
15
 
16
16
  HTTP_PROXY = {ip: '131.112.125.238', port: 3128}
17
17
  OPEN_TIMEOUT = 5
18
+ INTERVAL = 2
18
19
 
19
20
  def initialize
20
- @private = YAML.load(File::open(File::expand_path('config/private.yml',BASE_DIR),'r'))
21
-
22
21
  @agent, @agent_with_proxy = Mechanize.new, Mechanize.new
23
22
  [@agent,@agent_with_proxy].each{|agent|
24
23
  agent.follow_meta_refresh = true
25
24
  agent.open_timeout = OPEN_TIMEOUT
26
25
  }
27
26
  @agent_with_proxy.set_proxy(HTTP_PROXY[:ip], HTTP_PROXY[:port])
28
-
27
+
28
+ @private = YAML.load(File::open(File::expand_path('config/private.yml',BASE_DIR),'r'))
29
29
  end
30
30
 
31
31
  def auth
@@ -45,7 +45,6 @@ class TitechPubnetAuth
45
45
  return is_connected?
46
46
  end
47
47
 
48
-
49
48
  def is_connected?
50
49
  return @agent_with_proxy.get(SAMPLE_URI).uri.hostname == SAMPLE_URI.hostname
51
50
  rescue # retry without the proxy
@@ -0,0 +1,3 @@
1
+ class TitechPubnetAuth
2
+ VERSION = '0.1.5'
3
+ end
@@ -1,6 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  require 'rake'
4
+ require File.expand_path('../lib/titech_pubnet_auth/version', __FILE__)
4
5
 
5
6
  Gem::Specification.new do |gem|
6
7
  gem.authors = ["Sohei Takeno"]
@@ -14,9 +15,10 @@ Gem::Specification.new do |gem|
14
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
16
  gem.name = "titech-pubnet-auth"
16
17
  gem.require_paths = ["lib"]
17
- gem.version = "0.1.4"
18
+ gem.version = TitechPubnetAuth::VERSION
18
19
 
19
20
  gem.add_dependency 'colorize'
20
21
  gem.add_dependency 'mechanize', '~> 2.5'
22
+ gem.add_dependency 'terminal-notifier', '~> 1.4'
21
23
 
22
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: titech-pubnet-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
45
  version: '2.5'
46
+ - !ruby/object:Gem::Dependency
47
+ name: terminal-notifier
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.4'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
46
62
  description: This gem provides automatic authentication for titech-pubnet.
47
63
  email:
48
64
  - takeno.sh@gmail.com
@@ -53,9 +69,11 @@ extensions: []
53
69
  extra_rdoc_files: []
54
70
  files:
55
71
  - lib/titech_pubnet_auth/extension.rb
72
+ - lib/titech_pubnet_auth/version.rb
56
73
  - lib/titech_pubnet_auth.rb
57
74
  - bin/titech-pubnet-auth
58
75
  - bin/titech-pubnet-auth-daemon
76
+ - config/private.yml
59
77
  - config/private.yml.example
60
78
  - Rakefile
61
79
  - Gemfile