shoutbox-client 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module Shoutbox
2
2
  class Configuration
3
- attr_accessor :host, :port, :proxy_host, :proxy_port, :default_group, :auth_token
3
+ attr_accessor :host, :proxy_host, :proxy_port, :default_group, :auth_token
4
4
 
5
5
  def initialize
6
6
  config_file_exists? ? read_config_file : default_config
@@ -22,9 +22,8 @@ module Shoutbox
22
22
  end
23
23
 
24
24
  def default_config
25
- @host = 'localhost'
26
- @port = 3000
27
- @default_group = 'default group'
25
+ @host = 'http://shoutbox.io/'
26
+ @default_group = 'Home'
28
27
  @auth_token = 'invalid-auth-token'
29
28
  @proxy_host = nil
30
29
  @proxy_port = nil
@@ -33,8 +32,7 @@ module Shoutbox
33
32
  def read_config_file
34
33
  config_data = YAML::load_file(config_file)
35
34
  @host = config_data["host"]
36
- @port = config_data["port"]
37
- @default_group = config_data["default_group"] || 'default group'
35
+ @default_group = config_data["default_group"] || 'Home'
38
36
  @auth_token = config_data["auth_token"]
39
37
  @proxy_host = config_data["proxy_host"]
40
38
  @proxy_port = config_data["proxy_port"]
@@ -12,13 +12,18 @@ module Shoutbox
12
12
  def parse_options
13
13
  @conf = Trollop::options do
14
14
  banner <<-EOS
15
- usage: shout <subcommand> <name>
15
+ usage: shout <subcommand> <name> [message]
16
16
 
17
- <subcommand> must be one of red, green, remove
17
+ <subcommand> must be one of green, yellow, red, remove
18
18
  <name> is any given string you can think of
19
+ [message] is optional for green and required for red and yellow
19
20
 
20
- If you want to delete a status, you must provide
21
- a message.
21
+ examples
22
+
23
+ shout green db-export
24
+ shout yellow db-export "export took too long"
25
+ shout red db-export "failed saving file"
26
+ shout remove db-export
22
27
 
23
28
  shout allows the folling options:
24
29
  EOS
@@ -40,7 +45,7 @@ EOS
40
45
  when "green"
41
46
  # noop
42
47
  when "yellow"
43
- Trollop::die "provide <name> and <message> when shouting red" if @conf[:message].to_s.empty?
48
+ Trollop::die "provide <name> and <message> when shouting yellow" if @conf[:message].to_s.empty?
44
49
  when "remove"
45
50
  # noop
46
51
  else
@@ -57,4 +62,4 @@ EOS
57
62
  ShoutboxClient.shout :name => @conf[:name], :status => @conf[:status], :group => @conf[:group], :message => @conf[:message], :expires_in => @conf[:expires_in]
58
63
  end
59
64
  end
60
- end
65
+ end
@@ -28,7 +28,7 @@ class ShoutboxClient
28
28
  end
29
29
 
30
30
  def self.update_status( options )
31
- response = Net::HTTP.Proxy(configuration.proxy_host, configuration.proxy_port).start(configuration.host, configuration.port) do |http|
31
+ response = Net::HTTP.Proxy(configuration.proxy_host, configuration.proxy_port).start(self.host, self.port) do |http|
32
32
  req = Net::HTTP::Put.new( request_url(options) )
33
33
  default_headers(req)
34
34
  body_data = { :name => options[:name], :group => (options[:group] || configuration.default_group), :status => options[:status].to_s }
@@ -42,7 +42,7 @@ class ShoutboxClient
42
42
  end
43
43
 
44
44
  def self.delete_status( options )
45
- response = Net::HTTP.Proxy(configuration.proxy_host, configuration.proxy_port).start(configuration.host, configuration.port) do |http|
45
+ response = Net::HTTP.Proxy(configuration.proxy_host, configuration.proxy_port).start(self.host, self.port) do |http|
46
46
  req = Net::HTTP::Delete.new( request_url(options) )
47
47
  req.body = { :name => options[:name], :group => (options[:group] || configuration.default_group) }.to_json
48
48
  default_headers(req)
@@ -62,6 +62,14 @@ class ShoutboxClient
62
62
  '/status'
63
63
  end
64
64
 
