snarl-snp 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.
- data/GUIDE.rdoc.ja +126 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +144 -0
- data/README.rdoc.ja +166 -0
- data/Rakefile +47 -0
- data/VERSION +1 -0
- data/exsample/ping.rb +8 -0
- data/exsample/winamp_nowplaying.rb +227 -0
- data/exsample/yahoo_weather.rb +35 -0
- data/lib/snarl/autotest.rb +112 -0
- data/lib/snarl/snp.rb +11 -0
- data/lib/snarl/snp/action.rb +138 -0
- data/lib/snarl/snp/config.rb +32 -0
- data/lib/snarl/snp/error.rb +76 -0
- data/lib/snarl/snp/request.rb +83 -0
- data/lib/snarl/snp/response.rb +36 -0
- data/lib/snarl/snp/snp.rb +142 -0
- data/snarl-snp.gemspec +78 -0
- data/spec/exsample/data/weather_yahoo_co_jp.html +608 -0
- data/spec/exsample/yahoo_weather_spec.rb +22 -0
- data/spec/snp/action_spec.rb +198 -0
- data/spec/snp/config_spec.rb +53 -0
- data/spec/snp/request_spec.rb +72 -0
- data/spec/snp/response_sprc.rb +96 -0
- data/spec/snp/snp_spec.rb +265 -0
- data/spec/spec_helper.rb +20 -0
- metadata +119 -0
data/GUIDE.rdoc.ja
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
= SNP Connection Details with Snarl::SNP
|
2
|
+
|
3
|
+
SNP のコマンド文字列(実際に Snarl の動作してるマシンのポート 9887 に TCPSocket#write で送られる文字列)は以下のようなものです。
|
4
|
+
|
5
|
+
type=SNP#?version=1.1#?action=notification#?app=Ruby-Snarl#?class=type1#?title=title#?text=type1 text!#?timeout=10\r\n
|
6
|
+
|
7
|
+
data=value というペアが、区切り文字 #? で結合されて送信されます。終端は "\r\n" です。
|
8
|
+
value には #? という文字を含むことは出来ません。"\r" を含むことも出来ません。
|
9
|
+
Snarl::SNP のメソッドは、この長大な文字列を直接記述する代わりに、引数と内部デフォルト値から組み立てます。
|
10
|
+
|
11
|
+
snp.register('Ruby-Snarl')
|
12
|
+
snp.add_class('type1')
|
13
|
+
snp.notification('title', 'type1 text', nil, 10, 'type1')
|
14
|
+
|
15
|
+
と
|
16
|
+
snp.request("type=SNP#?version=1.1#?action=register#?app=Ruby-Snarl\r\n")
|
17
|
+
snp.request("type=SNP#?version=1.1#?action=add_class#?app=Ruby-Snarl#?class=type1\r\n")
|
18
|
+
snp.request("type=SNP#?version=1.1#?action=notification#?app=Ruby-Snarl#?class=type1#?title=title#?text=type1 text!#?timeout=10\r\n")
|
19
|
+
|
20
|
+
は、最終的に Snarl に送信された文字列は全く同じになります。
|
21
|
+
Snarl::SNP は "\r" や "\r\n" は "\n" に置換して処理しますが、 #? を送ることは依然出来ません。エスケープの仕方を知ってる方はぜひご一報を。
|
22
|
+
|
23
|
+
|
24
|
+
== 匿名クラスでポップアップを依頼する
|
25
|
+
|
26
|
+
「アプリケーション名」を登録して、ポップアップ依頼を送ります。
|
27
|
+
|
28
|
+
require 'rubygems'
|
29
|
+
require 'snarl/snp'
|
30
|
+
Snarl::SNP.open(@host) do |snp|
|
31
|
+
snp.register('Ruby-Snarl')
|
32
|
+
snp.notification('title', 'text', nil, 10)
|
33
|
+
end
|
34
|
+
# as you like
|
35
|
+
# Snarl::SNP.new(@host).unregister('Ruby-Snarl')
|
36
|
+
|
37
|
+
アプリケーション登録(register)だけを伴ったポップアップ依頼です。
|
38
|
+
登録されたアプリケーションは、Snarl 本体の設定画面の「Apps」の「The following applications are registered with Snarl:」で列挙されます。SNP 経由の場合は「アプリケーション名 on 接続元アドレス」(例:「Ruby-Snarl on xxx.xxx.xxx.xxx」)と表示されます。
|
39
|
+
これは SNP 経由で unregister するか、Snarl を再起動するまで保持されます。
|
40
|
+
|
41
|
+
なお、Snarl::SNP におけるアプリケーション名は Snarl::SNP オブジェクトにつきひとつです。別名義のアプリケーションを使用したい場合は、Snarl::SNP オブジェクトを別途作成してください。
|
42
|
+
|
43
|
+
=== 匿名アプリケーションポップアップ依頼
|
44
|
+
|
45
|
+
アプリケーション設定が register されていない状態のとき(Snarl 再起動後など)に notification を送ると「匿名ポップアップ」として処理されます。スタイル等は反映されませんが、ポップアップは普通に行われます(これを意図的に利用するととても便利なのですが、なぜか日本語が化けるので説明では省いています)。
|
46
|
+
|
47
|
+
require 'rubygems'; require 'snarl/snp'; require 'kconv'
|
48
|
+
Snarl::SNP.new(@host).notification('title', 'あいうえお'.tosjis) #=> "あいぁE"
|
49
|
+
|
50
|
+
「○○というアプリケーション用のポップアップ依頼だから○○アプリケーションの設定を自動で登録状態にして読み込んで使用する」というようなことはありません。
|
51
|
+
|
52
|
+
=== 匿名クラスポップアップの表示を Snarl 側でカスタマイズする
|
53
|
+
|
54
|
+
クラス設定を事前に SNP で送っていない場合、Snarl におけるクラスは匿名となります。本来は何らかのクラスを最低限1個、add_class で設定すべきなのですが、なくてもポップアップの動作設定はできます。
|
55
|
+
アプリケーションを登録すると、アプリケーション名義でクラス設定をまとめることができます(○○アプリケーションのクラス設定1、のように)。
|
56
|
+
次項のクラスつきポップアップ依頼を参考にして、<all>(他にクラス設定が何もないとき)または <other>(他の名前のクラス設定はあるが、匿名クラスを使うとき)で設定変更してください(このアプリケーションの匿名クラスポップアップ全てが影響を受けます)。これが好ましくない、またはクラスが複数あるほうが設定が使い分けられて都合がいいという場合は普通に SNP 経由でクラスを設定します。
|
57
|
+
|
58
|
+
=== アプリケーションの2重登録
|
59
|
+
|
60
|
+
既に同名(で、通信元が同ホスト)のアプリケーションが登録状態の場合、Snarl は「2度目以降の register」に対してエラーを返します。
|
61
|
+
が、Snarl::SNP はこれを例外として扱いません(例外にすることもできます)。
|
62
|
+
そもそもの登録行為自体、前回の register と今回の notification の間に Snarl が一度でも再起動されていると登録状態が解除されてしまっているという、永続性に疑問のあるてきとうなものなので、Snarl::SNP オブジェクト生成ごとに念のために register しておく、くらいの意気で構わないと思われます。
|
63
|
+
|
64
|
+
Snarl::SNP.open(@host) do |snp|
|
65
|
+
snp.register(app)
|
66
|
+
snp.add_class(class_id)
|
67
|
+
snp.notification(...)
|
68
|
+
end
|
69
|
+
|
70
|
+
はセットとして毎回書いておくことをお勧めします。
|
71
|
+
|
72
|
+
== unregister の罠
|
73
|
+
|
74
|
+
スクリプトでは unregister がぽつんと 1個離れて「お好みで」とかコメントがついてますが、unregister は「Snarl でのアプリケーション登録状態を(クラスごと)解除する」という効果をもちます。
|
75
|
+
register したんだから unregister もブロック内にペアで書くべき、なのですが、困ったことに Snarl は「unregister したアプリケーションは設定ウィンドウから消えて選べない」という仕様になっています。
|
76
|
+
なので、ユーザーが「このアプリケーションの表示設定を変えたい」と思っても、スクリプト内で unregister してしまうと Snarl の設定ウィンドウにはそのアプリケーションが表示されていないという事態になってしまいます。
|
77
|
+
|
78
|
+
irb> require 'rubygems'; require 'snarl/snp'
|
79
|
+
irb> @host = '127.0.0.1'
|
80
|
+
irb> snp = Snarl::SNP.new(@host)
|
81
|
+
irb> # Snarl の App 欄に「Ruby-Snarl on xxx.xxx.xxx.xxx」があれば一旦 unregister
|
82
|
+
irb> # snp.unregister('Ruby-Snarl')
|
83
|
+
irb> # 以下で Snarl の App 欄に「Ruby-Snarl on xxx.xxx.xxx.xxx」が出現する
|
84
|
+
irb> snp.register('Ruby-Snarl')
|
85
|
+
irb> # 以下で App 欄から「Ruby-Snarl on xxx.xxx.xxx.xxx」が消えてしまい触れなくなる
|
86
|
+
irb> snp.unregister('Ruby-Snarl')
|
87
|
+
irb> # コマンド送信ごとに TCPSocket.open(@host){...} してるので irb はこのまま閉じてOK
|
88
|
+
|
89
|
+
なので、unregister は「Snarl の設定欄から自分の設定の表示を消したい」ときにのみ、行ってください。
|
90
|
+
正直、普段使うようなコマンドではないと思われます。
|
91
|
+
|
92
|
+
=== unregister してもユーザー設定自体は消えない
|
93
|
+
|
94
|
+
unregister では Snarl の設定一覧から一旦消えるだけで、アプリケーションごとに設定した項目自体は Snarl のファイルに保存されています。設定を消す場合は
|
95
|
+
|
96
|
+
ユーザーフォルダ\Application Data\full phat\snarl\etc\.snarl
|
97
|
+
|
98
|
+
というファイルの中の、 [app.なんとか] の該当しそうなブロックを適当に(あるいは行単位で慎重に)削除してください。
|
99
|
+
適当な名前でテストしまくっていると全部記録されていて物凄い量になっていたりするので気をつけましょう。適宜掃除を。
|
100
|
+
|
101
|
+
== クラスつきでポップアップを依頼する
|
102
|
+
|
103
|
+
「アプリケーション名」を登録し「クラス名」を設定したあとに、それらを指定してポップアップ依頼を送ります。一番正当なものです。
|
104
|
+
|
105
|
+
require 'rubygems'
|
106
|
+
require 'snarl/snp'
|
107
|
+
Snarl::SNP.open(@host) do |snp|
|
108
|
+
snp.register('Ruby-Snarl')
|
109
|
+
snp.add_class('type1')
|
110
|
+
snp.add_class('type2')
|
111
|
+
snp.notification('title', 'type1 text', nil, 10, 'type1')
|
112
|
+
snp.notification('title', 'type2 text', nil, 10, 'type2')
|
113
|
+
snp.unregister('Ruby-Snarl')
|
114
|
+
end
|
115
|
+
|
116
|
+
アプリケーション登録(register)とクラス名追加(add_class)を伴ったポップアップ依頼です。
|
117
|
+
|
118
|
+
1. Snarl::SNP#register でアプリケーション名を登録する
|
119
|
+
2. Snarl::SNP#add_class でクラス名を使用するぶんだけ登録する(複数可能)
|
120
|
+
3. Snarl::SNP#notification で特定クラス使用のポップアップ依頼を送る
|
121
|
+
4. Snarl::SNP#unregister でアプリケーション名を削除する
|
122
|
+
|
123
|
+
という流れになります。
|
124
|
+
クラス名は Snarl の「App」欄の当該アプリ名選択後の「Notification classes:」に列挙されます。
|
125
|
+
type1 と書かれた欄を選んでたとえば「Visual」にて Style と Scheme を変更すれば、'type1' とした notification が来た場合にその Style でポップアップが表示されます。
|
126
|
+
red というクラスつきの依頼では赤っぽいポップアップを、green というクラスつきの依頼では緑っぽいポップアップを使う、といったような設定ができます。
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 kitamomonga
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
= snarl-snp
|
2
|
+
|
3
|
+
Snarl Network Protocol(SNP) Client for Snarl. You can send messages to Snarl over LAN.
|
4
|
+
|
5
|
+
Snarl is a popup-message application on Windows. Alike Growl.
|
6
|
+
http://www.fullphat.net/
|
7
|
+
SNP 1.0 documentation is here.
|
8
|
+
http://www.fullphat.net/dev/snp/index.htm
|
9
|
+
|
10
|
+
If you are able to read Japanese, please read README.rdoc.ja.
|
11
|
+
|
12
|
+
== Requirements
|
13
|
+
|
14
|
+
- Ruby 1.8.6 or later (including 1.9.1)
|
15
|
+
|
16
|
+
== Installation
|
17
|
+
|
18
|
+
gem install snarl-snp
|
19
|
+
|
20
|
+
No other gems are required (only to test, WebMock is needed).
|
21
|
+
|
22
|
+
== Contact
|
23
|
+
|
24
|
+
ezookojo@gmail.com
|
25
|
+
http://d.hatena.ne.jp/kitamomonga/ (in Japanese)
|
26
|
+
|
27
|
+
== Short Exsamples
|
28
|
+
|
29
|
+
@host is a Windows machine host which is running Snarl (LAN only).
|
30
|
+
Set the value in advance, then copy and paste codes on irb.
|
31
|
+
|
32
|
+
@host = '192.168.0.2' # Snarl machine host
|
33
|
+
|
34
|
+
When nil/undef, Snarl::SNP uses '127.0.0.1'. Default port is 9887.
|
35
|
+
|
36
|
+
=== Simple Popup (anonymous application)
|
37
|
+
|
38
|
+
require 'rubygems'
|
39
|
+
require 'snarl/snp'
|
40
|
+
Snarl::SNP.show_message(@host, 'title', 'Hello, Snarl!')
|
41
|
+
|
42
|
+
or
|
43
|
+
|
44
|
+
Snarl::SNP.new(@host).notification('title', 'Hello, Snarl!')
|
45
|
+
Snarl::SNP.open(@host){|snp| snp.notification('title', 'Hello, Snarl!')}
|
46
|
+
|
47
|
+
Snarl::SNP can simply send message in this way, but you cannot change popup settings on Snarl.
|
48
|
+
If you want to change popup settings(i.e. changing a color style), at least register an "application name".
|
49
|
+
|
50
|
+
NOTE: The multibyte anonymous application messages may not work well.
|
51
|
+
|
52
|
+
=== Popup Application (anonymous class)
|
53
|
+
|
54
|
+
require 'rubygems'
|
55
|
+
require 'snarl/snp'
|
56
|
+
Snarl::SNP.open(@host) do |snp|
|
57
|
+
snp.register('Ruby-Snarl')
|
58
|
+
snp.notification('title', 'text', nil, 10)
|
59
|
+
end
|
60
|
+
# if you wish
|
61
|
+
# Snarl::SNP.new(@host).unregister('Ruby-Snarl')
|
62
|
+
|
63
|
+
"application name" is Ruby-Snarl.
|
64
|
+
On Snarl, it's shown in "Apps" - "The following applications are registered with Snarl:" - "Ruby-Snarl on xxx.xxx.xxx.xxx".
|
65
|
+
You can change popup settings now.
|
66
|
+
If you want to classify messages(i.e. a green popup message, a red popup message, ...), set classes.
|
67
|
+
|
68
|
+
=== Unregister Application (remove application setting from Snarl)
|
69
|
+
|
70
|
+
When sending "unregister" or starting Snarl, application names are hideen from setting window.
|
71
|
+
|
72
|
+
require 'rubygems'
|
73
|
+
require 'snarl/snp'
|
74
|
+
Snarl::SNP.open(@host) do |snp|
|
75
|
+
snp.unregister('Ruby-Snarl')
|
76
|
+
end
|
77
|
+
|
78
|
+
An unregister command makes the application "inactive".
|
79
|
+
The application is removed from Snarl setting window, and Snarl users can not change their popup settings.
|
80
|
+
If you wish to allow users to change the popup settings, you should not use unregister commands on your usual scripts.
|
81
|
+
|
82
|
+
=== Popup Application (full)
|
83
|
+
|
84
|
+
require 'rubygems'
|
85
|
+
require 'snarl/snp'
|
86
|
+
Snarl::SNP.open(@host) do |snp|
|
87
|
+
snp.register('Ruby-Snarl')
|
88
|
+
snp.add_class('type1')
|
89
|
+
snp.add_class('type2')
|
90
|
+
snp.notification('title', 'type1 text', nil, 10, 'type1')
|
91
|
+
snp.notification('title', 'type2 text', nil, 10, 'type2')
|
92
|
+
end
|
93
|
+
# if you wish
|
94
|
+
# Snarl::SNP.new(@host).unregister('Ruby-Snarl')
|
95
|
+
|
96
|
+
Classes are used for message classification. They are shown in "Apps" - "Notification classes:".
|
97
|
+
If you change style of "type1" class on Snarl, all "type1" messages of application "Ruby-Snarl" pop in your way.
|
98
|
+
|
99
|
+
=== Send SNP raw command strings
|
100
|
+
|
101
|
+
require 'rubygems'
|
102
|
+
require 'snarl/snp'
|
103
|
+
Snarl::SNP.open(@host) do |snp|
|
104
|
+
snp.request("type=SNP#?version=1.1#?action=register#?app=Ruby-Snarl\r\n")
|
105
|
+
snp.request("type=SNP#?version=1.1#?action=add_class#?app=Ruby-Snarl#?class=type1\r\n")
|
106
|
+
snp.request("type=SNP#?version=1.1#?action=add_class#?app=Ruby-Snarl#?class=type2\r\n")
|
107
|
+
snp.request("type=SNP#?version=1.1#?action=notification#?app=Ruby-Snarl#?class=type1#?title=title#?text=type1 text!#?timeout=10\r\n")
|
108
|
+
snp.request("type=SNP#?version=1.1#?action=notification#?app=Ruby-Snarl#?class=type2#?title=title#?text=type2 text!#?timeout=10\r\n")
|
109
|
+
end
|
110
|
+
# if you wish
|
111
|
+
Snarl::SNP.new(@host).request("type=SNP#?version=1.1#?action=unregister#?app=Ruby-Snarl\r\n")
|
112
|
+
|
113
|
+
"\r\n" is must.
|
114
|
+
Don't use "\r\n" or "\r" in message body. Use "\n" instead.
|
115
|
+
|
116
|
+
=== Multibyte Popup
|
117
|
+
|
118
|
+
require 'rubygems'
|
119
|
+
require 'snarl/snp'
|
120
|
+
require 'kconv'
|
121
|
+
Snarl::SNP.open(@host){|snp| snp.notification('タイトル'.tosjis, '日本語'.tosjis)}
|
122
|
+
|
123
|
+
Windows encoding is required.
|
124
|
+
|
125
|
+
== FAQ
|
126
|
+
|
127
|
+
=== My autotest/autospec shutdowns after test. Snarl got no message.
|
128
|
+
|
129
|
+
Set Autotest::Snarl.host on ".autotest" file.
|
130
|
+
|
131
|
+
require 'snarl/autotest'
|
132
|
+
Autotest::Snarl.host = '192.168.0.1'
|
133
|
+
|
134
|
+
You may set OS environment variable SNARL_HOST.
|
135
|
+
Autotest::Snarl uses it instead of default host 127.0.0.1.
|
136
|
+
If you use Snarl on 192.168.0.1 (and use bash as a shell),
|
137
|
+
|
138
|
+
SNARL_HOST=192.168.0.1 autotest
|
139
|
+
|
140
|
+
== Copyright
|
141
|
+
|
142
|
+
Copyright (c) 2010 kitamomonga (TATEWAKI Hiroyuki).
|
143
|
+
This software is MIT license, see MIT-LICENSE file for details.
|
144
|
+
Snarl and SNP is not mine. See http://www.fullphat.net/ .
|
data/README.rdoc.ja
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
-*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
= Snarl-SNP
|
4
|
+
|
5
|
+
snarl/snp(snarl-snp)は、Snarl を LAN 越しに操作するための SNP プロトコルクライアントを提供します。
|
6
|
+
Ruby スクリプトの結果(の30字くらい)を Snarl に送ることができます。
|
7
|
+
|
8
|
+
Snarl は Windows で動作する、Growl っぽい通知ポップアップを行うソフトウェアです。
|
9
|
+
http://www.fullphat.net/
|
10
|
+
|
11
|
+
SNP は Snarl Networking Protocol です。SNP1.1 は文書化されていませんが、1.0 は以下の場所にあります。
|
12
|
+
http://www.fullphat.net/dev/snp/index.htm
|
13
|
+
|
14
|
+
== Requirements
|
15
|
+
|
16
|
+
- Ruby 1.8.6 or later (including 1.9.1)
|
17
|
+
|
18
|
+
今のところ必要な追加ライブラリはありません。
|
19
|
+
|
20
|
+
== Installation
|
21
|
+
|
22
|
+
gem install snarl-snp
|
23
|
+
|
24
|
+
内部では Rubygems を使用してないので、lib/snarl/snp.rb と lib/snarl/snp/ だけあればたぶん動きます。
|
25
|
+
|
26
|
+
== Contact
|
27
|
+
|
28
|
+
ezookojo@gmail.com
|
29
|
+
きたももんががきたん。
|
30
|
+
http://d.hatena.ne.jp/kitamomonga/
|
31
|
+
|
32
|
+
== License
|
33
|
+
|
34
|
+
MIT License です。使用改変配布商用等を無制限に許可し、ソフトウェアに関する責任は全く負わないものとします。
|
35
|
+
正確には MIT-LICENSE ファイルを http://sourceforge.jp/projects/opensource/wiki/licenses%2FMIT_license などを参考に読んでください。
|
36
|
+
|
37
|
+
== Usage
|
38
|
+
|
39
|
+
require 'rubygems'
|
40
|
+
require 'snarl/snp'
|
41
|
+
require 'kconv' # on Ruby 1.8
|
42
|
+
|
43
|
+
Snalr::SNP.open(Snarlが動いてるホスト) do |snp|
|
44
|
+
snp.register(設定区別用アプリケーション名)
|
45
|
+
snp.notification(メッセージ.tosjis) # toutf8かもしれない
|
46
|
+
end
|
47
|
+
# メッセージ表示をメッセージ種別ごとに分けたい場合は add_class(種別用クラス名) でクラスを追加したあとでクラス指定つきの notification をする
|
48
|
+
# こちらの環境では日本語文字は Shift_JIS にする必要があるが世間様では UTF-8 で通るらしい(たぶんWindowsのバージョン依存)
|
49
|
+
|
50
|
+
== Short Exsamples
|
51
|
+
|
52
|
+
@host は Snarl の動作している Windows マシンのホスト名か IP アドレスです(TCPSocket.open で使えるもの)。Snarl 本体の仕様上、LAN 内限定です。
|
53
|
+
irb 上でコピペするときに便利なように、対象ホストは @host としか書いてません。事前に設定しておいてください。
|
54
|
+
|
55
|
+
@host = '192.168.0.2' # Snarl machine host
|
56
|
+
|
57
|
+
Snarl が動作しているマシン上でスクリプトを動作させる場合は無設定の nil か "127.0.0.1" で OK です。
|
58
|
+
何らかの理由で接続できない場合は Errno::ECONNREFUSED が出ます。
|
59
|
+
|
60
|
+
=== Popup Application (anonymous class)
|
61
|
+
|
62
|
+
require 'rubygems'
|
63
|
+
require 'snarl/snp'
|
64
|
+
Snarl::SNP.open(@host) do |snp|
|
65
|
+
snp.register('Ruby-Snarl')
|
66
|
+
snp.notification('title', 'text', nil, 10)
|
67
|
+
end
|
68
|
+
# if you wish
|
69
|
+
# Snarl::SNP.new(@host).unregister('Ruby-Snarl')
|
70
|
+
|
71
|
+
Snarl の設定画面では「Ruby-Snarl」と名づけられます。
|
72
|
+
ポップアップメッセージは「title」「text」という2行で、標準アイコンつきで10秒表示されます。
|
73
|
+
|
74
|
+
=== Unregister Application (remove application setting from Snarl)
|
75
|
+
|
76
|
+
require 'rubygems'
|
77
|
+
require 'snarl/snp'
|
78
|
+
Snarl::SNP.open(@host) do |snp|
|
79
|
+
snp.unregister('Ruby-Snarl')
|
80
|
+
end
|
81
|
+
|
82
|
+
unregister は Snarl のポップアップ動作設定画面からアプリケーションを一旦削除します。
|
83
|
+
register -> unregister という流れ的には使うべきっぽいんですが意外と不便なので多用しないことをお勧めします。
|
84
|
+
設定された内容自体は Snarl のユーザーファイルに保存されており、register コマンドが来たときに再度ロードされます。
|
85
|
+
|
86
|
+
アプリケーションは Snarl を再起動すると画面からは一旦消えます(unregister と同じ動作)。設定完全消去はファイルを編集します。
|
87
|
+
|
88
|
+
=== Popup Application (full)
|
89
|
+
|
90
|
+
require 'rubygems'
|
91
|
+
require 'snarl/snp'
|
92
|
+
Snarl::SNP.open(@host) do |snp|
|
93
|
+
snp.register('Ruby-Snarl')
|
94
|
+
snp.add_class('type1')
|
95
|
+
snp.add_class('type2')
|
96
|
+
snp.notification('title', 'type1 text', nil, 10, 'type1')
|
97
|
+
snp.notification(:title => 'title', :text => 'type2 text', :icon => nil, :timeout => 7, :class => 'type2')
|
98
|
+
end
|
99
|
+
# if you wish
|
100
|
+
# Snarl::SNP.new(@host).unregister('Ruby-Snarl')
|
101
|
+
|
102
|
+
add_class でクラス名を指定することも出来ます(Ruby の Class オブジェクトとは無関係です)。
|
103
|
+
Snarl の設定画面では「Ruby-Snarl の中のクラス type1」という区分で、ポップアップスタイル等を変更できます。
|
104
|
+
メッセージごとにウィンドウの色などを変えたいときに便利です。
|
105
|
+
クラス名の設定は notification の第 5 引数になりますが、若干長いのでキーワード引数指定の活用などもどうぞ。
|
106
|
+
|
107
|
+
=== Send SNP raw command strings
|
108
|
+
|
109
|
+
require 'rubygems'
|
110
|
+
require 'snarl/snp'
|
111
|
+
Snarl::SNP.open(@host) do |snp|
|
112
|
+
snp.request("type=SNP#?version=1.1#?action=register#?app=Ruby-Snarl\r\n")
|
113
|
+
snp.request("type=SNP#?version=1.1#?action=add_class#?app=Ruby-Snarl#?class=type1\r\n")
|
114
|
+
snp.request("type=SNP#?version=1.1#?action=add_class#?app=Ruby-Snarl#?class=type2\r\n")
|
115
|
+
snp.request("type=SNP#?version=1.1#?action=notification#?app=Ruby-Snarl#?class=type1#?title=title#?text=type1 text!#?timeout=10\r\n")
|
116
|
+
snp.request("type=SNP#?version=1.1#?action=notification#?app=Ruby-Snarl#?class=type2#?title=title#?text=type2 text!#?timeout=10\r\n")
|
117
|
+
end
|
118
|
+
# if you wish
|
119
|
+
# Snarl::SNP.new(@host).request("type=SNP#?version=1.1#?action=unregister#?app=Ruby-Snarl\r\n")
|
120
|
+
|
121
|
+
本来の SNP のコマンドを直接送ります。デバッグ用途などお好みで。Fatal なエラーはふつうに例外になります。
|
122
|
+
終端の \r\n は必須です。自動で付加することはありません。本文に \r が入っていると Snarl がそこでコマンド文字列を切ってしまうので改行は \n だけにしてください。なお、notification などでは内部処理されて取り除かれています。
|
123
|
+
|
124
|
+
=== Multibyte Popup
|
125
|
+
|
126
|
+
require 'rubygems'
|
127
|
+
require 'snarl/snp'
|
128
|
+
require 'kconv'
|
129
|
+
Snarl::SNP.open(@host){|snp| snp.notification('タイトル'.tosjis, '日本語'.tosjis)}
|
130
|
+
|
131
|
+
対象の Snarl が動作している Windows で使用されているエンコーディングに変換して文字列を送ってください。
|
132
|
+
|
133
|
+
== FAQ
|
134
|
+
|
135
|
+
=== autotest または autospec がポップアップを出さずに普通に終了してしまう
|
136
|
+
|
137
|
+
Snarl::SNP が接続できなくてエラーを返しているのだと思われます。
|
138
|
+
ホームディレクトリなどにある .autotest ファイルに Autotest::Snarl.host = '192.168.0.2' などと書いてください。
|
139
|
+
|
140
|
+
require 'snarl/autotest'
|
141
|
+
Autotest::Snarl.host = '192.168.0.2'
|
142
|
+
|
143
|
+
autotest コマンドを環境変数 SNARL_HOST つきで起動しても構いません。Linux 上の bash だと
|
144
|
+
|
145
|
+
SNARL_HOST=192.168.0.1 autotest
|
146
|
+
|
147
|
+
などとすることでうまくいきます。
|
148
|
+
|
149
|
+
=== Snarl::SNP.show_message で日本語が化ける
|
150
|
+
|
151
|
+
化ける場合は SNP か Snarl の仕様かもしれません。適当に register してから notification(title, text) を使ってください。
|
152
|
+
app コマンドの指定がない notification アクションはなぜか日本語が化けます。
|
153
|
+
事前に register されている場合、メッセージが ascii 文字だけの場合は問題ありません。
|
154
|
+
|
155
|
+
show_message のウリは「Snarlの設定ファイルを汚さない匿名アプリケーションメッセージ」ですが、無論 register してしまうと Snarl に記録されます。
|
156
|
+
引数なしで register とだけ書くとデフォルトの Snarl::SNP::DEFAULT_APP が使用されますので、アプリケーション名をいちいち考えるのが煩雑な雑多なメッセージの場合はこれで代用するとやや簡便です。
|
157
|
+
|
158
|
+
Snarl::SNP.open(@host) do |snp|
|
159
|
+
snp.register
|
160
|
+
snp.notification('ごはんが炊けたよ')
|
161
|
+
end
|
162
|
+
|
163
|
+
=== SNP.open はいつ TCP ソケットを使用している?
|
164
|
+
|
165
|
+
SNP コマンドを送る瞬間だけ TCPSocket.open(@host, @port){|s| s.write(cmdstr)} してます。
|
166
|
+
ブロックつき open なのに、効率とかなにそれって感じでいちいちセッション切ってます。
|