zulu 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7f16c83018fcb8ac0324f3df20f4deb456c3471
4
+ data.tar.gz: c679a05347a7fb989f3a74e1c19363ff6434a610
5
+ SHA512:
6
+ metadata.gz: cc3a872a910338267b87efd264ccfcb90e60c8cdbb6ab01f11615f11eaefa1f4859cd0df63e701a83e838b4fe03cdd798ba582d7b653fe749053aafff938ec0a
7
+ data.tar.gz: 5de0a6f083d27a311f34d25c9739765119ab80a5a6a785b6025f8001b0382a3757091386190e31c91753f232ffaf11efed2576968e86efe5b8bb35df4ae7caf8
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in zulu.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dan Weinand
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.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Zulu
2
+
3
+ Zulu is standalone PuSH-inspired service for scheduling web hook execution.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'zulu'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install zulu
18
+
19
+ ## Usage
20
+
21
+ Run zulu:
22
+
23
+ $ zulu
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ end
7
+
8
+ task :default => :test
data/bin/zulu ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'zulu'
4
+
5
+ Zulu.parse_options
6
+ Zulu.run
@@ -0,0 +1,23 @@
1
+ require 'sinatra/base'
2
+
3
+ module Zulu
4
+ class Server < Sinatra::Base
5
+ CONTENT_TYPES = ['application/x-www-form-urlencoded']
6
+
7
+ post '/' do
8
+ if valid_content_type?
9
+ process_subscription
10
+ else
11
+ status 406
12
+ end
13
+ end
14
+
15
+ def process_subscription
16
+ status 202
17
+ end
18
+
19
+ def valid_content_type?
20
+ CONTENT_TYPES.include?(request.content_type)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Zulu
2
+ VERSION = "0.0.1"
3
+ end
data/lib/zulu.rb ADDED
@@ -0,0 +1,61 @@
1
+ require "slop"
2
+ require "rack"
3
+ require "reel"
4
+
5
+ require "zulu/version"
6
+ require "zulu/server"
7
+
8
+ module Zulu
9
+ DEFAULTS = {
10
+ port: 9292,
11
+ host: "0.0.0.0",
12
+ servers: 0,
13
+ workers: 5,
14
+ database: "localhost:6379",
15
+ keeper: false
16
+ }
17
+
18
+ def self.options
19
+ @options ||= DEFAULTS.dup
20
+ end
21
+
22
+ def self.options=(opts)
23
+ @options = opts
24
+ end
25
+
26
+ def self.parse_options(args=ARGV)
27
+ banner = "Zulu #{Zulu::VERSION}\nUsage: zulu [options]"
28
+ opts = Slop.parse args, strict: true, help: true, banner: banner do
29
+ on :v, :version, 'Print the version' do
30
+ puts "Version #{Zulu::VERSION}"
31
+ end
32
+
33
+ on :p, :port, 'Use PORT (default: 9292)', argument: true, as: Integer
34
+ on :o, :host, 'Listen on HOST (default: 0.0.0.0)', argument: true
35
+ on :s, :servers, 'Run SERVERS server workers (default: 0)', argument: true, as: Integer
36
+ on :w, :workers, 'Run WORKERS background workers (default: 5)', argument: true, as: Integer
37
+ on :d, :database, "Connect to DATABASE (default: localhost:6379)", argument: true
38
+ on :k, :keeper, "Run a keeper worker (default: false)"
39
+ end
40
+ opts.each do |option|
41
+ next unless option.value
42
+ option.value.is_a?(String) and option.value.strip!
43
+ options[option.key.to_sym] = option.value
44
+ end
45
+ rescue Slop::Error => e
46
+ abort "ERROR: #{e.message}"
47
+ end
48
+
49
+ def self.run
50
+ if options[:servers] > 0
51
+ run_servers
52
+ end
53
+ end
54
+
55
+ def self.run_servers
56
+ Rack::Handler::Reel.run Zulu::Server, port: options[:port],
57
+ host: options[:host],
58
+ workers: options[:servers]
59
+ end
60
+
61
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'zulu'
3
+ require 'rack/test'
4
+
5
+ require 'minitest/autorun'
6
+ require 'minitest/english/deny'
@@ -0,0 +1,28 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestServer < MiniTest::Test
4
+ include Rack::Test::Methods
5
+ include Zulu
6
+
7
+ def app
8
+ Server
9
+ end
10
+
11
+ def subscribe_options(opts={})
12
+ {
13
+ 'hub.mode' => 'subscribe',
14
+ 'hub.topic' => '*/15 * * * *',
15
+ 'hub.callback' => 'http://www.example.org/callback'
16
+ }.merge(opts)
17
+ end
18
+
19
+ def test_it_accepts_subscription_request
20
+ post '/', subscribe_options
21
+ assert_equal 202, last_response.status, last_response.body
22
+ end
23
+
24
+ def test_it_wont_accept_incorrect_format
25
+ post '/', '', 'CONTENT_TYPE' => 'application/rss+xml'
26
+ assert_equal 406, last_response.status
27
+ end
28
+ end
data/test/test_zulu.rb ADDED
@@ -0,0 +1,81 @@
1
+ require 'minitest_helper'
2
+
3
+ class TestZulu < MiniTest::Test
4
+ def setup
5
+ Zulu.options = nil
6
+ end
7
+
8
+ def test_it_has_version_number
9
+ refute_nil ::Zulu::VERSION
10
+ end
11
+
12
+ #
13
+ # Zulu.parse_options
14
+ #
15
+
16
+ def test_it_has_default_option_for_port
17
+ assert_equal 9292, Zulu.options[:port]
18
+ end
19
+
20
+ def test_it_has_default_option_for_host
21
+ assert_equal '0.0.0.0', Zulu.options[:host]
22
+ end
23
+
24
+ def test_it_has_default_option_for_servers
25
+ assert_equal 0, Zulu.options[:servers]
26
+ end
27
+
28
+ def test_it_has_default_option_for_workers
29
+ assert_equal 5, Zulu.options[:workers]
30
+ end
31
+
32
+ def test_it_has_default_option_for_database
33
+ assert_equal 'localhost:6379', Zulu.options[:database]
34
+ end
35
+
36
+ def test_it_has_default_option_for_keeper
37
+ deny Zulu.options[:keeper]
38
+ end
39
+
40
+ def test_it_accepts_option_for_port
41
+ Zulu.parse_options(['-p 3000'])
42
+ assert_equal 3000, Zulu.options[:port]
43
+ end
44
+
45
+ def test_it_accepts_option_for_host
46
+ Zulu.parse_options(['-o 127.0.0.1'])
47
+ assert_equal '127.0.0.1', Zulu.options[:host]
48
+ end
49
+
50
+ def test_it_accepts_option_for_servers
51
+ Zulu.parse_options(['-s 7'])
52
+ assert_equal 7, Zulu.options[:servers]
53
+ end
54
+
55
+ def test_it_accepts_option_for_workers
56
+ Zulu.parse_options(['-w 7'])
57
+ assert_equal 7, Zulu.options[:workers]
58
+ end
59
+
60
+ def test_it_accepts_option_for_database
61
+ Zulu.parse_options(['-d localhost:9000'])
62
+ assert_equal 'localhost:9000', Zulu.options[:database]
63
+ end
64
+
65
+ def test_it_accepts_option_for_keeper
66
+ Zulu.parse_options(['-k'])
67
+ assert Zulu.options[:keeper]
68
+ end
69
+
70
+ def test_it_aborts_on_option_with_missing_arg
71
+ assert_raises(SystemExit) do
72
+ out, err = capture_io { Zulu.parse_options(['-p']) }
73
+ assert_match /ERROR:/, err
74
+ end
75
+ end
76
+
77
+ #
78
+ # Zulu.run
79
+ #
80
+
81
+ end
data/zulu.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'zulu/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "zulu"
8
+ spec.version = Zulu::VERSION
9
+ spec.authors = ["Dan Weinand"]
10
+ spec.email = ["dweinand@gmail.com"]
11
+ spec.description = %q{A standalone PuSH-inspired service for scheduling web hook execution}
12
+ spec.summary = %q{PuSH-inspired web hook scheduler}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_runtime_dependency "sinatra", "~> 1.4.3"
22
+ spec.add_runtime_dependency "reel", "~> 0.3.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "minitest", "~> 5.0.6"
27
+ spec.add_development_dependency "minitest-english", "~> 0.1.0"
28
+ spec.add_development_dependency "rack-test", "~> 0.6.2"
29
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zulu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dan Weinand
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.3
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.3.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.3.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 5.0.6
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: 5.0.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest-english
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.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.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rack-test
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: 0.6.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: 0.6.2
111
+ description: A standalone PuSH-inspired service for scheduling web hook execution
112
+ email:
113
+ - dweinand@gmail.com
114
+ executables:
115
+ - zulu
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - .travis.yml
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - bin/zulu
126
+ - lib/zulu.rb
127
+ - lib/zulu/server.rb
128
+ - lib/zulu/version.rb
129
+ - test/minitest_helper.rb
130
+ - test/test_server.rb
131
+ - test/test_zulu.rb
132
+ - zulu.gemspec
133
+ homepage: ''
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.0.3
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: PuSH-inspired web hook scheduler
157
+ test_files:
158
+ - test/minitest_helper.rb
159
+ - test/test_server.rb
160
+ - test/test_zulu.rb