65
+ def self.host
66
+ URI.parse(configuration.host).host
67
+ end
68
+
69
+ def self.port
70
+ URI.parse(configuration.host).port
71
+ end
72
+
65
73
  def self.valid_status?( status )
66
74
  VALID_STATUS.keys.include?( status.to_s )
67
75
  end
@@ -10,27 +10,25 @@ describe "ShoutboxClient" do
10
10
  context 'configuration' do
11
11
  it 'should use the default configuration' do
12
12
  ShoutboxClient.configuration.config_file = '/i/dont/exist'
13
- ShoutboxClient.configuration.host.should == 'localhost'
14
- ShoutboxClient.configuration.port.should == 3000
13
+ ShoutboxClient.configuration.host.should == 'http://shoutbox.io/'
15
14
  ShoutboxClient.configuration.auth_token.should == 'invalid-auth-token'
16
15
  end
17
16
 
18
17
  it 'should use the values of the config file' do
19
18
  tempfile = Tempfile.new( '.shoutbox' )
20
- tempfile << { "host" => "example.com", "port" => 89, "proxy_host" => "prx", "proxy_port" => 8080, "auth_token" => 'abc' }.to_yaml
19
+ tempfile << { "host" => "http://example.com", "proxy_host" => "prx", "proxy_port" => 8080, "auth_token" => 'abc' }.to_yaml
21
20
  tempfile.close
22
21
  ShoutboxClient.configuration.config_file = tempfile.path
23
- ShoutboxClient.configuration.host.should == 'example.com'
24
- ShoutboxClient.configuration.port.should == 89
22
+ ShoutboxClient.configuration.host.should == 'http://example.com'
25
23
  ShoutboxClient.configuration.proxy_host.should == "prx"
26
24
  ShoutboxClient.configuration.proxy_port.should == 8080
27
- ShoutboxClient.configuration.default_group.should == 'default group'
25
+ ShoutboxClient.configuration.default_group.should == 'Home'
28
26
  ShoutboxClient.configuration.auth_token.should == 'abc'
29
27
  end
30
28
 
31
- it 'should use the configured default group' do
29
+ it 'should use the configured Home' do
32
30
  tempfile = Tempfile.new( '.shoutbox' )
33
- tempfile << { "host" => "example.com", "port" => 89, "proxy_host" => "prx", "proxy_port" => 8080, "default_group" => "some group" }.to_yaml
31
+ tempfile << { "host" => "http://example.com","proxy_host" => "prx", "proxy_port" => 8080, "default_group" => "some group" }.to_yaml
34
32
  tempfile.close
35
33
  ShoutboxClient.configuration.config_file = tempfile.path
36
34
  ShoutboxClient.configuration.default_group.should == 'some group'
@@ -46,7 +44,7 @@ describe "ShoutboxClient" do
46
44
 
47
45
 
48
46
  it 'should create a valid PUT request to the shoutbox' do
