shoutbox-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Benjamin Krause
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ shoutbox-client
2
+ ===
3
+
4
+ A simple Ruby client to manage your shoutbox (see https://github.com/benjaminkrause/shoutbox).
5
+
6
+ Examples
7
+ ---
8
+
9
+ You can use it via ruby
10
+
11
+ ruby-1.9.2-p0 > ShoutboxClient.shout :name => "nightly-rake-task", :status => :red
12
+ true
13
+
14
+ or as a shell script
15
+
16
+ benjamin@Jiji % shout -n important-task -s red
17
+
18
+ Configuration
19
+ ---
20
+
21
+ The shoutbox-client will look for a ~/.shoutbox config file with a hostname and portnumber
22
+ in YAML format, like this
23
+
24
+ host: localhost
25
+ port: 3001
26
+
27
+ Otherwise you can set the configuration manually via ruby
28
+
29
+ ShoutboxClient.configuration.config_file = 'some/file'
30
+ # or
31
+ ShoutboxClient.configuration.host = 'shoutbox.moviepilot.com'
32
+ ShoutboxClient.configuration.port = 80
33
+
34
+ The shell script accepts host and port parameters
35
+
36
+ benjamin@Jiji % shout -n important-task -s red -h shoutbox.moviepilot.com -p 80
37
+
38
+
39
+ Contributing to shoutbox-client
40
+ ---
41
+
42
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
43
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
44
+ * Fork the project
45
+ * Start a feature/bugfix branch
46
+ * Commit and push until you are happy with your contribution
47
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
48
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
49
+
50
+ Copyright
51
+ ---
52
+
53
+ Copyright (c) 2011 Benjamin Krause. See LICENSE.txt for
54
+ further details (will be added later).
55
+
data/bin/shout ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require 'rubygems'
5
+ require 'shoutbox_client'
6
+
7
+ Shoutbox::Shout.new
@@ -0,0 +1,36 @@
1
+ module Shoutbox
2
+ class Configuration
3
+ attr_accessor :host, :port
4
+
5
+ def initialize
6
+ config_file_exists? ? read_config_file : default_config
7
+ end
8
+
9
+ def config_file=( filename )
10
+ @config_file = filename
11
+ config_file_exists? ? read_config_file : default_config
12
+ end
13
+
14
+ private
15
+
16
+ def config_file_exists?
17
+ File.exists?(config_file)
18
+ end
19
+
20
+ def config_file
21
+ @config_file || File.join(ENV['HOME'], '.shoutbox')
22
+ end
23
+
24
+ def default_config
25
+ @host = 'localhost'
26
+ @port = 3000
27
+ end
28
+
29
+ def read_config_file
30
+ config_data = YAML::load_file(config_file)
31
+ @host = config_data["host"]
32
+ @port = config_data["port"]
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ require 'trollop'
2
+
3
+ module Shoutbox
4
+ class Shout
5
+
6
+ def initialize
7
+ parse_options
8
+ do_it
9
+ end
10
+
11
+ def parse_options
12
+ @conf = Trollop::options do
13
+ # banner = MPPerf.options_banner
14
+ opt :host, "The hostname of the Shoutbox", :type => String
15
+ opt :port, "The port of the Shoutbox", :type => Integer
16
+ opt :name, "", :type => String
17
+ opt :status, "", :type => String
18
+ end
19
+
20
+ Trollop::die :name, "name must be given" unless @conf[:name]
21
+ Trollop::die :status, "status must be given" unless @conf[:status]
22
+ ShoutboxClient.configuration.host = @conf[:host] if @conf[:host]
23
+ ShoutboxClient.configuration.port = @conf[:port] if @conf[:port]
24
+ end
25
+
26
+ def do_it
27
+ ShoutboxClient.shout :name => @conf[:name], :status => @conf[:status]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,24 @@
1
+ require 'shoutbox/shout'
2
+ require 'shoutbox/configuration'
3
+ require 'net/http'
4
+ require 'JSON'
5
+ require 'yaml'
6
+
7
+ class ShoutboxClient
8
+
9
+ def self.configuration
10
+ @configuration ||= Shoutbox::Configuration.new
11
+ end
12
+
13
+ def self.shout( options )
14
+ response = Net::HTTP.start(configuration.host, configuration.port) do |http|
15
+ req = Net::HTTP::Put.new('/status')
16
+ req['User-Agent'] = 'Ruby shoutbox-client'
17
+ req['Content-Type'] = 'application/json'
18
+ req['Accept'] = 'application/json'
19
+ req.body = { "group" => options[:group], "name" => options[:name], :status => options[:status].to_s }.to_json
20
+ http.request(req)
21
+ end
22
+ response.body == "OK"
23
+ end
24
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'tempfile'
3
+ require 'JSON'
4
+
5
+ describe "ShoutboxClient" do
6
+ context 'configuration' do
7
+ it 'should use the default configuration' do
8
+ ShoutboxClient.configuration.config_file = '/i/dont/exist'
9
+ ShoutboxClient.configuration.host.should == 'localhost'
10
+ ShoutboxClient.configuration.port.should == 3000
11
+ end
12
+
13
+ it 'should use the values of the config file' do
14
+ tempfile = Tempfile.new( '.shoutbox' )
15
+ tempfile << { "host" => "example.com", "port" => 89 }.to_yaml
16
+ tempfile.close
17
+ ShoutboxClient.configuration.config_file = tempfile.path
18
+ ShoutboxClient.configuration.host.should == 'example.com'
19
+ ShoutboxClient.configuration.port.should == 89
20
+ ShoutboxClient.configuration.config_file = nil
21
+ end
22
+ end
23
+
24
+ context 'http communication' do
25
+ it 'should create a valid PUT request to the shoutbox' do
26
+ stub_request(:put, "http://localhost:3000/status").
27
+ with(:body => "{\"group\":\"default\",\"name\":\"test_status\",\"status\":\"green\"}",
28
+ :headers => {'Accept'=>'application/json', 'User-Agent'=>'Ruby shoutbox-client'}).
29
+ to_return(:status => 200, :body => "OK", :headers => {})
30
+
31
+ ShoutboxClient.shout( :group => "default", :name => "test_status", :status => :green ).should == true
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'webmock/rspec'
5
+ require 'shoutbox_client'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shoutbox-client
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Benjamin Krause
13
+ autorequire: shoutbox_client
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-05 00:00:00 +01:00
18
+ default_executable: shout
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: trollop
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 16
31
+ version: "1.16"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: rspec
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 2
44
+ - 3
45
+ version: "2.3"
46
+ type: :development
47
+ version_requirements: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 1
58
+ - 0
59
+ version: "1.0"
60
+ type: :development
61
+ version_requirements: *id003
62
+ - !ruby/object:Gem::Dependency
63
+ name: webmock
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 1
72
+ - 6
73
+ version: "1.6"
74
+ type: :development
75
+ version_requirements: *id004
76
+ - !ruby/object:Gem::Dependency
77
+ name: jeweler
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ~>
83
+ - !ruby/object:Gem::Version
84
+ segments:
85
+ - 1
86
+ - 5
87
+ version: "1.5"
88
+ type: :development
89
+ version_requirements: *id005
90
+ description: " Simple Ruby Client to manage status on a node.js Shoutbox Server "
91
+ email: bk@benjaminkrause.com
92
+ executables:
93
+ - shout
94
+ extensions: []
95
+
96
+ extra_rdoc_files:
97
+ - LICENSE.txt
98
+ - README.md
99
+ files:
100
+ - bin/shout
101
+ - lib/shoutbox/configuration.rb
102
+ - lib/shoutbox/shout.rb
103
+ - lib/shoutbox_client.rb
104
+ - LICENSE.txt
105
+ - README.md
106
+ - spec/shoutbox_client_spec.rb
107
+ - spec/spec_helper.rb
108
+ has_rdoc: true
109
+ homepage: http://github.com/benjaminkrause/shoutbox-client
110
+ licenses:
111
+ - MIT
112
+ post_install_message:
113
+ rdoc_options: []
114
+
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ segments:
131
+ - 0
132
+ version: "0"
133
+ requirements: []
134
+
135
+ rubyforge_project:
136
+ rubygems_version: 1.3.7
137
+ signing_key:
138
+ specification_version: 3
139
+ summary: ruby client to publish shoutbox status updates
140
+ test_files:
141
+ - spec/shoutbox_client_spec.rb
142
+ - spec/spec_helper.rb