grenache-ruby-http 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bbaaef7fb85e08eab6ea57cdd0f8c1da399c0845
4
+ data.tar.gz: 65f844f3717c31fc38bcf8c2378577dc9c011b64
5
+ SHA512:
6
+ metadata.gz: 31c3a5c2d96714d51fdfab5c81f2fb247d2a235ed13c44720a39e9e38a14d03d8ea46c0c2de9bc346a837796bd0641e8684e29d29513fad08b56496f3d0f0d44
7
+ data.tar.gz: 8a91654aee0475ffd5e49196e8f1b1b473ebb4c589b1edac0f781a346ae37d6f298fa567691e68b365d3b2cde5193cef22301de004c72c64243cd35a78820369
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "eventmachine", "~> 1.0.9"
4
+ gem "faye-websocket", "~> 0.10.3"
5
+ gem "grenache-ruby-base"
6
+ gem 'httpclient'
7
+
8
+ gem "oj", "~> 2.1.0"
9
+ gem "thin"
10
+
11
+ group :development do
12
+ gem "pry"
13
+ gem "bundler", "~> 1.9"
14
+ gem "rake", "~> 10.0"
15
+ gem "rspec", "~> 3.1.0"
16
+ gem "simplecov", "~> 0.11.0"
17
+ end
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # grenache-ruby-http
2
+
3
+ # Configuration
4
+
5
+ ```ruby
6
+ Grenache::Base.configure do |conf|
7
+ conf.grape_address = "http://10.0.0.1:30002"
8
+ end
9
+ ```
10
+
11
+ # Usage
12
+
13
+ ## Announce a service
14
+
15
+ ```ruby
16
+ c = Grenache::Base.new
17
+
18
+ c.listen("test",5001) do |env|
19
+ req = Oj.load(env['rack.input'].read)
20
+ [200,nil,"hello #{req}"]
21
+ end
22
+ ```
23
+
24
+
25
+ ## calling a remote service
26
+
27
+ ```ruby
28
+ c.request('test', 'world')
29
+ ```
30
+
@@ -0,0 +1,17 @@
1
+ require 'grenache-ruby-base'
2
+
3
+ require_relative "../lib/grenache/base.rb"
4
+
5
+ Grenache::Base.configure do |conf|
6
+ conf.grape_address = "http://127.0.0.1:40002/"
7
+ end
8
+
9
+ c = Grenache::Base.new
10
+ start_time = Time.now
11
+
12
+ 10000.times do |n|
13
+ c.request("test","world #{n}")
14
+ end
15
+
16
+ puts "Total Time: #{Time.now - start_time}"
17
+
@@ -0,0 +1,21 @@
1
+ require 'thin'
2
+ require 'grenache-ruby-base'
3
+ require_relative "../lib/grenache/base.rb"
4
+
5
+ Grenache::Base.configure do |conf|
6
+ conf.grape_address = "http://127.0.0.1:40002/"
7
+ end
8
+
9
+ EM.run do
10
+
11
+ Signal.trap("INT") { EventMachine.stop }
12
+ Signal.trap("TERM") { EventMachine.stop }
13
+
14
+ c = Grenache::Base.new
15
+
16
+ c.listen('test',5004) do |env|
17
+ req = Oj.load(env['rack.input'].read)
18
+ [200,nil,"hello #{req}"]
19
+ end
20
+
21
+ end
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grenache/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grenache-ruby-http"
8
+ spec.version = Grenache::HTTP::VERSION
9
+ spec.email = ["info@bitfinex.com"]
10
+
11
+ spec.summary = %q{http client for Grenache}
12
+ spec.homepage = "https://github.com/bitfinexcom/grenache-ruby-http"
13
+ spec.license = "MIT"
14
+ spec.authors = "Bitfinex"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ # spec.add_bundler_dependencies
20
+ end
@@ -0,0 +1,26 @@
1
+ module Grenache
2
+ class Base
3
+ def listen(key, port, opts={}, &block)
4
+ start_http_service(port,&block)
5
+
6
+ announce(key, port, opts) do |res|
7
+ puts "#{key} announced #{res}"
8
+ end
9
+ end
10
+
11
+ def start_http_service(port, &block)
12
+ EM.defer {
13
+ app = -> (env) {
14
+ block.call(env)
15
+ }
16
+ server = Thin::Server.start('0.0.0.0', port, app, {signals: false})
17
+ }
18
+ end
19
+
20
+ def request(key, payload, &block)
21
+ services = lookup(key)
22
+ json = Oj.dump(payload)
23
+ res = http.post(services.sample,json).body
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module Grenache
2
+ module HTTP
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require 'oj'
2
+ require 'eventmachine'
3
+ require 'faye/websocket'
4
+ require 'httpclient'
5
+ require 'thin'
6
+ require 'rack'
7
+ require 'pry'
8
+
9
+ require 'grenache/base'
10
+ require 'grenache/version'
11
+
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grenache-ruby-http
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bitfinex
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - info@bitfinex.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - Gemfile
23
+ - README.md
24
+ - examples/client.rb
25
+ - examples/worker.rb
26
+ - grenache-ruby-http.gemspec
27
+ - lib/grenache-ruby-http.rb
28
+ - lib/grenache/base.rb
29
+ - lib/grenache/version.rb
30
+ homepage: https://github.com/bitfinexcom/grenache-ruby-http
31
+ licenses:
32
+ - MIT
33
+ metadata: {}
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubyforge_project:
50
+ rubygems_version: 2.4.5
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: http client for Grenache
54
+ test_files: []
55
+ has_rdoc: