socky-client 0.4.2 → 0.4.3

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/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## 0.4.3 / 2010-10-30
5
+
6
+ - new features:
7
+ - new, simpler syntax
8
+ - bugfixes
9
+ - none
10
+
4
11
  ## 0.4.2 / 2010-10-29
5
12
 
6
13
  - new features:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.4.3
data/lib/socky-client.rb CHANGED
@@ -1,5 +1,6 @@
1
- require 'yaml'
2
1
  require 'json'
2
+ require 'logger'
3
+ require 'yaml'
3
4
 
4
5
  require File.dirname(__FILE__) + '/socky-client/websocket'
5
6
 
@@ -7,7 +8,7 @@ module Socky
7
8
 
8
9
  class << self
9
10
 
10
- attr_accessor :config_path
11
+ attr_accessor :config_path, :logger
11
12
  def config_path
12
13
  @config_path ||= 'socky_hosts.yml'
13
14
  end
@@ -28,6 +29,14 @@ module Socky
28
29
  def hosts
29
30
  config[:hosts]
30
31
  end
32
+
33
+ def logger
34
+ @logger ||= Logger.new(STDOUT)
35
+ end
36
+
37
+ def deprecation_warning(msg)
38
+ logger.warn "DEPRECATION WARNING: " + msg.to_s
39
+ end
31
40
 
32
41
  private
33
42
 
@@ -48,6 +57,16 @@ module Socky
48
57
  def send_message(data, opts = {})
49
58
  to = opts[:to] || {}
50
59
  except = opts[:except] || {}
60
+
61
+ # Move to new syntax
62
+ if opts[:to] || opts[:except]
63
+ deprecation_warning "Using of :to and :except will be removed in next version - please move to new syntax."
64
+ end
65
+ to[:client] ||= opts[:client]
66
+ to[:clients] ||= opts[:clients]
67
+ to[:channel] ||= opts[:channel]
68
+ to[:channels] ||= opts[:channels]
69
+ # end of new syntax
51
70
 
52
71
  unless to.is_a?(Hash) && except.is_a?(Hash)
53
72
  raise "recipiend data should be in hash format"
@@ -37,6 +37,35 @@ describe Socky do
37
37
  end
38
38
  end
39
39
  context "should handle recipient conditions for" do
40
+ # New syntax
41
+ it ":client" do
42
+ Socky.should_receive(:send_data).with({:command => :broadcast, :body => "test", :to => { :clients => "first" }})
43
+ Socky.send("test", :client => "first")
44
+ end
45
+ it ":clients" do
46
+ Socky.should_receive(:send_data).with({:command => :broadcast, :body => "test", :to => { :clients => ["first","second"] }})
47
+ Socky.send("test", :clients => ["first","second"])
48
+ end
49
+ it ":channel" do
50
+ Socky.should_receive(:send_data).with({:command => :broadcast, :body => "test", :to => { :channels => "first" }})
51
+ Socky.send("test", :channel => "first")
52
+ end
53
+ it ":channels" do
54
+ Socky.should_receive(:send_data).with({:command => :broadcast, :body => "test", :to => { :channels => ["first","second"] }})
55
+ Socky.send("test", :channels => ["first","second"])
56
+ end
57
+ it "combination" do
58
+ Socky.should_receive(:send_data).with({
59
+ :command => :broadcast,
60
+ :body => "test",
61
+ :to => {
62
+ :clients => "allowed_user",
63
+ :channels => "allowed_channel"
64
+ }
65
+ })
66
+ Socky.send("test", :clients => "allowed_user", :channels => "allowed_channel")
67
+ end
68
+ # Old syntax
40
69
  it ":to => :client" do
41
70
  Socky.should_receive(:send_data).with({:command => :broadcast, :body => "test", :to => { :clients => "first" }})
42
71
  Socky.send("test", :to => { :client => "first" })
@@ -93,6 +122,17 @@ describe Socky do
93
122
  end
94
123
  end
95
124
  context "should ignore nil value for" do
125
+ # New syntax
126
+ it ":clients" do
127
+ Socky.should_receive(:send_data).with({:command => :broadcast, :body => "test"})
128
+ Socky.send("test", :clients => nil)
129
+ end
130
+ it ":channels" do
131
+ Socky.should_receive(:send_data).with({:command => :broadcast, :body => "test"})
132
+ Socky.send("test", :channels => nil)
133
+ end
134
+
135
+ # Old syntax
96
136
  it ":to => :clients" do
97
137
  Socky.should_receive(:send_data).with({:command => :broadcast, :body => "test"})
98
138
  Socky.send("test", :to => { :clients => nil })
@@ -111,6 +151,17 @@ describe Socky do
111
151
  end
112
152
  end
113
153
  context "should handle empty array for" do
154
+ # New syntax
155
+ it ":clients by not sending message" do
156
+ Socky.should_not_receive(:send_data)
157
+ Socky.send("test", :clients => [])
158
+ end
159
+ it ":channels by not sending message" do
160
+ Socky.should_not_receive(:send_data)
161
+ Socky.send("test", :channels => [])
162
+ end
163
+
164
+ # Old syntax
114
165
  it ":to => :clients by not sending message" do
115
166
  Socky.should_not_receive(:send_data)
116
167
  Socky.send("test", :to => { :clients => [] })
data/spec/spec_helper.rb CHANGED
@@ -3,3 +3,5 @@ require 'rspec'
3
3
 
4
4
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
5
5
  require 'socky-client'
6
+
7
+ Socky.logger.level = Logger::ERROR
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socky-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 2
10
- version: 0.4.2
9
+ - 3
10
+ version: 0.4.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bernard Potocki
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-29 00:00:00 +02:00
18
+ date: 2010-10-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency