shoutbox-client 0.0.11 → 0.0.12

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,6 +1,6 @@
1
1
  module Shoutbox
2
2
  class Configuration
3
- attr_accessor :host, :port
3
+ attr_accessor :host, :port, :proxy_host, :proxy_port, :default_group
4
4
 
5
5
  def initialize
6
6
  config_file_exists? ? read_config_file : default_config
@@ -22,15 +22,20 @@ module Shoutbox
22
22
  end
23
23
 
24
24
  def default_config
25
- @host = 'localhost'
26
- @port = 3000
25
+ @host = 'localhost'
26
+ @port = 3000
27
+ @default_group = 'default group'
28
+ @proxy_host = nil
29
+ @proxy_port = nil
27
30
  end
28
31
 
29
32
  def read_config_file
30
- config_data = YAML::load_file(config_file)
31
- @host = config_data["host"]
32
- @port = config_data["port"]
33
+ config_data = YAML::load_file(config_file)
34
+ @host = config_data["host"]
35
+ @port = config_data["port"]
36
+ @default_group = config_data["default_group"] || 'default group'
37
+ @proxy_host = config_data["proxy_host"]
38
+ @proxy_port = config_data["proxy_port"]
33
39
  end
34
-
35
40
  end
36
41
  end
@@ -22,9 +22,11 @@ a message.
22
22
 
23
23
  shout allows the folling options:
24
24
  EOS
25
- opt :host, "The hostname of the Shoutbox", :type => String
26
- opt :port, "The port of the Shoutbox", :type => Integer
27
- opt :group, "The group to use", :type => String, :default => "Shoutbox Default Group"
25
+ opt :host, "The hostname of the Shoutbox", :type => String
26
+ opt :port, "The port of the Shoutbox", :type => Integer
27
+ opt :proxy_host, "The proxy host to use", :type => String
28
+ opt :proxy_port, "The proxy port to use", :type => Integer
29
+ opt :group, "The group to use", :type => String, :default => "Shoutbox Default Group"
28
30
  end
29
31
 
30
32
  @conf[:status] = ARGV.shift
@@ -24,10 +24,10 @@ class ShoutboxClient
24
24
  end
25
25
 
26
26
  def self.update_status( options )
27
- response = Net::HTTP.start(configuration.host, configuration.port) do |http|
27
+ response = Net::HTTP.Proxy(configuration.proxy_host, configuration.proxy_port).start(configuration.host, configuration.port) do |http|
28
28
  req = Net::HTTP::Put.new( request_url(options) )
29
29
  default_headers(req)
30
- body_data = { :statusId => options[:statusId], :group => (options[:group] || 'default'), :status => options[:status].to_s }
30
+ body_data = { :statusId => options[:statusId], :group => (options[:group] || configuration.default_group), :status => options[:status].to_s }
31
31
  body_data[:message] = options[:message] if options[:status].to_s == 'red' or (options[:status].to_s == 'yellow' and options[:message])
32
32
  raise ArgumentError if (options[:status] == :red) and body_data[:message].to_s.empty?
33
33
  req.body = body_data.to_json
@@ -37,9 +37,9 @@ class ShoutboxClient
37
37
  end
38
38
 
39
39
  def self.delete_status( options )
40
- response = Net::HTTP.start(configuration.host, configuration.port) do |http|
40
+ response = Net::HTTP.Proxy(configuration.proxy_host, configuration.proxy_port).start(configuration.host, configuration.port) do |http|
41
41
  req = Net::HTTP::Delete.new( request_url(options) )
42
- req.body = { :statusId => options[:statusId], :group => (options[:group] || 'default') }.to_json
42
+ req.body = { :statusId => options[:statusId], :group => (options[:group] || configuration.default_group) }.to_json
43
43
  default_headers(req)
44
44
  http.request(req)
45
45
  end
@@ -12,11 +12,23 @@ describe "ShoutboxClient" do
12
12
 
13
13
  it 'should use the values of the config file' do
14
14
  tempfile = Tempfile.new( '.shoutbox' )
15
- tempfile << { "host" => "example.com", "port" => 89 }.to_yaml
15
+ tempfile << { "host" => "example.com", "port" => 89, "proxy_host" => "prx", "proxy_port" => 8080 }.to_yaml
16
16
  tempfile.close
17
17
  ShoutboxClient.configuration.config_file = tempfile.path
18
18
  ShoutboxClient.configuration.host.should == 'example.com'
19
19
  ShoutboxClient.configuration.port.should == 89
20
+ ShoutboxClient.configuration.proxy_host.should == "prx"
21
+ ShoutboxClient.configuration.proxy_port.should == 8080
22
+ ShoutboxClient.configuration.default_group.should == 'default group'
23
+ ShoutboxClient.configuration.config_file = nil
24
+ end
25
+
26
+ it 'should use the configured default group' do
27
+ tempfile = Tempfile.new( '.shoutbox' )
28
+ tempfile << { "host" => "example.com", "port" => 89, "proxy_host" => "prx", "proxy_port" => 8080, "default_group" => "some group" }.to_yaml
29
+ tempfile.close
30
+ ShoutboxClient.configuration.config_file = tempfile.path
31
+ ShoutboxClient.configuration.default_group.should == 'some group'
20
32
  ShoutboxClient.configuration.config_file = nil
21
33
  end
22
34
  end
@@ -33,7 +45,7 @@ describe "ShoutboxClient" do
33
45
 
34
46
  it 'should create use group default if no group given' do
35
47
  stub_request(:put, "http://localhost:3000/status").
