snarl-snp 0.1.1 → 0.2.0

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.
@@ -1,13 +1,13 @@
1
1
  = snarl-snp
2
2
 
3
- Snarl Network Protocol(SNP) Client for Snarl. You can send messages to Snarl over LAN.
3
+ Snarl Network Protocol(SNP) Client for Snarl. You can send messages to Snarl on LAN.
4
4
 
5
5
  Snarl is a popup-message application on Windows. Alike Growl.
6
6
  http://www.fullphat.net/
7
7
  SNP 1.0 documentation is here.
8
8
  http://www.fullphat.net/dev/snp/index.htm
9
9
 
10
- If you are able to read Japanese, please read README.rdoc.ja.
10
+ If you are able to read Japanese, please read doc-ja/README.rdoc.ja.
11
11
 
12
12
  == Requirements
13
13
 
@@ -17,7 +17,7 @@ If you are able to read Japanese, please read README.rdoc.ja.
17
17
 
18
18
  gem install snarl-snp
19
19
 
20
- No other gems are required (only to test, WebMock is needed).
20
+ No other gems are required.
21
21
 
22
22
  == Contact
23
23
 
@@ -33,6 +33,65 @@ Set the value in advance, then copy and paste codes on irb.
33
33
 
34
34
  When nil/undef, Snarl::SNP uses '127.0.0.1'. Default port is 9887.
35
35
 
36
+ === SNP with YAML
37
+
38
+ 0.2.0 feature. It maybe seems to be easy.
39
+
40
+ require 'rubygems'
41
+ require 'snarl/snp'
42
+ Snarl::SNP.load(<<YAML)
43
+ host : #{@host}
44
+ app : Ruby-Snarl
45
+ title : popup title
46
+ text : hello!
47
+ timeout : 5
48
+ unregister : false
49
+ YAML
50
+
51
+ require 'rubygems'
52
+ require 'snarl/snp'
53
+ yaml = <<YAML
54
+ host : #{@host}
55
+ app : Ruby-Snarl
56
+ class :
57
+ - [class1, name1]
58
+ - [class2, name2]
59
+ YAML
60
+ Snarl::SNP.load(yaml) do |snp|
61
+ snp.notification(:title => 'title', :text => 'text', :class => 'class1')
62
+ end
63
+
64
+ require 'rubygems'
65
+ require 'snarl/snp'
66
+ Snarl::SNP.load(<<YAML)
67
+ host : #{@host}
68
+ app : Ruby-Snarl
69
+ class :
70
+ - [class1, name1]
71
+ - [class2, name2]
72
+ notification :
73
+ title : title
74
+ text : text
75
+ class : class1
76
+ logfile : $stdout
77
+ YAML
78
+
79
+ require 'rubygems'
80
+ require 'snarl/snp'
81
+ Snarl::SNP.load(<<YAML)
82
+ host : #{@host}
83
+ app : Ruby-Snarl
84
+ notification :
85
+ -
86
+ title : 1st post!
87
+ text : message1
88
+ -
89
+ title : 2nd post!
90
+ text : message2
91
+ YAML
92
+
93
+ For YAML details, see YAML.rdoc.
94
+
36
95
  === Simple Popup (anonymous application)
37
96
 
38
97
  require 'rubygems'
@@ -120,7 +179,30 @@ Don't use "\r\n" or "\r" in message body. Use "\n" instead.
120
179
  require 'kconv'
121
180
  Snarl::SNP.open(@host){|snp| snp.notification('タイトル'.tosjis, '日本語'.tosjis)}
122
181
 
