eagle 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ InstalledFiles
7
+ _yardoc
8
+ coverage
9
+ doc/
10
+ lib/bundler/man
11
+ pkg
12
+ rdoc
13
+ spec/reports
14
+ test/tmp
15
+ test/version_tmp
16
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "pusher"
4
+ gem "pusher-client"
5
+ gem 'json'
6
+
7
+ group :test do
8
+ gem "minitest", ">= 0"
9
+ gem "ruby-debug"
10
+ end
11
+ # Specify your gem's dependencies in eagle.gemspec
12
+ gemspec
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ eagle (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.3.2)
10
+ columnize (0.3.6)
11
+ eventmachine (0.12.10)
12
+ json (1.7.5)
13
+ libwebsocket (0.1.5)
14
+ addressable
15
+ linecache (0.46)
16
+ rbx-require-relative (> 0.0.4)
17
+ minitest (3.4.0)
18
+ multi_json (1.3.6)
19
+ pusher (0.9.4)
20
+ multi_json (~> 1.0)
21
+ signature (~> 0.1.2)
22
+ pusher-client (0.2.1)
23
+ eventmachine (~> 0.12.10)
24
+ libwebsocket (~> 0.1.0)
25
+ rbx-require-relative (0.0.9)
26
+ ruby-debug (0.10.4)
27
+ columnize (>= 0.1)
28
+ ruby-debug-base (~> 0.10.4.0)
29
+ ruby-debug-base (0.10.4)
30
+ linecache (>= 0.3)
31
+ signature (0.1.4)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ eagle!
38
+ json
39
+ minitest
40
+ pusher
41
+ pusher-client
42
+ ruby-debug
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Roman Heinrich
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Eagle
2
+
3
+ A realtime server management framework
4
+ ## Requirements:
5
+
6
+ - slanger (gem install slanger) - an OSS clone for http://pusher.com/
7
+ (ruby 1.9, Redis)
8
+
9
+ - or use http://pusher.com/
10
+
11
+
12
+
13
+ ## Installation
14
+
15
+ $ gem install eagle
16
+
17
+
18
+ ## Usage
19
+
20
+ >cat ~/.eagle.yml
21
+ ---
22
+ pusher_app_id: 'your-pusher-app-id'
23
+ pusher_key: '765ec374ae0a69f4ce44'
24
+ pusher_secret: 'your-pusher-secret'
25
+ pusher_address: 'localhost'
26
+ pusher_port: 4567
27
+ pusher_ws_port: 8080
28
+ hostname: testnode
29
+
30
+
31
+ > eagle-client (optional path to another config file)
32
+
33
+
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib'
8
+ t.test_files = FileList["test/lib/**/*_test.rb"]
9
+ end
10
+
11
+
12
+ task :default => :test
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'eagle'
4
+ config = Eagle::Config.new(ARGV[0])
5
+ client = Eagle::Client.new(config)
6
+ client.run
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'eagle'
4
+ config = Eagle::Config.new(ARGV[0])
5
+ server = Eagle::Server.new(config)
6
+ server.run
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/eagle/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Roman Heinrich"]
6
+ gem.email = ["roman.heinrich@gmail.com"]
7
+ gem.description = %q{Manage servers with ease with eagle}
8
+ gem.summary = %q{Enables realtime server management with optional web UI}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "eagle"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Eagle::VERSION
17
+ end
@@ -0,0 +1,8 @@
1
+ ---
2
+ pusher_app_id: 'your-pusher-app-id'
3
+ pusher_key: '765ec374ae0a69f4ce44'
4
+ pusher_secret: 'your-pusher-secret'
5
+ pusher_address: 'localhost'
6
+ pusher_port: 4567
7
+ pusher_ws_port: 8080
8
+ hostname: testnode
@@ -0,0 +1,14 @@
1
+ require 'yaml'
2
+ require 'pusher'
3
+ require 'pusher-client'
4
+
5
+ require 'ext/kernel'
6
+ require "eagle/version"
7
+ require "eagle/config"
8
+ require "eagle/pusher_configurator"
9
+ require "eagle/client"
10
+ require "eagle/server"
11
+
12
+ module Eagle
13
+ # Your code goes here...
14
+ end
@@ -0,0 +1,59 @@
1
+ module Eagle
2
+ class Client
3
+ attr_accessor :config
4
+ attr_accessor :pusher_socket
5
+
6
+ def initialize(config_param=nil)
7
+ @config = config_param ||Config.config
8
+ pusher_configurator = PusherConfigurator.new(@config)
9
+ pusher_configurator.init_pusher # static
10
+ @pusher_socket = pusher_configurator.init_pusher_client
11
+ end
12
+
13
+ def run
14
+ subscribe_to_channels
15
+ subscribe_ping
16
+ loop do
17
+ sleep(1) # Keep your main thread running
18
+ end
19
+ end
20
+
21
+
22
+ def subscribe_to_channels
23
+ @pusher_socket.subscribe('channel1')
24
+ @pusher_socket.subscribe('channel2')
25
+
26
+ # Bind to a global event (can occur on either channel1 or channel2)
27
+ @pusher_socket.bind('globalevent') do |data|
28
+ puts data
29
+ end
30
+
31
+ # Bind to a channel event (can only occur on channel1)
32
+ @pusher_socket['channel1'].bind('channelevent') do |data|
33
+ self.publish_result('hello', :rock => 'on!')
34
+ puts data
35
+ end
36
+
37
+ # Bind to a channel event
38
+ @pusher_socket['channel2'].bind('hello') do |data|
39
+ puts "GOT BACK! with #{data}"
40
+ end
41
+ end
42
+
43
+
44
+ def subscribe_ping
45
+ @pusher_socket.subscribe('ping')
46
+ @pusher_socket['ping'].bind('ping') do
47
+ self.pong
48
+ end
49
+ end
50
+
51
+ def pong
52
+ Pusher['pong'].trigger!('pong', :host => @config.hostname)
53
+ end
54
+
55
+ def publish_result(event, data)
56
+ Pusher['channel2'].trigger!(event, data)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,44 @@
1
+ class ConfigNotFoundException < Exception
2
+ end
3
+ module Eagle
4
+ class Config
5
+ attr_accessor :data
6
+ def initialize(config_path=nil)
7
+ locations = Config.default_config_locations
8
+ locations = [config_path] if config_path
9
+ locations.each do |file|
10
+ @data = YAML.load(File.read(file)) if File.exist?(file)
11
+ end
12
+
13
+ unless @data
14
+ raise ConfigNotFoundException, "Not found at #{locations.join(', ')}"
15
+ end
16
+ end
17
+
18
+ [:pusher_key, :pusher_secret, :pusher_app_id, :pusher_address, :pusher_port, :pusher_ws_port].each do |key|
19
+ define_method key do
20
+ @data[key.to_s]
21
+ end
22
+ end
23
+
24
+ def hostname
25
+ @data['hostname'] ||%x(hostname)
26
+ end
27
+
28
+ #### singleton config
29
+ def self.config(config_path=nil)
30
+ @config || Config.new(config_path)
31
+ end
32
+
33
+ def self.reset
34
+ @config = nil
35
+ end
36
+
37
+ def self.default_config_locations
38
+ filename = 'eagle.yml'
39
+ home = File.expand_path('~')
40
+ locations = ["#{home}/.#{filename}", "/etc/#{filename}", filename]
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,32 @@
1
+ module Eagle
2
+ class PusherConfigurator
3
+ attr_accessor :config
4
+ def initialize(config_param)
5
+ @config = config_param
6
+ end
7
+
8
+ ## pusher is for pushing events (pusher gem)
9
+ def init_pusher
10
+ Pusher.app_id = @config.pusher_app_id
11
+ Pusher.key = @config.pusher_key
12
+ Pusher.secret = @config.pusher_secret
13
+ Pusher.host = @config.pusher_address
14
+ Pusher.port = @config.pusher_port
15
+ end
16
+
17
+
18
+ ## pusher-client is for subscribing to events (pusher-client gem)
19
+ def init_pusher_client
20
+ suppress_warnings do
21
+ PusherClient.const_set(:HOST, @config.pusher_address)
22
+ PusherClient.const_set(:WS_PORT, @config.pusher_ws_port)
23
+ PusherClient.logger = Logger.new(STDOUT)
24
+ end
25
+
26
+ options = {:secret => @config.pusher_secret}
27
+ @pusher_socket = PusherClient::Socket.new(@config.pusher_key, options)
28
+ @pusher_socket.connect(true) # Connect asynchronously
29
+ return @pusher_socket
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,5 @@
1
+ module Eagle
2
+ class Server
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Eagle
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ module Kernel
2
+ def suppress_warnings
3
+ original_verbosity = $VERBOSE
4
+ $VERBOSE = nil
5
+ result = yield
6
+ $VERBOSE = original_verbosity
7
+ return result
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ ---
2
+ pusher_app_id: 'your-pusher-app-id'
3
+ pusher_key: '11111111111111111'
4
+ pusher_secret: 'your-pusher-secret'
5
+ pusher_address: 'localhost'
6
+ pusher_port: 4567
7
+ pusher_ws_port: 8080
8
+ hostname: testnode
@@ -0,0 +1,24 @@
1
+ require 'test/test_helper'
2
+
3
+ describe Eagle::Client do
4
+
5
+ def new_config
6
+ Eagle::Config.new(fixture_path('eagle1.yml'))
7
+ end
8
+
9
+ it "must be defined" do
10
+ Eagle::Client.wont_be_nil
11
+ end
12
+
13
+ it "is initializable" do
14
+ client = Eagle::Client.new(new_config)
15
+ client.config.wont_be_nil
16
+ end
17
+
18
+ it "subscribes to channels to 2 channels" do
19
+ client = Eagle::Client.new(new_config)
20
+ client.pusher_socket.channels.size.must_equal 0
21
+ client.subscribe_to_channels
22
+ client.pusher_socket.channels.size.must_equal 2
23
+ end
24
+ end
@@ -0,0 +1,45 @@
1
+ require 'test/test_helper'
2
+
3
+ describe Eagle::Config do
4
+ it "must be defined" do
5
+ Eagle::Config.wont_be_nil
6
+ end
7
+
8
+ it "raises, if not config file was found" do
9
+ Eagle::Config.stub(:default_config_locations, []) do
10
+ Eagle::Config.reset
11
+ proc { Eagle::Config.config }.must_raise ConfigNotFoundException
12
+ end
13
+ end
14
+
15
+
16
+ it "has some default locations for config file" do
17
+ locs = Eagle::Config.default_config_locations
18
+ locs.size.must_equal 3
19
+ end
20
+
21
+
22
+ describe 'config file present' do
23
+ before do
24
+ @config = Eagle::Config.config(fixture_path('eagle1.yml'))
25
+ end
26
+
27
+ it "loads the config" do
28
+ @config.wont_be_nil
29
+ end
30
+
31
+ it "is instance of class Config" do
32
+ @config.must_be_instance_of Eagle::Config
33
+ end
34
+
35
+ it "has dynamic methods for pusher" do
36
+ @config.pusher_app_id.must_equal 'your-pusher-app-id'
37
+ @config.pusher_key.must_equal '11111111111111111'
38
+ @config.pusher_secret.must_equal 'your-pusher-secret'
39
+ @config.pusher_address.must_equal 'localhost'
40
+ @config.pusher_port.must_equal 4567
41
+ @config.pusher_ws_port.must_equal 8080
42
+ @config.hostname.must_equal 'testnode'
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,30 @@
1
+ require 'test/test_helper'
2
+
3
+ describe Eagle::PusherConfigurator do
4
+ def new_config
5
+ Eagle::Config.new(fixture_path('eagle1.yml'))
6
+ end
7
+
8
+ it "must be defined" do
9
+ Eagle::PusherConfigurator.wont_be_nil
10
+ end
11
+
12
+ describe 'init_pusher' do
13
+ it "configures pusher" do
14
+ cnf = new_config
15
+ Pusher.app_id = ''
16
+ push_conf = Eagle::PusherConfigurator.new(cnf)
17
+ push_conf.init_pusher
18
+ Pusher.app_id.must_equal(cnf.pusher_app_id)
19
+ end
20
+ end
21
+
22
+ describe 'init_pusher_client' do
23
+ it "configures pusher-client" do
24
+ cnf = new_config
25
+ push_conf = Eagle::PusherConfigurator.new(cnf)
26
+ pusher_socket = push_conf.init_pusher_client
27
+ pusher_socket.must_be_instance_of PusherClient::Socket
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/test_helper'
2
+
3
+ describe Eagle::Server do
4
+ it "must be defined" do
5
+ Eagle::Server.wont_be_nil
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'test/test_helper'
2
+
3
+ describe Eagle do
4
+
5
+ it "must define version" do
6
+ Eagle::VERSION.wont_be_nil
7
+ end
8
+
9
+ it "uses fixture path" do
10
+ fixture_path('eagle1.yml').split('/')[-3..-1].join('/').must_equal "test/fixtures/eagle1.yml"
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
3
+ require 'minitest/autorun'
4
+ require 'minitest/pride'
5
+ require File.expand_path('../../lib/eagle.rb', __FILE__)
6
+
7
+
8
+ def fixture_path(file)
9
+ File.expand_path("../fixtures/#{file}", __FILE__)
10
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eagle
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Roman Heinrich
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-18 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Manage servers with ease with eagle
22
+ email:
23
+ - roman.heinrich@gmail.com
24
+ executables:
25
+ - eagle-client
26
+ - eagle-server
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Gemfile.lock
35
+ - LICENSE
36
+ - README.md
37
+ - Rakefile
38
+ - bin/eagle-client
39
+ - bin/eagle-server
40
+ - eagle.gemspec
41
+ - example/eagle.yml
42
+ - lib/eagle.rb
43
+ - lib/eagle/client.rb
44
+ - lib/eagle/config.rb
45
+ - lib/eagle/pusher_configurator.rb
46
+ - lib/eagle/server.rb
47
+ - lib/eagle/version.rb
48
+ - lib/ext/kernel.rb
49
+ - test/fixtures/eagle1.yml
50
+ - test/lib/eagle/client_test.rb
51
+ - test/lib/eagle/config_test.rb
52
+ - test/lib/eagle/pusher_configurator_test.rb
53
+ - test/lib/eagle/server_test.rb
54
+ - test/lib/eagle/version_test.rb
55
+ - test/test_helper.rb
56
+ homepage: ""
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.16
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Enables realtime server management with optional web UI
89
+ test_files:
90
+ - test/fixtures/eagle1.yml
91
+ - test/lib/eagle/client_test.rb
92
+ - test/lib/eagle/config_test.rb
93
+ - test/lib/eagle/pusher_configurator_test.rb
94
+ - test/lib/eagle/server_test.rb
95
+ - test/lib/eagle/version_test.rb
96
+ - test/test_helper.rb