wamp-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wamp-client.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Eric Wollesen
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,29 @@
1
+ # Wamp::Client
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'wamp-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install wamp-client
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,111 @@
1
+ require "wamp/client/version"
2
+ require "net/ws"
3
+ require "json"
4
+ require "timeout"
5
+
6
+
7
+ module WAMP
8
+ class Client
9
+ TYPEID_WELCOME = 0
10
+ TYPEID_PREFIX = 1
11
+ TYPEID_CALL = 2
12
+ TYPEID_CALLRESULT = 3
13
+ TYPEID_CALLERROR = 4
14
+ TYPEID_SUBSCRIBE = 5
15
+ TYPEID_UNSUBSCRIBE = 6
16
+ TYPEID_PUBLISH = 7
17
+ TYPEID_EVENT = 8
18
+
19
+
20
+ def initialize(uri, options=nil)
21
+ options ||= {}
22
+ @session_id = nil
23
+ @ws = Net::WS.new(uri, options)
24
+ @subscriptions = {}
25
+ end
26
+
27
+ def open(request_uri="/")
28
+ @ws.open(request_uri)
29
+ receive_welcome_message
30
+ end
31
+
32
+ def close
33
+ @ws.close
34
+ end
35
+
36
+ # FIXME: this doesn't seem to be working yet... I've no idea why
37
+ def prefix(prefix, uri)
38
+ payload = [TYPEID_PREFIX, prefix, uri]
39
+ @ws.send_text(JSON.dump(payload))
40
+ end
41
+
42
+ def subscribe(uri_or_curie, cb)
43
+ payload = [TYPEID_SUBSCRIBE, uri_or_curie]
44
+ @ws.send_text(JSON.dump(payload))
45
+ @subscriptions[uri_or_curie] = @subscriptions.fetch(uri_or_curie, []) << cb
46
+ end
47
+
48
+ def to_io
49
+ @ws.to_io
50
+ end
51
+
52
+ def handle_message
53
+ payload = receive_message
54
+
55
+ case payload[0]
56
+ when TYPEID_EVENT
57
+ handle_event(payload)
58
+ else
59
+ $stderr.puts "Unhandled message type id: #{payload[0].pretty_inspect}"
60
+ end
61
+ end
62
+
63
+ def check(timeout=5)
64
+ Timeout.timeout(timeout) do
65
+ loop {handle_message}
66
+ end
67
+ rescue Timeout::Error
68
+ # noop
69
+ end
70
+
71
+ def publish(uri_or_curie, data)
72
+ payload = [TYPEID_PUBLISH, uri_or_curie, data]
73
+ @ws.send_text(JSON.dump(payload))
74
+ end
75
+
76
+
77
+ private
78
+
79
+ def handle_event(payload)
80
+ uri_or_curie = payload[1]
81
+ data = payload[2]
82
+
83
+ unless @subscriptions.fetch(uri_or_curie, nil)
84
+ $stderr.puts "received event for unsubscribed channel: #{uri_or_curie.pretty_inspect}"
85
+ end
86
+
87
+ @subscriptions.fetch(uri_or_curie, []).each do |cb|
88
+ cb.call(data, self, uri_or_curie)
89
+ end
90
+ data
91
+ end
92
+
93
+ def receive_welcome_message
94
+ message = receive_message
95
+ verify_welcome_message(message)
96
+ @session_id = message[1]
97
+ end
98
+
99
+ def _receive(payload)
100
+ JSON.parse(payload)
101
+ end
102
+
103
+ def receive_message
104
+ _receive(@ws.receive_message)
105
+ end
106
+
107
+ def verify_welcome_message(message)
108
+ raise "Invalid welcome message" unless TYPEID_WELCOME == message[0]
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,5 @@
1
+ module WAMP
2
+ class Client
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/wamp/client/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Eric Wollesen"]
6
+ gem.email = ["ericw@xmtp.net"]
7
+ gem.description = %q{WAMP client}
8
+ gem.summary = %q{WAMP client}
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 = "wamp-client"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = WAMP::Client::VERSION
17
+
18
+ gem.add_development_dependency("rake")
19
+ gem.add_development_dependency("pry")
20
+ gem.add_development_dependency("debugger")
21
+
22
+ gem.add_dependency("json")
23
+ gem.add_dependency("net-ws")
24
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wamp-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric Wollesen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: pry
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: debugger
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: json
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: net-ws
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: WAMP client
95
+ email:
96
+ - ericw@xmtp.net
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - LICENSE
104
+ - README.md
105
+ - Rakefile
106
+ - lib/wamp/client.rb
107
+ - lib/wamp/client/version.rb
108
+ - wamp-client.gemspec
109
+ homepage: ''
110
+ licenses: []
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ segments:
122
+ - 0
123
+ hash: -721303708302766997
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
126
+ requirements:
127
+ - - ! '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ segments:
131
+ - 0
132
+ hash: -721303708302766997
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 1.8.23
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: WAMP client
139
+ test_files: []