eye-http 0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTM3N2NlZmM0NTUyOTAzMzFmMTEwNjhkODYxYjcwODBhNmUyYzZhMQ==
5
+ data.tar.gz: !binary |-
6
+ OGIxNDE2ZDgzMWNiMjczY2IyZTFmNWM3ODY0MjkyOTJlYmNiN2M2ZQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDQ3YzVjNWIyODUzYTNiZTdmNTNmYmJhODA4ZTU4ZTRjZjFlMzE3MjViMTBh
10
+ MGQ2ZGU2YTFiOGEyZTFmNGQ0NzhhMzBlYmRlY2QyOWUwNjc3ZDRlMWM1ZDk5
11
+ ZjFiOGMxM2U5ZmE3YjliNTdhMzg0NWNmODhjOGRkNGUxODRmYTk=
12
+ data.tar.gz: !binary |-
13
+ ODNjMDEwZGI4OGIwNzZmNDUzMzNjN2Y4YjM2NzI2YWY3ODc2YzQxZTI5NWVk
14
+ Y2YwZjhhNzgzN2UzZmI1OTRjYzQ1OGU5NDU2ZTE2NDdlNTJmMmQ3YzAxZDBk
15
+ ZGYzOWMwMjEzMWRhNTVjZDUzOTdhZWU2YTRkYTY2OWFhNmRkOGE=
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ *.log
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eye-http.gemspec
4
+ gemspec
5
+
6
+ #gem 'eye', :git => "https://github.com/kostya/eye.git"
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 'Konstantin Makarchev'
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,38 @@
1
+ Eye::Http
2
+ ---------
3
+
4
+ Http interface for the [Eye](http://github.com/kostya/eye) gem.
5
+
6
+ ## Installation
7
+
8
+ gem install eye
9
+ gem install eye-http
10
+
11
+ ## Usage
12
+
13
+ Example config:
14
+
15
+ ```ruby
16
+ require 'eye-http'
17
+
18
+ Eye.config do
19
+ http :enable => true, :host => "127.0.0.1", :port => 12345
20
+ end
21
+
22
+ Eye.application :app do
23
+ process :process do
24
+ start_command "sleep 100"
25
+ daemonize true
26
+ pid_file "/tmp/1.pid"
27
+ end
28
+ end
29
+ ```
30
+
31
+ Run:
32
+
33
+ bundle exec eye l examples/1.eye
34
+
35
+ Api:
36
+
37
+ curl http://127.0.0.1:12345/api/info?filter=all
38
+ curl -X PUT http://127.0.0.1:12345/api/restart?filter=all
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :spec
5
+
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.verbose = false
8
+ end
@@ -0,0 +1,13 @@
1
+ require 'eye-http'
2
+
3
+ Eye.config do
4
+ http :enable => true, :host => "127.0.0.1", :port => 12345
5
+ end
6
+
7
+ Eye.application :app do
8
+ process :process do
9
+ start_command "sleep 100"
10
+ daemonize true
11
+ pid_file "/tmp/1.pid"
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eye-http/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eye-http"
8
+ spec.version = Eye::Http::VERSION
9
+ spec.authors = ["'Konstantin Makarchev'"]
10
+ spec.email = ["'kostya27@gmail.com'"]
11
+ spec.summary = %q{Http interface for the Eye gem.}
12
+ spec.description = %q{Http interface for the Eye gem.}
13
+ spec.homepage = "https://github.com/kostya/eye-http"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'eye', '~> 0.6'
22
+ spec.add_dependency 'reel', '~> 0.5.0'
23
+ spec.add_dependency 'reel-rack'
24
+ spec.add_dependency 'cuba'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.6"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec", '<2.14'
29
+ spec.add_development_dependency "rr"
30
+ end
@@ -0,0 +1,4 @@
1
+ require 'eye'
2
+
3
+ require_relative 'eye-http/extend_eye'
4
+ require_relative 'eye-http/version'
@@ -0,0 +1,37 @@
1
+ Eye::Dsl::ConfigOpts
2
+ class Eye::Dsl::ConfigOpts
3
+ create_options_methods([:http], Hash)
4
+ end
5
+
6
+ Eye::Controller
7
+ class Eye::Controller
8
+ def set_opt_http(params = {})
9
+ if params[:enable]
10
+ if @http
11
+ if params[:host] != @http.host || params[:port].to_i != @http.port
12
+ stop_http
13
+ start_http(params[:host], params[:port])
14
+ end
15
+ else
16
+ start_http(params[:host], params[:port])
17
+ end
18
+ else
19
+ stop_http if @http
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def stop_http
26
+ if @http
27
+ @http.stop
28
+ @http = nil
29
+ end
30
+ end
31
+
32
+ def start_http(host, port)
33
+ require_relative 'http'
34
+ @http = Eye::Http.new(host, port)
35
+ @http.start
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ gem 'reel', '~> 0.5.0'
2
+ gem 'reel-rack'
3
+ gem 'cuba'
4
+
5
+ require 'reel/rack/server'
6
+
7
+ class Eye::Http
8
+ autoload :Router, 'eye-http/router'
9
+
10
+ attr_reader :server, :host, :port
11
+
12
+ def initialize(host, port)
13
+ @host = host
14
+ @port = port.to_i
15
+ @router = Router
16
+ end
17
+
18
+ def start
19
+ stop
20
+ @server = Reel::Rack::Server.supervise(@router, :Host => @host, :Port => port)
21
+ end
22
+
23
+ def stop
24
+ if @server
25
+ @server.terminate
26
+ @server = nil
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ require 'cuba'
2
+ require 'json'
3
+
4
+ Eye::Http::Router = Cuba.new do
5
+ def json(result)
6
+ res.headers['Content-Type'] = 'application/json; charset=utf-8'
7
+ res.write({ result: result }.to_json)
8
+ end
9
+
10
+ on root do
11
+ res.write Eye::ABOUT
12
+ end
13
+
14
+ on "api/info", param("filter") do |filter|
15
+ json Eye::Control.command(:info_data, filter)
16
+ end
17
+
18
+ [:start, :stop, :restart, :delete, :unmonitor, :monitor].each do |act|
19
+ on put, "api/#{act}", param("filter") do |filter|
20
+ json Eye::Control.command(act, filter)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Eye
2
+ class Http
3
+ VERSION = "0.6"
4
+ end
5
+ end
@@ -0,0 +1,49 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe "http" do
4
+ subject{ Eye::Controller.new }
5
+
6
+ let(:uri){ URI.parse("http://127.0.0.1:#{PORT}/") }
7
+ let(:uri2){ URI.parse("http://127.0.0.1:#{PORT+1}/") }
8
+
9
+ it "load config with http enable" do
10
+ expect{ Net::HTTP.get(uri) }.to raise_error(Errno::ECONNREFUSED)
11
+
12
+ subject.load2(fixture("http1.eye"))
13
+ Net::HTTP.get(uri).should == Eye::ABOUT
14
+ end
15
+
16
+ it "load config with http enable then disable" do
17
+ subject.load2(fixture("http1.eye"))
18
+ Net::HTTP.get(uri).should == Eye::ABOUT
19
+
20
+ subject.load2(fixture("http2.eye"))
21
+ expect{ Net::HTTP.get(uri) }.to raise_error(Errno::ECONNREFUSED)
22
+ end
23
+
24
+ it "load config with http enable then change port" do
25
+ subject.load2(fixture("http1.eye"))
26
+ Net::HTTP.get(uri).should == Eye::ABOUT
27
+
28
+ subject.load2(fixture("http3.eye"))
29
+ expect{ Net::HTTP.get(uri) }.to raise_error(Errno::ECONNREFUSED)
30
+ Net::HTTP.get(uri2).should == Eye::ABOUT
31
+ end
32
+
33
+ it "should not reconnect when load the same config" do
34
+ res = subject.load2(fixture("http1.eye"))
35
+ res.values.map{|c| c[:error]}.should == [false]
36
+ Net::HTTP.get(uri).should == Eye::ABOUT
37
+
38
+ dont_allow(subject).stop_http
39
+
40
+ res = subject.load2(fixture("http1.eye"))
41
+ res.values.map{|c| c[:error]}.should == [false]
42
+ Net::HTTP.get(uri).should == Eye::ABOUT
43
+ end
44
+
45
+ it "load error should catch" do
46
+ res = subject.load2(fixture("http4.eye"))
47
+ res.values.map{|c| c[:error]}.should == [true]
48
+ end
49
+ end
@@ -0,0 +1,25 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe "Eye::Http" do
4
+ let(:uri){ URI.parse("http://127.0.0.1:#{PORT}/") }
5
+
6
+ it "should up and down" do
7
+ app = Eye::Http.new(uri.host, uri.port)
8
+
9
+ expect{ Net::HTTP.get(uri) }.to raise_error(Errno::ECONNREFUSED)
10
+
11
+ app.start
12
+ sleep 0.5
13
+ Net::HTTP.get(uri).should == Eye::ABOUT
14
+
15
+ app.stop
16
+ sleep 0.5
17
+ expect{ Net::HTTP.get(uri) }.to raise_error(Errno::ECONNREFUSED)
18
+
19
+ app.start
20
+ sleep 0.5
21
+ Net::HTTP.get(uri).should == Eye::ABOUT
22
+
23
+ app.stop
24
+ end
25
+ end
@@ -0,0 +1,5 @@
1
+ require 'eye-http'
2
+
3
+ Eye.config do
4
+ http :enable => true, :host => "127.0.0.1", :port => 12346
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'eye-http'
2
+
3
+ Eye.config do
4
+ http :enable => false
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'eye-http'
2
+
3
+ Eye.config do
4
+ http :enable => true, :host => "127.0.0.1", :port => 12347
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'eye-http'
2
+
3
+ Eye.config do
4
+ http :enable => true, :hhhasdf => 2, :port => :aa
5
+ end
@@ -0,0 +1,25 @@
1
+ require 'bundler/setup'
2
+ Bundler.require
3
+ require 'celluloid'
4
+
5
+ require 'uri'
6
+ require 'net/http'
7
+
8
+ PORT = 12346
9
+
10
+ def fixture(name)
11
+ File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', name))
12
+ end
13
+
14
+ class Eye::Controller
15
+ def load2(*args); load(*args); end
16
+ end
17
+
18
+ Eye::Logger.link_logger(File.join(File.dirname(__FILE__), ["spec.log"]))
19
+
20
+ RSpec.configure do |config|
21
+ config.mock_with :rr
22
+
23
+ config.before { Celluloid.boot }
24
+ config.after { Celluloid.shutdown }
25
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eye-http
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.6'
5
+ platform: ruby
6
+ authors:
7
+ - ! '''Konstantin Makarchev'''
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: eye
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: reel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.5.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: reel-rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cuba
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.6'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - <
102
+ - !ruby/object:Gem::Version
103
+ version: '2.14'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - <
109
+ - !ruby/object:Gem::Version
110
+ version: '2.14'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Http interface for the Eye gem.
126
+ email:
127
+ - ! '''kostya27@gmail.com'''
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - Gemfile
134
+ - LICENSE.txt
135
+ - README.md
136
+ - Rakefile
137
+ - examples/1.eye
138
+ - eye-http.gemspec
139
+ - lib/eye-http.rb
140
+ - lib/eye-http/extend_eye.rb
141
+ - lib/eye-http/http.rb
142
+ - lib/eye-http/router.rb
143
+ - lib/eye-http/version.rb
144
+ - spec/controller_spec.rb
145
+ - spec/eye-http_spec.rb
146
+ - spec/fixtures/http1.eye
147
+ - spec/fixtures/http2.eye
148
+ - spec/fixtures/http3.eye
149
+ - spec/fixtures/http4.eye
150
+ - spec/spec_helper.rb
151
+ homepage: https://github.com/kostya/eye-http
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ! '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.2.2
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Http interface for the Eye gem.
175
+ test_files:
176
+ - spec/controller_spec.rb
177
+ - spec/eye-http_spec.rb
178
+ - spec/fixtures/http1.eye
179
+ - spec/fixtures/http2.eye
180
+ - spec/fixtures/http3.eye
181
+ - spec/fixtures/http4.eye
182
+ - spec/spec_helper.rb