snarl-snp 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +86 -4
- data/Rakefile +4 -3
- data/VERSION +1 -1
- data/YAML.rdoc +197 -0
- data/bin/snarl_snp +112 -0
- data/{GUIDE.rdoc.ja → doc-ja/GUIDE.rdoc.ja} +0 -0
- data/{README.rdoc.ja → doc-ja/README.rdoc.ja} +94 -29
- data/doc-ja/YAML.rdoc.ja +200 -0
- data/exsample/yahoo_weather.rb +18 -4
- data/lib/snarl/autotest.rb +7 -77
- data/lib/snarl/snp.rb +4 -4
- data/lib/snarl/snp/action.rb +15 -11
- data/lib/snarl/snp/autosnp.rb +69 -0
- data/lib/snarl/snp/config.rb +109 -17
- data/lib/snarl/snp/error.rb +7 -6
- data/lib/snarl/snp/request.rb +31 -21
- data/lib/snarl/snp/response.rb +1 -0
- data/lib/snarl/snp/snp.rb +56 -41
- data/lib/snarl/snp/snp_procedure.rb +105 -0
- data/snarl-snp.gemspec +21 -15
- data/spec/bin/snarl_snp_spec.rb +91 -0
- data/spec/snp/action_spec.rb +149 -86
- data/spec/snp/config_spec.rb +181 -37
- data/spec/snp/real_connection_spec.rb +295 -0
- data/spec/snp/request_spec.rb +40 -10
- data/spec/snp/snp_procedure_spec.rb +226 -0
- data/spec/snp/snp_spec.rb +216 -193
- data/spec/spec_helper.rb +6 -4
- metadata +22 -27
- data/spec/exsample/data/weather_yahoo_co_jp.html +0 -608
- data/spec/exsample/yahoo_weather_spec.rb +0 -22
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'yaml' # some users don't use rubygems
|
2
|
+
class Snarl
|
3
|
+
class SNP
|
4
|
+
module SNPProcedure
|
5
|
+
def is_app_available? ; self['app'] && !self['app'].empty? ; end
|
6
|
+
def auto_register
|
7
|
+
if is_app_available? then
|
8
|
+
register(self['app'])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_class_available? ; self['class'] && !self['class'].empty? ; end
|
13
|
+
def auto_add_class
|
14
|
+
if is_app_available? && is_class_available? then
|
15
|
+
add_classes(*self['class'])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def is_notification_available? ; self['notification'] && !self['notification'].empty? ; end
|
20
|
+
def auto_notification
|
21
|
+
_notify_arg_is_array = is_notification_available? && self['notification'].kind_of?(Array)
|
22
|
+
_notify_arg_is_arraied_notify_hashes = is_notification_available? && self['notification'].first.kind_of?(Hash)
|
23
|
+
|
24
|
+
if is_notification_available? then
|
25
|
+
if _notify_arg_is_array then
|
26
|
+
if _notify_arg_is_arraied_notify_hashes then
|
27
|
+
# [{notify_hash1}, {notify_hash2}, ...]
|
28
|
+
self['notification'].map{|h| notification(h)}
|
29
|
+
else
|
30
|
+
# [title, text, timeout, icon, class]
|
31
|
+
notification(*self['notification'])
|
32
|
+
end
|
33
|
+
else
|
34
|
+
# {notify_hash}
|
35
|
+
notification(self['notification'])
|
36
|
+
end
|
37
|
+
else # config has no 'notification' key
|
38
|
+
# build notify arg from config
|
39
|
+
h = {}
|
40
|
+
h[:app] = self['app'] if self['app']
|
41
|
+
h[:title] = self['title'] if self['title']
|
42
|
+
h[:text] = self['text'] if self['text']
|
43
|
+
h[:timeout] = self['timeout'] if self['timeout']
|
44
|
+
h[:icon] = self['icon'] if self['icon']
|
45
|
+
h[:class] = self['class'][0][0] if is_class_available? # snp['class'] == [['clsnam', 'clstit']]
|
46
|
+
notification(h) if (h.has_key?(:text)||h.has_key?(:title))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private :is_app_available?, :is_class_available?, :is_notification_available?
|
51
|
+
|
52
|
+
def auto_unregister
|
53
|
+
if self['unregister'] && is_app_available? then
|
54
|
+
unregister(self['app'])
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def autoexecute_with_config!
|
59
|
+
[auto_register,
|
60
|
+
auto_add_class,
|
61
|
+
auto_notification]
|
62
|
+
end
|
63
|
+
|
64
|
+
def apply_yaml(yamldata)
|
65
|
+
YAML.load(yamldata).each do |k ,v|
|
66
|
+
self[k] = v
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def set_logger(arg_logger)
|
71
|
+
# TODO: support for another Logger
|
72
|
+
if arg_logger then
|
73
|
+
require 'logger' # FIXME: oh twice?
|
74
|
+
arg_logger = Logger.new(arg_logger) unless arg_logger.respond_to?(:warn)
|
75
|
+
self.logger = arg_logger
|
76
|
+
elsif self['logfile'] then
|
77
|
+
require 'logger' # FIXME: oh ...
|
78
|
+
logger = Logger.new(self['logfile'])
|
79
|
+
logger.level = self['loglevel'] if self['loglevel']
|
80
|
+
self.logger = logger
|
81
|
+
else
|
82
|
+
# do nothing
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def load(yamldata, logger = nil, &block)
|
87
|
+
apply_yaml(yamldata)
|
88
|
+
# apply/overwrite user Logger object
|
89
|
+
# yaml cannot make 'raw' Logger object
|
90
|
+
set_logger(logger)
|
91
|
+
begin
|
92
|
+
autoexecute_with_config!
|
93
|
+
block.call(self) if block_given?
|
94
|
+
ensure
|
95
|
+
auto_unregister
|
96
|
+
end
|
97
|
+
self
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.load(*args, &block)
|
102
|
+
self.new.load(*args, &block)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/snarl-snp.gemspec
CHANGED
@@ -5,42 +5,49 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{snarl-snp}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["kitamomonga"]
|
12
|
-
s.date = %q{2010-
|
13
|
-
s.
|
12
|
+
s.date = %q{2010-05-20}
|
13
|
+
s.default_executable = %q{snarl_snp}
|
14
|
+
s.description = %q{Snarl Network Protocol Client. Snarl is the notification program for Windows. You can send notification messages to Snarl with SNP on LAN.}
|
14
15
|
s.email = %q{ezookojo@gmail.com}
|
16
|
+
s.executables = ["snarl_snp"]
|
15
17
|
s.extra_rdoc_files = [
|
16
|
-
"README.rdoc"
|
17
|
-
"README.rdoc.ja"
|
18
|
+
"README.rdoc"
|
18
19
|
]
|
19
20
|
s.files = [
|
20
|
-
"
|
21
|
-
"MIT-LICENSE",
|
21
|
+
"MIT-LICENSE",
|
22
22
|
"README.rdoc",
|
23
|
-
"README.rdoc.ja",
|
24
23
|
"Rakefile",
|
25
24
|
"VERSION",
|
25
|
+
"YAML.rdoc",
|
26
|
+
"bin/snarl_snp",
|
27
|
+
"doc-ja/GUIDE.rdoc.ja",
|
28
|
+
"doc-ja/README.rdoc.ja",
|
29
|
+
"doc-ja/YAML.rdoc.ja",
|
26
30
|
"exsample/ping.rb",
|
27
31
|
"exsample/winamp_nowplaying.rb",
|
28
32
|
"exsample/yahoo_weather.rb",
|
29
33
|
"lib/snarl/autotest.rb",
|
30
34
|
"lib/snarl/snp.rb",
|
31
35
|
"lib/snarl/snp/action.rb",
|
36
|
+
"lib/snarl/snp/autosnp.rb",
|
32
37
|
"lib/snarl/snp/config.rb",
|
33
38
|
"lib/snarl/snp/error.rb",
|
34
39
|
"lib/snarl/snp/request.rb",
|
35
40
|
"lib/snarl/snp/response.rb",
|
36
41
|
"lib/snarl/snp/snp.rb",
|
42
|
+
"lib/snarl/snp/snp_procedure.rb",
|
37
43
|
"snarl-snp.gemspec",
|
38
|
-
"spec/
|
39
|
-
"spec/exsample/yahoo_weather_spec.rb",
|
44
|
+
"spec/bin/snarl_snp_spec.rb",
|
40
45
|
"spec/snp/action_spec.rb",
|
41
46
|
"spec/snp/config_spec.rb",
|
47
|
+
"spec/snp/real_connection_spec.rb",
|
42
48
|
"spec/snp/request_spec.rb",
|
43
49
|
"spec/snp/response_sprc.rb",
|
50
|
+
"spec/snp/snp_procedure_spec.rb",
|
44
51
|
"spec/snp/snp_spec.rb",
|
45
52
|
"spec/spec_helper.rb"
|
46
53
|
]
|
@@ -48,12 +55,14 @@ Gem::Specification.new do |s|
|
|
48
55
|
s.rdoc_options = ["--charset=UTF-8"]
|
49
56
|
s.require_paths = ["lib"]
|
50
57
|
s.rubygems_version = %q{1.3.6}
|
51
|
-
s.summary = %q{Snarl Network Protocol Client. You can notify to Snarl
|
58
|
+
s.summary = %q{Snarl Network Protocol Client. You can notify to Snarl on LAN.}
|
52
59
|
s.test_files = [
|
53
|
-
"spec/
|
60
|
+
"spec/bin/snarl_snp_spec.rb",
|
54
61
|
"spec/spec_helper.rb",
|
55
62
|
"spec/snp/config_spec.rb",
|
56
63
|
"spec/snp/response_sprc.rb",
|
64
|
+
"spec/snp/snp_procedure_spec.rb",
|
65
|
+
"spec/snp/real_connection_spec.rb",
|
57
66
|
"spec/snp/request_spec.rb",
|
58
67
|
"spec/snp/snp_spec.rb",
|
59
68
|
"spec/snp/action_spec.rb"
|
@@ -65,14 +74,11 @@ Gem::Specification.new do |s|
|
|
65
74
|
|
66
75
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
67
76
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
68
|
-
s.add_development_dependency(%q<webmock>, [">= 0"])
|
69
77
|
else
|
70
78
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
71
|
-
s.add_dependency(%q<webmock>, [">= 0"])
|
72
79
|
end
|
73
80
|
else
|
74
81
|
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
75
|
-
s.add_dependency(%q<webmock>, [">= 0"])
|
76
82
|
end
|
77
83
|
end
|
78
84
|
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# -*- coding:utf-8 -*-
|
2
|
+
require 'tempfile'
|
3
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
4
|
+
|
5
|
+
if defined?(TEST_SNARL_SNP_BIN_SPEC) then
|
6
|
+
class SNPBin
|
7
|
+
remove_const :"BINCMD_OPTION"
|
8
|
+
end
|
9
|
+
else
|
10
|
+
TEST_SNARL_SNP_BIN_SPEC=true
|
11
|
+
end
|
12
|
+
load File.expand_path(File.dirname(__FILE__) + '/../../bin/snarl_snp')
|
13
|
+
|
14
|
+
describe "SNPBin" do
|
15
|
+
|
16
|
+
before :all do
|
17
|
+
@argv_bak = ARGV.dup
|
18
|
+
end
|
19
|
+
after :all do
|
20
|
+
ARGV.replace(@argv_bak)
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "initialize" do
|
24
|
+
before do
|
25
|
+
@snpbin = SNPBin.new
|
26
|
+
end
|
27
|
+
it "initialize data" do
|
28
|
+
@snpbin.argv_option.should eql({})
|
29
|
+
@snpbin.config.should eql({})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "parse_argv" do
|
34
|
+
SNPBin::BINCMD_OPTION.each do |optname, opthash|
|
35
|
+
before do
|
36
|
+
ARGV.clear
|
37
|
+
@snpbin = SNPBin.new
|
38
|
+
end
|
39
|
+
# opthash[:opt] == ['-a app', '--app=app']
|
40
|
+
arg = opthash[:opt][0].split(/\s+|=/) # ['-a', 'app']
|
41
|
+
value = if arg[1] then "'#{arg[1]}'" else true end # ''app''
|
42
|
+
instance_eval(<<EOS)
|
43
|
+
it "when ARGV[1] = '#{opthash[:opt][0]}', set {'#{optname}' => #{value}} to @argv_option" do
|
44
|
+
ARGV.replace([__FILE__] + arg)
|
45
|
+
@snpbin.parse_argv
|
46
|
+
@snpbin.argv_option.should eql({'#{optname}' => #{value}})
|
47
|
+
end
|
48
|
+
EOS
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "merge_yaml_from_argvopt" do
|
53
|
+
before do
|
54
|
+
@yamlfile = Tempfile.new('snarlsnpbinsnarlsnpspecrb')
|
55
|
+
File.open(@yamlfile.path, 'w'){|f| f.write("data : yaml!")}
|
56
|
+
@snpbin = SNPBin.new
|
57
|
+
@snpbin.argv_option.update({'yaml' => @yamlfile.path})
|
58
|
+
end
|
59
|
+
after do
|
60
|
+
@yamlfile.close
|
61
|
+
end
|
62
|
+
|
63
|
+
it "do nothing when @argv_option has no 'yaml' key" do
|
64
|
+
@snpbin.argv_option.delete('yaml')
|
65
|
+
lambda{@snpbin.merge_yaml_from_argvopt}.should_not change(@snpbin, :config)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "picks and deletes {'yaml' => yamlpath} from @argv_option and update @config by yamlpath-yaml" do
|
69
|
+
# FIXME: rewrite with change matcher
|
70
|
+
@snpbin.config.should be_empty
|
71
|
+
@snpbin.merge_yaml_from_argvopt
|
72
|
+
@snpbin.config.should eql({'data' => 'yaml!'})
|
73
|
+
@snpbin.argv_option.should_not have_key('yaml')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "#merge_all_argvopt_to_config" do
|
78
|
+
before do
|
79
|
+
@snpbin = SNPBin.new
|
80
|
+
@data = {'key' => 'value'}
|
81
|
+
end
|
82
|
+
it "copys @argv_option to @config" do
|
83
|
+
@snpbin.instance_variable_set(:@argv_option, @data)
|
84
|
+
@snpbin.merge_all_argvopt_to_config
|
85
|
+
@snpbin.config.should eql(@data)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# tests for SNPBin#exec_snplib and #run are in ../snp/real_connection_spec.rb
|
90
|
+
|
91
|
+
end
|
data/spec/snp/action_spec.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- coding:utf-8 -*-
|
2
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
2
|
|
4
3
|
describe "SNP" do
|
@@ -8,120 +7,114 @@ describe "SNP" do
|
|
8
7
|
@port = 9887
|
9
8
|
@app = Snarl::SNP::DEFAULT_TITLE
|
10
9
|
@class = '1'
|
11
|
-
|
10
|
+
end
|
11
|
+
|
12
|
+
def snp_open(&block)
|
13
|
+
snp = Snarl::SNP.new(@host, @port)
|
14
|
+
snp.stub!(:send).and_return('SNP/1.1/0/OK/1234/')
|
15
|
+
block.call(snp)
|
12
16
|
end
|
13
17
|
|
14
18
|
describe "#register" do
|
15
|
-
it "
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
snp.unregister(@app)
|
20
|
-
end
|
21
|
-
}.should_not raise_error
|
22
|
-
end
|
23
|
-
it "twice raises error on verbose" do
|
24
|
-
Snarl::SNP.open(@host, @port) do |snp|
|
25
|
-
snp.verbose = true
|
26
|
-
snp.register(@app)
|
27
|
-
lambda{snp.register(@app)}.should raise_error(Snarl::SNP::Error::SNP_ERROR_ALREADY_REGISTERED)
|
28
|
-
snp.unregister(@app)
|
29
|
-
end
|
30
|
-
Snarl::SNP.open(@host, @port) do |snp|
|
31
|
-
snp.register(@app)
|
32
|
-
lambda{snp.register(@app)}.should_not raise_error(Snarl::SNP::Error::SNP_ERROR_ALREADY_REGISTERED)
|
33
|
-
snp.unregister(@app)
|
19
|
+
it "makes valid SNP command string" do
|
20
|
+
expected = "type=SNP#?version=1.0#?action=register#?app=#{@app}\r\n"
|
21
|
+
snp_open do |snp|
|
22
|
+
snp.register(@app).request_str.should eql(expected)
|
34
23
|
end
|
35
24
|
end
|
36
25
|
end
|
37
26
|
|
38
27
|
describe "#unregister" do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
snp.
|
43
|
-
lambda{snp.unregister(@app)}.should raise_error(Snarl::SNP::Error::SNP_ERROR_NOT_REGISTERED)
|
28
|
+
it "makes valid SNP command string" do
|
29
|
+
expected = "type=SNP#?version=1.0#?action=unregister#?app=#{@app}\r\n"
|
30
|
+
snp_open do |snp|
|
31
|
+
snp.unregister(@app).request_str.should eql(expected)
|
44
32
|
end
|
45
|
-
|
46
|
-
|
33
|
+
end
|
34
|
+
it "raises error when snp has no @app yet" do
|
35
|
+
snp_open do |snp|
|
36
|
+
lambda{snp.unregister}.should raise_error(RuntimeError)
|
47
37
|
end
|
48
38
|
end
|
49
39
|
end
|
50
40
|
|
51
41
|
describe "#add_class" do
|
52
|
-
|
53
|
-
|
54
|
-
|
42
|
+
describe "makes valid SNP command string" do
|
43
|
+
it "snp.add_class(clsname) has class=clsname" do
|
44
|
+
expected = "type=SNP#?version=1.0#?action=add_class#?app=#{@app}#?class=#{@class}\r\n"
|
45
|
+
snp_open do |snp|
|
55
46
|
snp.register(@app)
|
56
|
-
snp.add_class(@class)
|
57
|
-
|
47
|
+
snp.add_class(@class).request_str.should eql(expected)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
it "snp.add_class(clsname, clstitle) has class=clsname#?title=clstitle" do
|
51
|
+
clstitle = 'classtitle'
|
52
|
+
expected = "type=SNP#?version=1.0#?action=add_class#?app=#{@app}#?class=#{@class}#?title=#{clstitle}\r\n"
|
53
|
+
snp_open do |snp|
|
54
|
+
snp.register(@app)
|
55
|
+
snp.add_class(@class, clstitle).request_str.should eql(expected)
|
58
56
|
end
|
59
|
-
}.should_not raise_error
|
60
|
-
end
|
61
|
-
it "add same class raises error on verbose" do
|
62
|
-
Snarl::SNP.open(@host, @port) do |snp|
|
63
|
-
snp.verbose = true
|
64
|
-
snp.register(@app)
|
65
|
-
snp.add_class(@class)
|
66
|
-
lambda{snp.add_class(@class)}.should raise_error(Snarl::SNP::Error::SNP_ERROR_CLASS_ALREADY_EXISTS)
|
67
|
-
snp.unregister(@app)
|
68
57
|
end
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
snp.
|
58
|
+
end
|
59
|
+
it "raises error when snp has no @app yet" do
|
60
|
+
clstitle = 'classtitle'
|
61
|
+
snp_open do |snp|
|
62
|
+
lambda{snp.add_class(@class, clstitle)}.should raise_error(RuntimeError)
|
74
63
|
end
|
75
64
|
end
|
76
65
|
end
|
77
66
|
|
78
67
|
describe "#notification" do
|
79
|
-
|
80
|
-
|
81
|
-
snp.register(@app)
|
82
|
-
snp.add_class(@class)
|
83
|
-
res = snp.notification('tit', 'tex(4 no icon popups)', 'ico', 9, 'cls')
|
68
|
+
describe "makes valid SNP command string" do
|
69
|
+
it "sends title, text, icon, timeout, class" do
|
84
70
|
expected = "type=SNP#?version=1.0#?action=notification#?app=Ruby-Snarl#?class=cls#?title=tit#?text=tex(4 no icon popups)#?timeout=9#?icon=ico\r\n"
|
85
|
-
|
71
|
+
snp_open do |snp|
|
72
|
+
snp.register(@app)
|
73
|
+
snp.add_class(@class)
|
74
|
+
res = snp.notification('tit', 'tex(4 no icon popups)', 'ico', 9, 'cls')
|
75
|
+
res.request_str.should eql(expected)
|
76
|
+
end
|
86
77
|
end
|
87
|
-
|
88
|
-
it "sends keyword-hash, keys=[:title, :text, :icon, :timeout, :class]" do
|
89
|
-
Snarl::SNP.open(@host) do |snp|
|
90
|
-
snp.register(@app)
|
91
|
-
snp.add_class(@class)
|
92
|
-
res = snp.notification(:title => 'tit', :text => 'tex', :icon => 'ico', :timeout => 9, :class => 'cls')
|
78
|
+
it "sends keyword-hash, keys=[:title, :text, :icon, :timeout, :class]" do
|
93
79
|
expected = "type=SNP#?version=1.0#?action=notification#?app=Ruby-Snarl#?class=cls#?title=tit#?text=tex#?timeout=9#?icon=ico\r\n"
|
94
|
-
|
80
|
+
snp_open do |snp|
|
81
|
+
snp.register(@app)
|
82
|
+
snp.add_class(@class)
|
83
|
+
res = snp.notification(:title => 'tit', :text => 'tex', :icon => 'ico', :timeout => 9, :class => 'cls')
|
84
|
+
res.request_str.should eql(expected)
|
85
|
+
end
|
95
86
|
end
|
96
|
-
|
97
|
-
it "sends 'anonymous' message if not registered yet" do
|
98
|
-
Snarl::SNP.open(@host) do |snp|
|
99
|
-
res = snp.notification('tit', 'tex', 'ico', 9)
|
87
|
+
it "sends 'anonymous' message if not registered yet" do
|
100
88
|
expected = "type=SNP#?version=1.0#?action=notification#?title=tit#?text=tex#?timeout=9#?icon=ico\r\n"
|
101
|
-
|
89
|
+
snp_open do |snp|
|
90
|
+
res = snp.notification('tit', 'tex', 'ico', 9)
|
91
|
+
res.request_str.should eql(expected)
|
92
|
+
end
|
102
93
|
end
|
103
|
-
|
104
|
-
it "sends 'anonymous' message if keyhash has {:app => nil} pair" do
|
105
|
-
Snarl::SNP.open(@host) do |snp|
|
106
|
-
res = snp.notification(:app => nil, :title => 'tit', :text => 'tex', :icon => 'ico', :timeout => 9)
|
94
|
+
it "sends 'anonymous' message if keyhash has {:app => nil} pair" do
|
107
95
|
expected = "type=SNP#?version=1.0#?action=notification#?title=tit#?text=tex#?timeout=9#?icon=ico\r\n"
|
108
|
-
|
96
|
+
snp_open do |snp|
|
97
|
+
res = snp.notification(:app => nil, :title => 'tit', :text => 'tex', :icon => 'ico', :timeout => 9)
|
98
|
+
res.request_str.should eql(expected)
|
99
|
+
end
|
109
100
|
end
|
110
101
|
end
|
111
102
|
end
|
112
103
|
|
113
104
|
describe "#hello" do
|
114
|
-
it "
|
115
|
-
|
116
|
-
|
105
|
+
it "makes valid SNP command string" do
|
106
|
+
expected = "type=SNP#?version=1.0#?action=hello\r\n"
|
107
|
+
snp_open do |snp|
|
108
|
+
snp.hello.request_str.should eql(expected)
|
117
109
|
end
|
118
110
|
end
|
119
111
|
end
|
120
112
|
|
121
113
|
describe "#version" do
|
122
|
-
it "
|
123
|
-
|
124
|
-
|
114
|
+
it "makes valid SNP command string" do
|
115
|
+
expected = "type=SNP#?version=1.0#?action=version\r\n"
|
116
|
+
snp_open do |snp|
|
117
|
+
snp.version.request_str.should eql(expected)
|
125
118
|
end
|
126
119
|
end
|
127
120
|
end
|
@@ -141,10 +134,10 @@ describe "SNP" do
|
|
141
134
|
expected = {:action => 'notification', :title => @default_title, :text => "text", :timeout => @default_timeout}
|
142
135
|
normalize_notification_params(params).should eql(expected)
|
143
136
|
end
|
144
|
-
it "['text'] returns {:title => snp.title, :text => 'text', :timeout => DEFAULT_TIMEOUT}, when snp
|
137
|
+
it "['text'] returns {:title => snp.title, :text => 'text', :timeout => DEFAULT_TIMEOUT}, when snp['title'] is set" do
|
145
138
|
params = ['text']
|
146
139
|
snp = Snarl::SNP.new
|
147
|
-
snp
|
140
|
+
snp['title'] = 'snp.title'
|
148
141
|
expected = {:action => 'notification', :title => 'snp.title', :text => "text", :timeout => @default_timeout}
|
149
142
|
snp.__send__(:normalize_notification_params, params).should eql(expected)
|
150
143
|
end
|
@@ -153,10 +146,10 @@ describe "SNP" do
|
|
153
146
|
expected = {:action => 'notification', :title => @default_title, :text => "text", :timeout => 9}
|
154
147
|
normalize_notification_params(params).should eql(expected)
|
155
148
|
end
|
156
|
-
it "['text', 9] returns {:title => snp.title, :text => 'text', :timeout => 9}, when snp
|
149
|
+
it "['text', 9] returns {:title => snp.title, :text => 'text', :timeout => 9}, when snp['title'] is set" do
|
157
150
|
params = ['text', 9]
|
158
151
|
snp = Snarl::SNP.new
|
159
|
-
snp
|
152
|
+
snp['title'] = 'snp.title'
|
160
153
|
expected = {:action => 'notification', :title => 'snp.title', :text => "text", :timeout => 9}
|
161
154
|
snp.__send__(:normalize_notification_params, params).should eql(expected)
|
162
155
|
end
|
@@ -180,19 +173,89 @@ describe "SNP" do
|
|
180
173
|
end
|
181
174
|
it "when already registered, app is @app" do
|
182
175
|
params = [{:text => 'text'}]
|
176
|
+
app = 'app'
|
183
177
|
snp = Snarl::SNP.new
|
184
|
-
snp
|
185
|
-
expected = {:action => 'notification', :app =>
|
178
|
+
snp['app'] = app
|
179
|
+
expected = {:action => 'notification', :app => app, :title => @default_title, :text => "text", :timeout => @default_timeout}
|
186
180
|
snp.__send__(:normalize_notification_params, params).should eql(expected)
|
187
181
|
end
|
188
|
-
it "if @app is
|
182
|
+
it "if @app is nil, app is unset" do
|
189
183
|
params = [{:text => 'text'}]
|
190
184
|
snp = Snarl::SNP.new
|
191
|
-
snp
|
192
|
-
expected = {:action => 'notification', :
|
185
|
+
snp['app'] = nil
|
186
|
+
expected = {:action => 'notification', :title => @default_title, :text => "text", :timeout => @default_timeout}
|
193
187
|
snp.__send__(:normalize_notification_params, params).should eql(expected)
|
194
188
|
end
|
189
|
+
it "title == param['title'] || snp['title'] || 'Ruby-Snarl'" do
|
190
|
+
param_title = 'param_title'
|
191
|
+
snp_title = 'snp_title'
|
192
|
+
|
193
|
+
params = [{:title => param_title}]
|
194
|
+
Snarl::SNP.new do |snp|
|
195
|
+
snp['title'] = snp_title
|
196
|
+
snp.__send__(:normalize_notification_params, params)[:title].should eql(param_title)
|
197
|
+
end
|
198
|
+
|
199
|
+
params = [{}]
|
200
|
+
Snarl::SNP.new do |snp|
|
201
|
+
snp['title'] = snp_title
|
202
|
+
snp.__send__(:normalize_notification_params, params)[:title].should eql(snp_title)
|
203
|
+
end
|
204
|
+
|
205
|
+
params = [{}]
|
206
|
+
Snarl::SNP.new do |snp|
|
207
|
+
snp.__send__(:normalize_notification_params, params)[:title].should eql(Snarl::SNP::DEFAULT_TITLE)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
it "timeout == param['timeout'] || snp['timeout'] || 10" do
|
211
|
+
param_timeout = 11
|
212
|
+
snp_timeout = 12
|
213
|
+
|
214
|
+
params = [{:timeout => param_timeout}]
|
215
|
+
Snarl::SNP.new do |snp|
|
216
|
+
snp['timeout'] = snp_timeout
|
217
|
+
snp.__send__(:normalize_notification_params, params)[:timeout].should eql(param_timeout)
|
218
|
+
end
|
219
|
+
|
220
|
+
params = [{}]
|
221
|
+
Snarl::SNP.new do |snp|
|
222
|
+
snp['timeout'] = snp_timeout
|
223
|
+
snp.__send__(:normalize_notification_params, params)[:timeout].should eql(snp_timeout)
|
224
|
+
end
|
225
|
+
|
226
|
+
params = [{}]
|
227
|
+
Snarl::SNP.new do |snp|
|
228
|
+
snp.__send__(:normalize_notification_params, params)[:timeout].should eql(Snarl::SNP::DEFAULT_TIMEOUT)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
it "icon == iconset(param['icon']) || param['icon'] || snp['icon'] || #unset" do
|
232
|
+
set_icon = ':set_icon'
|
233
|
+
param_icon = 'param_icon'
|
234
|
+
snp_icon = 'snp_icon'
|
235
|
+
|
236
|
+
params = [{:icon => :set_icon}]
|
237
|
+
Snarl::SNP.new do |snp|
|
238
|
+
snp['iconset'] = {:set_icon => set_icon}
|
239
|
+
snp['icon'] = snp_icon
|
240
|
+
snp.__send__(:normalize_notification_params, params)[:icon].should eql(set_icon)
|
241
|
+
end
|
242
|
+
|
243
|
+
params = [{:icon => param_icon}]
|
244
|
+
Snarl::SNP.new do |snp|
|
245
|
+
snp['icon'] = snp_icon
|
246
|
+
snp.__send__(:normalize_notification_params, params)[:icon].should eql(param_icon)
|
247
|
+
end
|
248
|
+
|
249
|
+
params = [{}]
|
250
|
+
Snarl::SNP.new do |snp|
|
251
|
+
snp['icon'] = snp_icon
|
252
|
+
snp.__send__(:normalize_notification_params, params)[:icon].should eql(snp_icon)
|
253
|
+
end
|
195
254
|
|
255
|
+
params = [{}]
|
256
|
+
Snarl::SNP.new do |snp|
|
257
|
+
snp.__send__(:normalize_notification_params, params).should_not have_key(:icon)
|
258
|
+
end
|
259
|
+
end
|
196
260
|
end
|
197
261
|
end
|
198
|
-
|