rpcplus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ab162c7ab7c430aaaa812b273658e4bff3310b0
4
+ data.tar.gz: 2e56041ad9c31bb4ecb40b17fb49ec651c99ec0d
5
+ SHA512:
6
+ metadata.gz: 1b94e9dc07241a4054d9d7f978b6a6ad812b39892cda49deaf767e332df1fb0a8b5d9d58bba66fbe208476d783a7f1147c44416c5d38c663aa5e6d76f2af566c
7
+ data.tar.gz: d8020ff9f754dce03d6ba00b980b1d103891c1d2104dbc68c7aa5804143ca2838e518583c0a1e1002d60338437a17caf6ef2db1137edbbfcdd7e9a2174a21a81
@@ -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
@@ -0,0 +1 @@
1
+ See the [Flynn contributing guide](https://flynn.io/docs/contributing)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rpcplus.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ Flynn is a trademark of Apollic Software, LLC.
2
+
3
+ Copyright (c) 2014 Apollic Software, LLC. All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are
7
+ met:
8
+
9
+ * Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ * Redistributions in binary form must reproduce the above
12
+ copyright notice, this list of conditions and the following disclaimer
13
+ in the documentation and/or other materials provided with the
14
+ distribution.
15
+ * Neither the name of Apollic Software, LLC nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,2 @@
1
+ Jonathan Rudenberg <jonathan@titanous.com> (github: titanous)
2
+ Lewis Marshall <lewis@lmars.net> (github: lmars)
@@ -0,0 +1,29 @@
1
+ # RPCPlus
2
+
3
+ A Flynn RPCPlus client for Ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rpcplus'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rpcplus
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/<my-github-username>/rpcplus/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "rpcplus/client"
2
+ require "rpcplus/response"
@@ -0,0 +1,54 @@
1
+ require "celluloid/io"
2
+ require "yajl"
3
+
4
+ module RPCPlus
5
+ class Client
6
+ include Celluloid::IO
7
+ finalizer :shutdown
8
+
9
+ def initialize(host, port)
10
+ @seq = 0
11
+ @requests = {}
12
+
13
+ @sock = Celluloid::IO::TCPSocket.new(host, port)
14
+ @sock.write("CONNECT /_goRPC_ HTTP/1.0\r\nAccept: application/vnd.flynn.rpc-hijack+json\r\n\r\n")
15
+ response = @sock.readline(/\r?\n/)
16
+ raise 'invalid response' if !response.start_with?('HTTP/1.0 200')
17
+ @sock.readline(/\r?\n/)
18
+ async.read_responses
19
+ end
20
+
21
+ def request(method, arg, &block)
22
+ req = { 'id' => @seq+=1, 'method' => method, 'params' => [arg] }
23
+ future = Celluloid::Future.new
24
+ @requests[req['id']] = { stream: block, future: future }
25
+ Yajl::Encoder.encode(req, @sock)
26
+
27
+ # block until stream is done, so that the block doesn't become invalid due
28
+ # to https://github.com/celluloid/celluloid/pull/245
29
+ future.value if block
30
+
31
+ future
32
+ end
33
+
34
+ private
35
+
36
+ def shutdown
37
+ @sock.close if @sock
38
+ end
39
+
40
+ def read_responses
41
+ loop do
42
+ response = Yajl::Parser.parse(@sock.readline)
43
+ req = @requests[response['id']]
44
+ next if !req
45
+ if req[:stream] && !response['error']
46
+ req[:stream].call(response['result'])
47
+ next
48
+ end
49
+ req[:future].signal(Response.new(response["result"]))
50
+ @requests.delete(response['id'])
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,4 @@
1
+ module RPCPlus
2
+ class Response < Struct.new(:value)
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module RPCPlus
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rpcplus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rpcplus"
8
+ spec.version = RPCPlus::VERSION
9
+ spec.authors = ["Lewis Marshall"]
10
+ spec.email = ["lewis@lmars.net"]
11
+ spec.summary = %q{A Flynn RPCPlus client for Ruby}
12
+ spec.description = %q{A Flynn RPCPlus client for Ruby}
13
+ spec.homepage = ""
14
+ spec.license = "BSD"
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 "celluloid-io"
22
+ spec.add_dependency "yajl-ruby"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpcplus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lewis Marshall
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: celluloid-io
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: yajl-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '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'
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.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
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
+ description: A Flynn RPCPlus client for Ruby
70
+ email:
71
+ - lewis@lmars.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - CONTRIBUTING.md
78
+ - Gemfile
79
+ - LICENSE
80
+ - MAINTAINERS
81
+ - README.md
82
+ - Rakefile
83
+ - lib/rpcplus.rb
84
+ - lib/rpcplus/client.rb
85
+ - lib/rpcplus/response.rb
86
+ - lib/rpcplus/version.rb
87
+ - rpcplus.gemspec
88
+ homepage: ''
89
+ licenses:
90
+ - BSD
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.0.14
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: A Flynn RPCPlus client for Ruby
112
+ test_files: []