123
- Windows encoding is required.
182
+ Windows encoding is required. Windows 2000 is Shift_JIS (CP932), XP is UTF-8, maybe.
183
+
184
+ == SNP on command line
185
+
186
+ bin/snarl_snp is available.
187
+
188
+ snarl_snp -H host -a app -t title -m message
189
+
190
+ snarl_snp --yaml=./snp.yml
191
+
192
+ and so on.
193
+
194
+ [-H host, --host=host] the hostname/address which Snarl is running (default, 127.0.0.1). -h shows help. "H"ost. Sorry.
195
+ [-p port, --port=port] the port number which Snarl uses (default, 9887)
196
+ [-a app, --app=app] the application name you use on Snarl (default, nothing). It's read in SNP#register(app)
197
+ [-c class, --class=class] the classname you use on Snarl (default, nothing). It's read in SNP#add_class and notification
198
+ [-t title, --title=title] the title string of popup (default 'Ruby-Snarl').
199
+ [-m msg, --text=msg] the popup message body.
200
+ [-s sec, --timeout=sec] popups automatically close in sec (default 10 sec.). -t is not for timeout but title.
201
+ [--icon=icon_path] popup message icon path (default, default style's icon). URL or filepath on Snarl machine. JPG/PNG/GIF
202
+ [--sticky] makes popup "sticky" (default, closes in timeout sec). this is equal to "--timeout=0".
203
+ [-u, --unregister] removes app from Snarl setting window (default, false). note: users cannot change app's setting.
204
+ [--verbose] shows SNP logs to stdout (default, false)
205
+ [-y yamlpath, --yaml=yamlpath] the YAML file path for "automatic SNP" (default, nothing)
124
206
 
125
207
  == FAQ
126
208
 
data/Rakefile CHANGED
@@ -5,13 +5,12 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "snarl-snp"
8
- gem.summary = %Q{Snarl Network Protocol Client. You can notify to Snarl over LAN.}
9
- gem.description = %Q{Snarl Network Protocol Client. Snarl is the notification program for Windows. You can send notification messages to Snarl with SNP over LAN.}
8
+ gem.summary = %Q{Snarl Network Protocol Client. You can notify to Snarl on LAN.}
9
+ gem.description = %Q{Snarl Network Protocol Client. Snarl is the notification program for Windows. You can send notification messages to Snarl with SNP on LAN.}
10
10
  gem.email = "ezookojo@gmail.com"
11
11
  gem.homepage = "http://github.com/kitamomonga/snarl-snp"
12
12
  gem.authors = ["kitamomonga"]
13
13
  gem.add_development_dependency "rspec", ">= 1.2.9"
14
- gem.add_development_dependency "webmock"
15
14
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
15
  end
17
16
  Jeweler::GemcutterTasks.new
@@ -43,5 +42,7 @@ Rake::RDocTask.new do |rdoc|
43
42
  rdoc.title = "snarl-snp #{version}"
44
43
  rdoc.rdoc_files.include('README.rdoc*')
45
44
  rdoc.rdoc_files.include('GUIDE.rdoc*')
45
+ rdoc.rdoc_files.include('YAML.rdoc*')
46
46
  rdoc.rdoc_files.include('lib/**/*.rb')
47
+ rdoc.rdoc_files.include('doc-ja/**/*rdoc.ja')
47
48
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -0,0 +1,197 @@
1
+ = YAML for Snarl::SNP.load(yaml)
2
+
3
+ NOTE: YAML is linehead-space-sensitive. When you run samples, remove 4 white spaces from each line head.
4
+
5
+ - Values from YAML are always overwriten by Snarl::SNP methods' arguments.
6
+
7
+ snp = Snarl::SNP.load(<<YAML)
8
+ title : yaml title!
9
+ YAML
10
+ snp.notification(:title => 'new title') #=> "new title"
11
+
12
+ - nil value / empty value / undef key are considerd as 'it is not set on yaml'.
13
+
14
+ - class : nil
15
+ - class : []
16
+ (there is no 'class')
17
+
18
+ == text and title
19
+
20
+ If
21
+ - there is "text : ..." field or "title : ..." field
22
+ and
23
+ - there is no "notification : ..." field,
24
+ Snarl::SNP.load(yaml) makes notification massage with "text :", "title :", "timeout :", "icon :" and "class :".
25
+
26
+ === host
27
+
28
+ host : 192.168.0.2
29
+
30
+ The hostname/address of Snarl Machine. (This is used as TCPSocket.open(host)).
31
+ If nothing is set on yaml and methods arguments, last 'host' value is 127.0.0.1.
32
+
33
+ === port
34
+
35
+ port : 9887
36
+
37
+ The port number which Snarl uses. 9887. (This is used as TCPSocket.open(host, port)).
38
+ If nothing is set on yaml and methods arguments, last 'port' value is 9887.
39
+
40
+ === app, name, register
41
+
42
+ app : Ruby-Snarl
43
+
44
+ The application name. This is shown on Snarl setting window. (This is used as Snarl::SNP#register(app))
45
+ If nothing is set on yaml and methods arguments, last 'app' value is nil. "anonymous application message".
46
+
47
+ === class, add_class
48
+
49
+ class :
50
+ - [classname1, classtitle1]
51
+ - [classname2, classtitle2]
52
+
53
+ The classname and classtitle alias.
54
+ The classname is used for classifing your message.
55
+ The classtitle is shown on Snarl setting window(it is optional. if nil, classname is shown).
56
+ (This is used as SNP#add_class(classname1, classtitle1) and SNP#notification(:text => text, :class => classname1))
57
+ If nothing is set on yaml and methods arguments, last 'class' value is nil. "anonymous class message".
58
+
59
+ class : classname1
60
+
61
+ class : [classname1, classname2, classname3]
62
+
63
+ class :
64
+ - [classname1, classtitle1]
65
+ or
66
+ class : [[classname1, classtitle1]]
67
+
68
+ === title
69
+
70
+ title : message title
71
+
72
+ The title of popup messages.
73
+ If there is no "notification : ..." field, SNP#notification makes message with this value as title.
74
+ When "notification : ..." has no 'title' key, SNP#notification uses this value as notification title.
75
+ If nothing is set on yaml and methods arguments, last 'title' value is Ruby-Snarl.
76
+
77
+ === text, message
78
+
79
+ text : hello, Ruby!
80
+
81
+ The body of popup messages.
82
+ If there is no "notification : ..." field, SNP#notification makes message with this value as body text.
83
+ When "notification : ..." has no 'text' key, SNP#notification uses this value as notification body.
84
+ If nothing is set on yaml and methods arguments, last 'body' value is nil. empty body message.
85
+
86
+ === timeout, sec
87
+
88
+ timeout : 30
89
+
90
+ The "timeout" seconds of popups. After this seconds, popups are automatically closed.
91
+ If SNP#notification makes message for lack of "notification : ..." field, SNP#notification uses this value as timeout.
92
+ When "notification : ..." has no 'timeout' key, SNP#notification uses this value as notification timeout.
93
+ "timeout : 0" makes popups "sticky". popups never close by time.
94
+ If nothing is set on yaml and methods arguments, last 'timeout' value is 10.
95
+
96
+ === sticky
97
+
98
+ sticky : true
99
+
100
+ makes popups "sticky". It is same to "timeout : 0". It is mainly for snarl_snp command. Do not use.
101
+ If nothing is set on yaml, sticky is false.
102
+
103
+ === icon
104
+
105
+ icon : http://exsample.com/good.png
106
+
107
+ The icon path of popups. The popup has this images as icon.
108
+ If SNP#notification makes message for lack of "notification : ..." field, SNP#notification uses this value as icon.
109
+ When "notification : ..." has no 'icon' key, SNP#notification uses this value as notification icon.
110
+
111
+ The value is URL or filepath. The filepath should be accessable an absolute/relative path on Snarl machine.
112
+ Image types are Jpeg, PNG, GIF, and so on.
113
+ If nothing is set on yaml and methods arguments, last 'icon' value is nil. The icon will be a style's default icon.
114
+
115
+ === notification
116
+
117
+ notifitation : [title, text, icon.jpg, 9, classname]
118
+ or
119
+ notifitation :
120
+ title : title
121
+ text : text
122
+ icon : icon.jpg
123
+ timeout : 9
124
+ class : classname
125
+ or
126
+ notifitation :
127
+ -
128
+ title : 1st message
129
+ text : one
130
+ -
131
+ title : 2nd message
132
+ text : two
133
+ - { title : 3rd message, title : three }
134
+
135
+ The popup messages. This is for Snarl::SNP#notification(params). params is Array or Hash above.
136
+
137
+ If notification field has no key of 'title', 'text', 'icon', 'timeout', and top fields has same name one, SNP#notification uses top fields' value as its arguments.
138
+
139
+ # actually same message
140
+ notifitation :
141
+ title : title
142
+ text : text
143
+ timeout : 9
144
+
145
+ title : title
146
+ timeout : 9
147
+ notifitation :
148
+ text : text
149
+
150
+ If there is no "notifitation : " field (and no "title : " and "text :" field), Snarl::SNP.load(yaml) sends no notifitation message.
151
+
152
+ === unregister
153
+
154
+ unregister : true
155
+
156
+ removes application from Snarl setting window.
157
+ If true, application is removed from Snarl settings after closing Snarl::SNP.load(yaml){...} block,
158
+ and users are not able to change application settings.
159
+
160
+ === logfile
161
+
162
+ logfile : $stdout
163
+
164
+ SNP logs are put to this path's file. Logger.new(logfile).
165
+ YAML value is always String, but '$stdout' and '$stderr' are treated as Ruby's $stdout IO and $stderr IO.
166
+ If you set "logfile : $stdout", SNP logs are printed to standard output.
167
+ If you set "logfile : $stderr", SNP logs are printed to standard error.
168
+
169
+ If nothing is set on yaml and methods arguments, last 'logfile' value is nil. No log messages are printed.
170
+
171
+ === loglevel
172
+
173
+ loglevel : INFO
174
+
175
+ The loglevel for logger output. "logfile : " field is required. (or, SNP.load(yaml, logger) is also ok)
176
+ The values are DEBUG, INFO, WARN, ERROR, FATAL (they are not case-sensitive) or 0, 1, 2, 3, 4.
177
+
178
+ ERROR (or 3) :: Snarl error, TCPSocket connection fail
179
+ INFO (or 1) :: ERROR, and SNP response code
180
+ DEBUG (or 0) :: INFO, and sent string to Snarl
181
+
182
+ If loglevel is nil/unset (and there is any logger), loglevel is DEBUG. All logs are printed.
183
+
184
+ === iconset
185
+
186
+ iconset :
187
+ ok : ./green.jpg
188
+ fail : ./red.jpg
189
+ notification :
190
+ title : Good!
191
+ text : no errors.
192
+ icon : ok
193
+
194
+ The icons for notification.
195
+ It works as "icon : ./green.jpg", and
196
+ snp.notification(:title => title, :text => text, :icon => iconset['ok'])
197
+ .
@@ -0,0 +1,112 @@
1
+ #!/usr/local/bin/ruby
2
+ require 'optparse'
3
+ require 'yaml'
4
+ $LOAD_PATH.unshift(File.join(File.dirname(File.expand_path(__FILE__)), '/../lib/'))
5
+ require 'snarl/snp'
6
+
7
+ class SNPBin
8
+
9
+ BINCMD_OPTION = {
10
+ "host" => {
11
+ :opt => ['-H host', '--host=host'],
12
+ :help => "the host address to send notification message. if you run on Snarl machine, set 'localhost' or '127.0.0.1'. Default: localhost"
13
+ },
14
+ "port" => {
15
+ :opt => ['-p port', '--port=port'],
16
+ :help => "the port to send notification message. SNP default is 9887. Default: 9887"
17
+ },
18
+ "app" => {
19
+ :opt => ['-a app', '--app=app'],
20
+ :help => "the name of your messaging program. this is shown on Snarl Setting window until unregister. Default: (nothing, anonymous application)"
21
+ },
22
+ "class" => {
23
+ :opt => ['-c class', '--class=class',],
24
+ :help => "the class type of message. same classed message is treated as a 'same class' message. Default:(nothing, anonymous class)"
25
+ },
26
+ "title" => {
27
+ :opt => ['-t title', '--title=title'],
28
+ :help => "the notification message title. Default: Ruby-Snarl" # default maybe
29
+ },
30
+ "timeout" => {
31
+ :opt => ['-s sec', '-d sec', '--span=sec', '--timeout=sec', '--duration=sec'],
32
+ :help => "the popup duration time(seccond). when sec=0, popup is sticky (never automatically closed). Default: 10"
33
+ },
34
+ "sticky" => {
35
+ :opt => ['--sticky'],
36
+ :help => "make notification message 'sticky'. the message popup never closes automatically. -s sec option are ignored."
37
+ },
38
+ "icon" => {
39
+ :opt => ['--icon=url_or_path'],
40
+ :help => "the icon path for notification message. http URL or absolute path or relative path (relative to Snarl work dir). image type are JPEG, GIF, PNG. Default: (nothing, default icon of Snarl style)"
41
+ },
42
+ "text" => {
43
+ :opt => ['-m message_text', '--message=message_text', '--text=message_text'],
44
+ :help => "the notification message text."
45
+ },
46
+ # "notification" => ['-n notification_subcmd_set'] # TODO:
47
+ "unregister" => {
48
+ :opt => ['-u', '--unregister'],
49
+ :help => "unregister application on Snarl setting after notification. Default (unset)"
50
+ },
51
+ "verbose" => {
52
+ :opt => ['--verbose'],
53
+ :help => "print SNP log to stdout"
54
+ },
55
+ "yaml" => {
56
+ :opt => ['-y yaml_or_path', '--yaml=yaml_or_path', '--config=yaml_or_path'],
57
+ :help => "read and set paramater from YAML file or YAML string. for yaml details, see YAML.rdoc"
58
+ },
59
+ }
60
+ # --yaml #=> YAML String / --config #=> YAML path
61
+ # --silent / --quiet / --verbose
62
+
63
+ def initialize
64
+ @argv_option = {}
65
+ @config = {}
66
+ end
67
+
68
+ attr_reader :argv_option, :config
69
+
70
+ def parse_argv
71
+ OptionParser.new do |opt|
72
+ BINCMD_OPTION.each do |name, data|
73
+ instance_eval "opt.on(*(#{data[:opt].inspect} << \"#{data[:help]}\")){|v| @argv_option[\"#{name}\"] = v}"
74
+ end
75
+ opt.parse!(ARGV)
76
+ end
77
+ end
78
+
79
+ def merge_yaml_from_argvopt
80
+ if @argv_option['yaml'] then
81
+ @config.update(YAML.load(File.open(@argv_option['yaml']){|f| f.read}))
82
+ @argv_option.delete('yaml')
83
+ end
84
+ end
85
+ def merge_all_argvopt_to_config
86
+ @config.update(@argv_option)
87
+ end
88
+ def pick_logger
89
+ if @argv_option['verbose'] then
90
+ require 'logger'
91
+ @logger = Logger.new($stdout)
92
+ @argv_option.delete('verbose')
93
+ else
94
+ @logger = nil
95
+ end
96
+ end
97
+
98
+ def exec_snplib
99
+ # oh reconvert to yaml
100
+ Snarl::SNP.load(@config.to_yaml, @logger)
101
+ end
102
+
103
+ def run
104
+ parse_argv
105
+ merge_yaml_from_argvopt
106
+ pick_logger
107
+ merge_all_argvopt_to_config
108
+ exec_snplib
109
+ end
110
+ end
111
+
112
+ SNPBin.new.run unless defined?(TEST_SNARL_SNP_BIN_SPEC)