36
- with(:body => "{\"statusId\":\"test_status\",\"group\":\"default\",\"status\":\"green\"}",
48
+ with(:body => "{\"statusId\":\"test_status\",\"group\":\"default group\",\"status\":\"green\"}",
37
49
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client'}).
38
50
  to_return(:status => 200, :body => "OK", :headers => {})
39
51
 
@@ -42,7 +54,7 @@ describe "ShoutboxClient" do
42
54
 
43
55
  it 'should not include a message when status is yellow and no message given' do
44
56
  stub_request(:put, "http://localhost:3000/status").
45
- with(:body => "{\"statusId\":\"test_status\",\"group\":\"default\",\"status\":\"yellow\"}",
57
+ with(:body => "{\"statusId\":\"test_status\",\"group\":\"default group\",\"status\":\"yellow\"}",
46
58
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client'}).
47
59
  to_return(:status => 200, :body => "OK", :headers => {})
48
60
 
@@ -51,7 +63,7 @@ describe "ShoutboxClient" do
51
63
 
52
64
  it 'should include a message when status is yellow and message is given' do
53
65
  stub_request(:put, "http://localhost:3000/status").
54
- with(:body => "{\"statusId\":\"test_status\",\"group\":\"default\",\"status\":\"yellow\",\"message\":\"This is what you should do now..\"}",
66
+ with(:body => "{\"statusId\":\"test_status\",\"group\":\"default group\",\"status\":\"yellow\",\"message\":\"This is what you should do now..\"}",
55
67
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client'}).
56
68
  to_return(:status => 200, :body => "OK", :headers => {})
57
69
 
@@ -60,7 +72,7 @@ describe "ShoutboxClient" do
60
72
 
61
73
  it 'should include a message when status is red' do
62
74
  stub_request(:put, "http://localhost:3000/status").
63
- with(:body => "{\"statusId\":\"test_status\",\"group\":\"default\",\"status\":\"red\",\"message\":\"This is what you should do now..\"}",
75
+ with(:body => "{\"statusId\":\"test_status\",\"group\":\"default group\",\"status\":\"red\",\"message\":\"This is what you should do now..\"}",
64
76
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client'}).
65
77
  to_return(:status => 200, :body => "OK", :headers => {})
66
78
 
@@ -69,7 +81,7 @@ describe "ShoutboxClient" do
69
81
 
70
82
  it 'should not include a message when status is green' do
71
83
  stub_request(:put, "http://localhost:3000/status").
72
- with(:body => "{\"statusId\":\"test_status\",\"group\":\"default\",\"status\":\"green\"}",
84
+ with(:body => "{\"statusId\":\"test_status\",\"group\":\"default group\",\"status\":\"green\"}",
73
85
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client'}).
74
86
  to_return(:status => 200, :body => "OK", :headers => {})
75
87
 
@@ -84,7 +96,7 @@ describe "ShoutboxClient" do
84
96
 
85
97
  it 'should delete a status' do
86
98
  stub_request(:delete, "http://localhost:3000/status").
87
- with(:body => "{\"statusId\":\"test_status\",\"group\":\"default\"}",
99
+ with(:body => "{\"statusId\":\"test_status\",\"group\":\"default group\"}",
88
100
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client'}).
89
101
  to_return(:status => 200, :body => "OK", :headers => {})
90
102
 
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoutbox-client
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 0
8
- - 11
9
- version: 0.0.11
4
+ prerelease:
5
+ version: 0.0.12
10
6
  platform: ruby
11
7
  authors:
12
8
  - Benjamin Krause
@@ -14,7 +10,7 @@ autorequire: shoutbox_client
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-01-31 00:00:00 +01:00
13
+ date: 2011-03-10 00:00:00 +01:00
18
14
  default_executable: shout
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -24,9 +20,6 @@ dependencies:
24
20
  requirements:
25
21
  - - ~>
26
22
  - !ruby/object:Gem::Version
27
- segments:
28
- - 1
29
- - 16
30
23
  version: "1.16"
31
24
  type: :runtime
32
25
  prerelease: false
@@ -38,9 +31,6 @@ dependencies:
38
31
  requirements:
39
32
  - - ~>
40
33
  - !ruby/object:Gem::Version
41
- segments:
42
- - 2
43
- - 3
44
34
  version: "2.3"
45
35
  type: :development
46
36
  prerelease: false
@@ -52,9 +42,6 @@ dependencies:
52
42
  requirements:
53
43
  - - ~>
54
44
  - !ruby/object:Gem::Version
55
- segments:
56
- - 1
57
- - 0
58
45
  version: "1.0"
59
46
  type: :development
60
47
  prerelease: false
@@ -66,9 +53,6 @@ dependencies:
66
53
  requirements:
67
54
  - - ~>
68
55
  - !ruby/object:Gem::Version
69
- segments:
70
- - 1
71
- - 6
72
56
  version: "1.6"
73
57
  type: :development
74
58
  prerelease: false
@@ -80,9 +64,6 @@ dependencies:
80
64
  requirements:
81
65
  - - ~>
82
66
  - !ruby/object:Gem::Version
83
- segments:
84
- - 1
85
- - 5
86
67
  version: "1.5"
87
68
  type: :development
88
69
  prerelease: false
@@ -94,10 +75,6 @@ dependencies:
94
75
  requirements:
95
76
  - - ~>
96
77
  - !ruby/object:Gem::Version
97
- segments:
98
- - 1
99
- - 4
100
- - 0
101
78
  version: 1.4.0
102
79
  type: :runtime
103
80
  prerelease: false
@@ -134,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
111
  requirements:
135
112
  - - ">="
136
113
  - !ruby/object:Gem::Version
137
- hash: -4378634194582785805
114
+ hash: 591505643333229033
138
115
  segments:
139
116
  - 0
140
117
  version: "0"
@@ -143,13 +120,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
120
  requirements:
144
121
  - - ">="
145
122
  - !ruby/object:Gem::Version
146
- segments:
147
- - 0
148
123
  version: "0"
149
124
  requirements: []
150
125
 
151
126
  rubyforge_project:
152
- rubygems_version: 1.3.7
127
+ rubygems_version: 1.5.0
153
128
  signing_key:
154
129
  specification_version: 3
155
130
  summary: ruby client to publish shoutbox status updates