wamp_client 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72e6d6b94bf4b5f244885438e6c122c952d5d084
4
- data.tar.gz: 0366993e7d42a1e3673210af8c8b4a05b63206e9
3
+ metadata.gz: 150daa5402442aaf1557dda7501439fa35266669
4
+ data.tar.gz: 72d8de49f166b98d2688c2602857c3eef5cbb07d
5
5
  SHA512:
6
- metadata.gz: 0de90b5fc4cdf71d2e76b587a232530b47fb8e0ebd961c5a77299f130714c575ac36061a5c0bdeb75de5a535d9711a07523b79360d1d1c777738f0314f70179a
7
- data.tar.gz: bf65fac58f124abb76d0c4518067f28f2046a29ffcb1d7fb0aede645654ae9d445ffeafded1c3d94aa759e316f9fd2738f38c72f8a2c3b4d2550a6ff21f6a4e8
6
+ metadata.gz: a16f76680f8b99352b8321729f9f538d40db5b5d208c864e1d6770cd89e31b9733a8b72bd1378321fe83523bd1829720b1e772ee12a2b6430ba7c76ca290379a
7
+ data.tar.gz: 986f7e28cd8773a040778704e28ca4c8f47f213157073f8bd51116599c2da0b70a42989decf524384f9b8374d1a6890b26b02beeace5ec1831c377371d5c072f
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # WampClient
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/wamp_client.svg)](https://badge.fury.io/rb/wamp_client)
3
4
  [![Circle CI](https://circleci.com/gh/ericchapman/ruby_wamp_client/tree/master.svg?&style=shield&circle-token=92813c17f9c9510c4c644e41683e7ba2572e0b2a)](https://circleci.com/gh/ericchapman/ruby_wamp_client/tree/master)
4
5
  [![Codecov](https://img.shields.io/codecov/c/github/ericchapman/ruby_wamp_client/master.svg)](https://codecov.io/github/ericchapman/ruby_wamp_client)
5
6
 
@@ -9,6 +10,9 @@ Client for talking to a WAMP Router. This is defined at
9
10
 
10
11
  ## Revision History
11
12
 
13
+ - v0.0.2:
14
+ - Added defer call result support
15
+ - Added progressive callee support
12
16
  - v0.0.1:
13
17
  - Initial Release
14
18
 
@@ -428,6 +432,84 @@ Options are
428
432
  - receive_progress [Boolean] - "true" if you support results being able to be sent progressively
429
433
  - disclose_me [Boolean] - "true" if the caller would like the callee to know the identity
430
434
 
435
+ #### Errors
436
+ Errors can either be raised OR returned as shown below
437
+
438
+ ```ruby
439
+ handler = lambda do |args, kwargs, details|
440
+ raise 'error'
441
+ # OR
442
+ raise WampClient::CallError.new('wamp.error', ['some error'], {details: true})
443
+ # OR
444
+ WampClient::CallError.new('wamp.error', ['some error'], {details: true})
445
+ end
446
+ session.register('com.example.procedure', handler)
447
+ ```
448
+
449
+ All 3 of the above examples will return a WAMP Error
450
+
451
+ #### Deferred Call
452
+ A deferred call refers to a call where the response needs to be asynchronously fetched before it can be returned to the
453
+ caller. This is shown below
454
+
455
+ ```ruby
456
+ def add(args, kwargs, details)
457
+ defer = WampClient::Defer::CallDefer.new
458
+ EM.add_timer(2) { # Something Async
459
+ defer.succeed(args[0]+args[1])
460
+ }
461
+ defer
462
+ end
463
+ session.register('com.example.procedure', method(:add))
464
+ ```
465
+
466
+ Errors are returned as follows
467
+
468
+ ```ruby
469
+ def add(args, kwargs, details)
470
+ defer = WampClient::Defer::CallDefer.new
471
+ EM.add_timer(2) { # Something Async
472
+ defer.fail(WampClient::CallError.new('test.error'))
473
+ }
474
+ defer
475
+ end
476
+ session.register('com.example.procedure', method(:add))
477
+ ```
478
+
479
+ #### Progressive Calls
480
+ Progressive calls are ones that return the result in pieces rather than all at once. They are invoked as follows
481
+
482
+ **Caller**
483
+
484
+ ```ruby
485
+ results = []
486
+ session.call('com.example.procedure', [], {}, {receive_progress: true}) do |result, error, details|
487
+ results = results + result.args
488
+ unless details[:progress]
489
+ puts results # => [1,2,3,4,5,6]
490
+ end
491
+ end
492
+ ```
493
+
494
+ **Callee**
495
+
496
+ ```ruby
497
+ def add(args, kwargs, details)
498
+ defer = WampClient::Defer::ProgressiveCallDefer.new
499
+ EM.add_timer(2) { # Something Async
500
+ defer.progress(WampClient::CallResult.new([1,2,3]))
501
+ }
502
+ EM.add_timer(4) { # Something Async
503
+ defer.progress(WampClient::CallResult.new([1,2,3]))
504
+ }
505
+ EM.add_timer(6) { # Something Async
506
+ defer.succeed(WampClient::CallResult.new())
507
+ }
508
+ defer
509
+ end
510
+ session.register('com.example.procedure', method(:add))
511
+ ```
512
+
431
513
  ## Contributing
432
514
 
433
515
  1. Fork it ( https://github.com/ericchapman/ruby_wamp_client )
data/lib/wamp_client.rb CHANGED
@@ -1,7 +1,35 @@
1
+ =begin
2
+
3
+ Copyright (c) 2016 Eric Chapman
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ =end
27
+
1
28
  require 'wamp_client/version'
2
29
  require 'wamp_client/message'
3
30
  require 'wamp_client/serializer'
4
31
  require 'wamp_client/transport'
5
32
  require 'wamp_client/connection'
6
33
  require 'wamp_client/session'
7
- require 'wamp_client/auth'
34
+ require 'wamp_client/auth'
35
+ require 'wamp_client/defer'
@@ -1,3 +1,30 @@
1
+ =begin
2
+
3
+ Copyright (c) 2016 Eric Chapman
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ =end
27
+
1
28
  require 'openssl'
2
29
  require 'base64'
3
30
 
@@ -1,3 +1,30 @@
1
+ =begin
2
+
3
+ Copyright (c) 2016 Eric Chapman
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ =end
27
+
1
28
  module WampClient
2
29
  module Check
3
30
 
@@ -1,3 +1,30 @@
1
+ =begin
2
+
3
+ Copyright (c) 2016 Eric Chapman
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ =end
27
+
1
28
  require 'websocket-eventmachine-client'
2
29
  require 'wamp_client/session'
3
30
  require 'wamp_client/transport'
@@ -53,7 +80,9 @@ module WampClient
53
80
  # @param options [Hash] The different options to pass to the connection
54
81
  # @option options [String] :uri The uri of the WAMP router to connect to
55
82
  # @option options [String] :realm The realm to connect to
56
- # @option options [String] :protocol The protocol (default if wamp.2.json)
83
+ # @option options [String,nil] :protocol The protocol (default if wamp.2.json)
84
+ # @option options [String,nil] :authid The id to authenticate with
85
+ # @option options [Array, nil] :authmethods The different auth methods that the client supports
57
86
  # @option options [Hash] :headers Custom headers to include during the connection
58
87
  # @option options [WampClient::Serializer::Base] :serializer The serializer to use (default is json)
59
88
  def initialize(options)
@@ -0,0 +1,68 @@
1
+ =begin
2
+
3
+ Copyright (c) 2016 Eric Chapman
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ =end
27
+
28
+ module WampClient
29
+ module Defer
30
+
31
+ class CallDefer
32
+ attr_accessor :request
33
+
34
+ @on_complete
35
+ def on_complete(&on_complete)
36
+ @on_complete = on_complete
37
+ end
38
+
39
+ @on_error
40
+ def on_error(&on_error)
41
+ @on_error = on_error
42
+ end
43
+
44
+ def succeed(result)
45
+ @on_complete.call(self, result) if @on_complete
46
+ end
47
+
48
+ def fail(error)
49
+ @on_error.call(self, error) if @on_error
50
+ end
51
+
52
+ end
53
+
54
+ class ProgressiveCallDefer < CallDefer
55
+
56
+ @on_progress
57
+ def on_progress(&on_progress)
58
+ @on_progress = on_progress
59
+ end
60
+
61
+ def progress(result)
62
+ @on_progress.call(self, result) if @on_progress
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+ end
@@ -1,3 +1,30 @@
1
+ =begin
2
+
3
+ Copyright (c) 2016 Eric Chapman
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ =end
27
+
1
28
  require 'wamp_client/check'
2
29
 
3
30
  # !!!!THIS FILE IS AUTOGENERATED. DO NOT HAND EDIT!!!!
@@ -1,3 +1,30 @@
1
+ =begin
2
+
3
+ Copyright (c) 2016 Eric Chapman
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ =end
27
+
1
28
  require 'json'
2
29
 
3
30
  module WampClient
@@ -1,3 +1,30 @@
1
+ =begin
2
+
3
+ Copyright (c) 2016 Eric Chapman
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ =end
27
+
1
28
  require 'wamp_client/transport'
2
29
  require 'wamp_client/message'
3
30
  require 'wamp_client/check'
@@ -22,7 +49,7 @@ module WampClient
22
49
  shared_registration: true,
23
50
  ##call_timeout: true,
24
51
  ##call_canceling: true,
25
- # progressive_call_results: true,
52
+ progressive_call_results: true,
26
53
  registration_revocation: true
27
54
  }
28
55
  },
@@ -48,8 +75,18 @@ module WampClient
48
75
  attr_accessor :args, :kwargs
49
76
 
50
77
  def initialize(args=nil, kwargs=nil)
51
- self.args = args
52
- self.kwargs = kwargs
78
+ self.args = args || []
79
+ self.kwargs = kwargs || {}
80
+ end
81
+ end
82
+
83
+ class CallError < Exception
84
+ attr_accessor :error, :args, :kwargs
85
+
86
+ def initialize(error, args=nil, kwargs=nil)
87
+ self.error = error
88
+ self.args = args || []
89
+ self.kwargs = kwargs || {}
53
90
  end
54
91
  end
55
92
 
@@ -119,7 +156,7 @@ module WampClient
119
156
  attr_accessor :id, :realm, :transport, :verbose, :options
120
157
 
121
158
  # Private attributes
122
- attr_accessor :_goodbye_sent, :_requests, :_subscriptions, :_registrations
159
+ attr_accessor :_goodbye_sent, :_requests, :_subscriptions, :_registrations, :_defers
123
160
 
124
161
  # Constructor
125
162
  # @param transport [WampClient::Transport::Base] The transport that the session will use
@@ -147,6 +184,7 @@ module WampClient
147
184
  # Init Subs and Regs in place
148
185
  self._subscriptions = {}
149
186
  self._registrations = {}
187
+ self._defers = {}
150
188
 
151
189
  # Setup Transport
152
190
  self.transport = transport
@@ -623,20 +661,69 @@ module WampClient
623
661
  begin
624
662
  value = h.call(args, kwargs, details)
625
663
 
626
- if value.nil?
627
- value = CallResult.new
628
- elsif not value.is_a?(CallResult)
629
- value = CallResult.new([value])
664
+ def send_error(request, error)
665
+ if error.nil?
666
+ error = CallError.new('wamp.error.runtime')
667
+ elsif not error.is_a?(CallError)
668
+ error = CallError.new('wamp.error.runtime', [error.to_s])
669
+ end
670
+
671
+ error_msg = WampClient::Message::Error.new(WampClient::Message::Types::INVOCATION, request, {}, error.error, error.args, error.kwargs)
672
+ self._send_message(error_msg)
673
+ end
674
+
675
+ def send_result(request, result, options={})
676
+ if result.nil?
677
+ result = CallResult.new
678
+ elsif result.is_a?(CallError)
679
+ # Do nothing
680
+ elsif not result.is_a?(CallResult)
681
+ result = CallResult.new([result])
682
+ end
683
+
684
+ if result.is_a?(CallError)
685
+ send_error(request, result)
686
+ else
687
+ yield_msg = WampClient::Message::Yield.new(request, options, result.args, result.kwargs)
688
+ self._send_message(yield_msg)
689
+ end
630
690
  end
631
691
 
632
- # TODO: Handle promise or future
692
+ # If a defer was returned, handle accordingly
693
+ if value.is_a? WampClient::Defer::CallDefer
694
+ value.request = request
695
+
696
+ # Store the defer
697
+ self._defers[request] = value
698
+
699
+ # On complete, send the result
700
+ value.on_complete do |defer, result|
701
+ send_result(defer.request, result)
702
+ self._defers.delete(defer.request)
703
+ end
704
+
705
+ # On error, send the error
706
+ value.on_error do |defer, error|
707
+ send_error(defer.request, error)
708
+ self._defers.delete(defer.request)
709
+ end
710
+
711
+ # For progressive, return the progress
712
+ if value.is_a? WampClient::Defer::ProgressiveCallDefer
713
+ value.on_progress do |defer, result|
714
+ send_result(defer.request, result, {progress: true})
715
+ end
716
+ end
717
+
718
+ # Else it was a normal response
719
+ else
720
+ send_result(request, value)
721
+ end
633
722
 
634
- yield_msg = WampClient::Message::Yield.new(request, {}, value.args, value.kwargs)
635
- self._send_message(yield_msg)
636
- rescue Exception => e
637
- error = WampClient::Message::Error.new(WampClient::Message::Types::INVOCATION, request, {}, 'wamp.error.runtime', [e.to_s])
638
- self._send_message(error)
723
+ rescue Exception => error
724
+ send_error(request, error)
639
725
  end
726
+
640
727
  end
641
728
  end
642
729
  end
@@ -1,3 +1,30 @@
1
+ =begin
2
+
3
+ Copyright (c) 2016 Eric Chapman
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ =end
27
+
1
28
  require 'wamp_client/serializer'
2
29
 
3
30
  module WampClient
@@ -1,3 +1,30 @@
1
+ =begin
2
+
3
+ Copyright (c) 2016 Eric Chapman
4
+
5
+ MIT License
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+ =end
27
+
1
28
  module WampClient
2
- VERSION = '0.0.1'
29
+ VERSION = '0.0.2'
3
30
  end
data/spec/session_spec.rb CHANGED
@@ -566,23 +566,43 @@ describe WampClient::Session do
566
566
  welcome = WampClient::Message::Welcome.new(1234, {})
567
567
  transport.receive_message(welcome.payload)
568
568
 
569
- # Register
570
- @response = 'response'
571
- @throw_error = false
569
+ # Register Response
572
570
  handler = lambda do |args, kwargs, details|
573
-
574
- raise 'error' if @throw_error
575
-
576
571
  @response
577
572
  end
578
-
579
573
  session.register('test.procedure', handler, {test: 1})
580
574
  request_id = session._requests[:register].keys.first
581
-
582
- # Generate server response
583
575
  registered = WampClient::Message::Registered.new(request_id, 3456)
584
576
  transport.receive_message(registered.payload)
585
577
 
578
+ # Defer Register
579
+ defer_handler = lambda do |args, kwargs, details|
580
+ @defer
581
+ end
582
+ session.register('test.defer.procedure', defer_handler)
583
+
584
+ request_id = session._requests[:register].keys.first
585
+ registered = WampClient::Message::Registered.new(request_id, 4567)
586
+ transport.receive_message(registered.payload)
587
+
588
+ # Register Error Response
589
+ handler = lambda do |args, kwargs, details|
590
+ raise 'error'
591
+ end
592
+ session.register('test.procedure.error', handler, {test: 1})
593
+ request_id = session._requests[:register].keys.first
594
+ registered = WampClient::Message::Registered.new(request_id, 5678)
595
+ transport.receive_message(registered.payload)
596
+
597
+ # Register Call Error Response
598
+ handler = lambda do |args, kwargs, details|
599
+ raise WampClient::CallError.new('test.error', ['error'])
600
+ end
601
+ session.register('test.procedure.call.error', handler, {test: 1})
602
+ request_id = session._requests[:register].keys.first
603
+ registered = WampClient::Message::Registered.new(request_id, 6789)
604
+ transport.receive_message(registered.payload)
605
+
586
606
  transport.messages = []
587
607
  end
588
608
 
@@ -620,7 +640,7 @@ describe WampClient::Session do
620
640
 
621
641
  end
622
642
 
623
- it 'call result response' do
643
+ it 'result response' do
624
644
 
625
645
  @response = WampClient::CallResult.new(['test'], {test:1})
626
646
 
@@ -638,15 +658,120 @@ describe WampClient::Session do
638
658
 
639
659
  end
640
660
 
641
- it 'call error response' do
661
+ it 'raise error response' do
662
+
663
+ # Generate server event
664
+ invocation = WampClient::Message::Invocation.new(7890, 5678, {test:1}, [2], {param: 'value'})
665
+ transport.receive_message(invocation.payload)
666
+
667
+ # Check and make sure yield message was sent
668
+ expect(transport.messages.count).to eq(1)
669
+ expect(transport.messages[0][0]).to eq(WampClient::Message::Types::ERROR)
670
+ expect(transport.messages[0][1]).to eq(WampClient::Message::Types::INVOCATION)
671
+ expect(transport.messages[0][2]).to eq(7890)
672
+ expect(transport.messages[0][3]).to eq({})
673
+ expect(transport.messages[0][4]).to eq('wamp.error.runtime')
674
+ expect(transport.messages[0][5]).to eq(['error'])
675
+
676
+ end
677
+
678
+ it 'raise call error response' do
679
+
680
+ # Generate server event
681
+ invocation = WampClient::Message::Invocation.new(7890, 6789, {test:1}, [2], {param: 'value'})
682
+ transport.receive_message(invocation.payload)
683
+
684
+ # Check and make sure yield message was sent
685
+ expect(transport.messages.count).to eq(1)
686
+ expect(transport.messages[0][0]).to eq(WampClient::Message::Types::ERROR)
687
+ expect(transport.messages[0][1]).to eq(WampClient::Message::Types::INVOCATION)
688
+ expect(transport.messages[0][2]).to eq(7890)
689
+ expect(transport.messages[0][3]).to eq({})
690
+ expect(transport.messages[0][4]).to eq('test.error')
691
+ expect(transport.messages[0][5]).to eq(['error'])
692
+
693
+ end
694
+
695
+ it 'return error response' do
642
696
 
643
- @throw_error = true
697
+ @response = WampClient::CallError.new('wamp.error.runtime', ['error'], {error: true})
644
698
 
645
699
  # Generate server event
646
700
  invocation = WampClient::Message::Invocation.new(7890, 3456, {test:1}, [2], {param: 'value'})
647
701
  transport.receive_message(invocation.payload)
648
702
 
649
- @throw_error = false
703
+ # Check and make sure yield message was sent
704
+ expect(transport.messages.count).to eq(1)
705
+ expect(transport.messages[0][0]).to eq(WampClient::Message::Types::ERROR)
706
+ expect(transport.messages[0][1]).to eq(WampClient::Message::Types::INVOCATION)
707
+ expect(transport.messages[0][2]).to eq(7890)
708
+ expect(transport.messages[0][3]).to eq({})
709
+ expect(transport.messages[0][4]).to eq('wamp.error.runtime')
710
+ expect(transport.messages[0][5]).to eq(['error'])
711
+ expect(transport.messages[0][6]).to eq({error: true})
712
+
713
+ end
714
+
715
+ it 'defer normal response' do
716
+
717
+ @response = WampClient::CallResult.new(['test'], {test:1})
718
+
719
+ @defer = WampClient::Defer::CallDefer.new
720
+
721
+ # Generate server event
722
+ invocation = WampClient::Message::Invocation.new(7890, 4567, {test:1}, [2], {param: 'value'})
723
+ transport.receive_message(invocation.payload)
724
+
725
+ expect(transport.messages.count).to eq(0)
726
+
727
+ @defer.succeed(@response)
728
+
729
+ # Check and make sure yield message was sent
730
+ expect(transport.messages.count).to eq(1)
731
+ expect(transport.messages[0][0]).to eq(WampClient::Message::Types::YIELD)
732
+ expect(transport.messages[0][1]).to eq(7890)
733
+ expect(transport.messages[0][2]).to eq({})
734
+ expect(transport.messages[0][3]).to eq(['test'])
735
+ expect(transport.messages[0][4]).to eq({test:1})
736
+
737
+ end
738
+
739
+ it 'defer error normal response' do
740
+
741
+ @defer = WampClient::Defer::CallDefer.new
742
+
743
+ # Generate server event
744
+ invocation = WampClient::Message::Invocation.new(7890, 4567, {test:1}, [2], {param: 'value'})
745
+ transport.receive_message(invocation.payload)
746
+
747
+ expect(transport.messages.count).to eq(0)
748
+
749
+ @defer.fail('error')
750
+
751
+ # Check and make sure yield message was sent
752
+ expect(transport.messages.count).to eq(1)
753
+ expect(transport.messages[0][0]).to eq(WampClient::Message::Types::ERROR)
754
+ expect(transport.messages[0][1]).to eq(WampClient::Message::Types::INVOCATION)
755
+ expect(transport.messages[0][2]).to eq(7890)
756
+ expect(transport.messages[0][3]).to eq({})
757
+ expect(transport.messages[0][4]).to eq('wamp.error.runtime')
758
+ expect(transport.messages[0][5]).to eq(['error'])
759
+
760
+ end
761
+
762
+ it 'defer error object response' do
763
+
764
+ @response = WampClient::CallError.new('wamp.error.runtime', ['error'], {error: true})
765
+
766
+ @defer = WampClient::Defer::CallDefer.new
767
+
768
+ # Generate server event
769
+ invocation = WampClient::Message::Invocation.new(7890, 4567, {test:1}, [2], {param: 'value'})
770
+ transport.receive_message(invocation.payload)
771
+
772
+ expect(transport.messages.count).to eq(0)
773
+
774
+ @defer.fail(@response)
650
775
 
651
776
  # Check and make sure yield message was sent
652
777
  expect(transport.messages.count).to eq(1)
@@ -656,6 +781,7 @@ describe WampClient::Session do
656
781
  expect(transport.messages[0][3]).to eq({})
657
782
  expect(transport.messages[0][4]).to eq('wamp.error.runtime')
658
783
  expect(transport.messages[0][5]).to eq(['error'])
784
+ expect(transport.messages[0][6]).to eq({error: true})
659
785
 
660
786
  end
661
787
  end
@@ -936,6 +1062,106 @@ describe WampClient::Session do
936
1062
 
937
1063
  end
938
1064
 
1065
+ it 'callee result support' do
1066
+
1067
+ # Defer Register
1068
+ @defer = WampClient::Defer::ProgressiveCallDefer.new
1069
+ defer_handler = lambda do |args, kwargs, details|
1070
+ @defer
1071
+ end
1072
+ session.register('test.defer.procedure', defer_handler)
1073
+
1074
+ request_id = session._requests[:register].keys.first
1075
+ registered = WampClient::Message::Registered.new(request_id, 4567)
1076
+ transport.receive_message(registered.payload)
1077
+
1078
+ transport.messages = []
1079
+
1080
+ # Generate server event
1081
+ invocation = WampClient::Message::Invocation.new(7890, 4567, {test:1}, [2], {param: 'value'})
1082
+ transport.receive_message(invocation.payload)
1083
+
1084
+ expect(transport.messages.count).to eq(0)
1085
+ expect(session._defers.count).to eq(1)
1086
+
1087
+ @defer.progress(WampClient::CallResult.new(['test1']))
1088
+ expect(session._defers.count).to eq(1)
1089
+ @defer.progress(WampClient::CallResult.new(['test2']))
1090
+ expect(session._defers.count).to eq(1)
1091
+ @defer.succeed(WampClient::CallResult.new(['test3']))
1092
+ expect(session._defers.count).to eq(0)
1093
+
1094
+ expect(transport.messages.count).to eq(3)
1095
+
1096
+ # Check and make sure yield message was sent
1097
+ expect(transport.messages[0][0]).to eq(WampClient::Message::Types::YIELD)
1098
+ expect(transport.messages[0][1]).to eq(7890)
1099
+ expect(transport.messages[0][2]).to eq({progress: true})
1100
+ expect(transport.messages[0][3]).to eq(['test1'])
1101
+
1102
+ expect(transport.messages[1][0]).to eq(WampClient::Message::Types::YIELD)
1103
+ expect(transport.messages[1][1]).to eq(7890)
1104
+ expect(transport.messages[1][2]).to eq({progress: true})
1105
+ expect(transport.messages[1][3]).to eq(['test2'])
1106
+
1107
+ expect(transport.messages.count).to eq(3)
1108
+ expect(transport.messages[2][0]).to eq(WampClient::Message::Types::YIELD)
1109
+ expect(transport.messages[2][1]).to eq(7890)
1110
+ expect(transport.messages[2][2]).to eq({})
1111
+ expect(transport.messages[2][3]).to eq(['test3'])
1112
+
1113
+ end
1114
+
1115
+ it 'callee error support' do
1116
+
1117
+ # Defer Register
1118
+ @defer = WampClient::Defer::ProgressiveCallDefer.new
1119
+ defer_handler = lambda do |args, kwargs, details|
1120
+ @defer
1121
+ end
1122
+ session.register('test.defer.procedure', defer_handler)
1123
+
1124
+ request_id = session._requests[:register].keys.first
1125
+ registered = WampClient::Message::Registered.new(request_id, 4567)
1126
+ transport.receive_message(registered.payload)
1127
+
1128
+ transport.messages = []
1129
+
1130
+ # Generate server event
1131
+ invocation = WampClient::Message::Invocation.new(7890, 4567, {test:1}, [2], {param: 'value'})
1132
+ transport.receive_message(invocation.payload)
1133
+
1134
+ expect(transport.messages.count).to eq(0)
1135
+ expect(session._defers.count).to eq(1)
1136
+
1137
+ @defer.progress(WampClient::CallResult.new(['test1']))
1138
+ expect(session._defers.count).to eq(1)
1139
+ @defer.progress(WampClient::CallResult.new(['test2']))
1140
+ expect(session._defers.count).to eq(1)
1141
+ @defer.fail(WampClient::CallError.new('test.error'))
1142
+ expect(session._defers.count).to eq(0)
1143
+
1144
+ expect(transport.messages.count).to eq(3)
1145
+
1146
+ # Check and make sure yield message was sent
1147
+ expect(transport.messages[0][0]).to eq(WampClient::Message::Types::YIELD)
1148
+ expect(transport.messages[0][1]).to eq(7890)
1149
+ expect(transport.messages[0][2]).to eq({progress: true})
1150
+ expect(transport.messages[0][3]).to eq(['test1'])
1151
+
1152
+ expect(transport.messages[1][0]).to eq(WampClient::Message::Types::YIELD)
1153
+ expect(transport.messages[1][1]).to eq(7890)
1154
+ expect(transport.messages[1][2]).to eq({progress: true})
1155
+ expect(transport.messages[1][3]).to eq(['test2'])
1156
+
1157
+ expect(transport.messages[2][0]).to eq(WampClient::Message::Types::ERROR)
1158
+ expect(transport.messages[2][1]).to eq(WampClient::Message::Types::INVOCATION)
1159
+ expect(transport.messages[2][2]).to eq(7890)
1160
+ expect(transport.messages[2][3]).to eq({})
1161
+ expect(transport.messages[2][4]).to eq('test.error')
1162
+
1163
+ end
1164
+
939
1165
  end
940
1166
 
941
1167
  describe 'auth' do
data/spec/spec_helper.rb CHANGED
@@ -3,8 +3,10 @@ SimpleCov.start
3
3
 
4
4
  require_relative '../lib/wamp_client'
5
5
 
6
- require 'codecov'
7
- SimpleCov.formatter = SimpleCov::Formatter::Codecov
6
+ if ENV['CODECOV_TOKEN']
7
+ require 'codecov'
8
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
9
+ end
8
10
 
9
11
  require 'wamp_client'
10
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wamp_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Chapman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-09 00:00:00.000000000 Z
11
+ date: 2016-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,6 +125,7 @@ files:
125
125
  - lib/wamp_client/auth.rb
126
126
  - lib/wamp_client/check.rb
127
127
  - lib/wamp_client/connection.rb
128
+ - lib/wamp_client/defer.rb
128
129
  - lib/wamp_client/message.rb
129
130
  - lib/wamp_client/serializer.rb
130
131
  - lib/wamp_client/session.rb