49
- stub_request(:put, "http://localhost:3000/status").
47
+ stub_request(:put, "http://shoutbox.io/status").
50
48
  with(:body => "{\"name\":\"test_status\",\"group\":\"my_group\",\"status\":\"green\"}",
51
49
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client', 'X-Shoutbox-Auth-Token' => 'invalid-auth-token'}).
52
50
  to_return(:status => 200, :body => "OK", :headers => {})
@@ -55,8 +53,8 @@ describe "ShoutboxClient" do
55
53
  end
56
54
 
57
55
  it 'should create use group default if no group given' do
58
- stub_request(:put, "http://localhost:3000/status").
59
- with(:body => "{\"name\":\"test_status\",\"group\":\"default group\",\"status\":\"green\"}",
56
+ stub_request(:put, "http://shoutbox.io/status").
57
+ with(:body => "{\"name\":\"test_status\",\"group\":\"Home\",\"status\":\"green\"}",
60
58
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client', 'X-Shoutbox-Auth-Token' => 'invalid-auth-token'}).
61
59
  to_return(:status => 200, :body => "OK", :headers => {})
62
60
 
@@ -64,8 +62,8 @@ describe "ShoutboxClient" do
64
62
  end
65
63
 
66
64
  it 'should include a message when status is yellow and message is given' do
67
- stub_request(:put, "http://localhost:3000/status").
68
- with(:body => "{\"name\":\"test_status\",\"group\":\"default group\",\"status\":\"yellow\",\"message\":\"This is what you should do now..\"}",
65
+ stub_request(:put, "http://shoutbox.io/status").
66
+ with(:body => "{\"name\":\"test_status\",\"group\":\"Home\",\"status\":\"yellow\",\"message\":\"This is what you should do now..\"}",
69
67
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client', 'X-Shoutbox-Auth-Token' => 'invalid-auth-token'}).
70
68
  to_return(:status => 200, :body => "OK", :headers => {})
71
69
 
@@ -73,8 +71,8 @@ describe "ShoutboxClient" do
73
71
  end
74
72
 
75
73
  it 'should include a message when status is red' do
76
- stub_request(:put, "http://localhost:3000/status").
77
- with(:body => "{\"name\":\"test_status\",\"group\":\"default group\",\"status\":\"red\",\"message\":\"This is what you should do now..\"}",
74
+ stub_request(:put, "http://shoutbox.io/status").
75
+ with(:body => "{\"name\":\"test_status\",\"group\":\"Home\",\"status\":\"red\",\"message\":\"This is what you should do now..\"}",
78
76
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client', 'X-Shoutbox-Auth-Token' => 'invalid-auth-token'}).
79
77
  to_return(:status => 200, :body => "OK", :headers => {})
80
78
 
@@ -82,8 +80,8 @@ describe "ShoutboxClient" do
82
80
  end
83
81
 
84
82
  it 'should include an expiration time when given' do
85
- stub_request(:put, "http://localhost:3000/status").
86
- with(:body => "{\"name\":\"test_status\",\"group\":\"default group\",\"status\":\"green\",\"expires_in\":3600}",
83
+ stub_request(:put, "http://shoutbox.io/status").
84
+ with(:body => "{\"name\":\"test_status\",\"group\":\"Home\",\"status\":\"green\",\"expires_in\":3600}",
87
85
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client', 'X-Shoutbox-Auth-Token' => 'invalid-auth-token'}).
88
86
  to_return(:status => 200, :body => "OK", :headers => {})
89
87
 
@@ -103,8 +101,8 @@ describe "ShoutboxClient" do
103
101
  end
104
102
 
105
103
  it 'should send optional status on green update' do
106
- stub_request(:put, "http://localhost:3000/status").
107
- with(:body => "{\"name\":\"test_status\",\"group\":\"default group\",\"status\":\"green\",\"message\":\"everything's ok!\"}",
104
+ stub_request(:put, "http://shoutbox.io/status").
105
+ with(:body => "{\"name\":\"test_status\",\"group\":\"Home\",\"status\":\"green\",\"message\":\"everything's ok!\"}",
108
106
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client', 'X-Shoutbox-Auth-Token' => 'invalid-auth-token'}).
109
107
  to_return(:status => 200, :body => "OK", :headers => {})
110
108
  lambda {
@@ -113,8 +111,8 @@ describe "ShoutboxClient" do
113
111
  end
114
112
 
115
113
  it 'should delete a status' do
116
- stub_request(:delete, "http://localhost:3000/status").
117
- with(:body => "{\"name\":\"test_status\",\"group\":\"default group\"}",
114
+ stub_request(:delete, "http://shoutbox.io/status").
115
+ with(:body => "{\"name\":\"test_status\",\"group\":\"Home\"}",
118
116
  :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client', 'X-Shoutbox-Auth-Token' => 'invalid-auth-token'}).
119
117
  to_return(:status => 200, :body => "OK", :headers => {})
120
118
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: shoutbox-client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Benjamin Krause
@@ -10,7 +10,7 @@ autorequire: shoutbox_client
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-04 00:00:00 +02:00
13
+ date: 2011-04-14 00:00:00 +02:00
14
14
  default_executable: shout
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -73,9 +73,9 @@ dependencies:
73
73
  requirement: &id006 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
- - - ~>
76
+ - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: 1.4.0
78
+ version: "0"
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: *id006
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
112
  - - ">="
113
113
  - !ruby/object:Gem::Version
114
- hash: 592437698402898647
114
+ hash: 4047158430543841235
115
115
  segments:
116
116
  - 0
117
117
  version: "0"