wamp_client 0.1.3 → 0.1.4

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: cc93c0d05bcbfb3733b1f40ce71f6c318467d6fd
4
- data.tar.gz: d5219fd104bc66d1a88f7b388f69eee2c8b4587d
3
+ metadata.gz: 35fec0c02c367a33b50ea31953fbd8dc6c27e59e
4
+ data.tar.gz: c8d09d7b4b8982268f4f761b8b308d43aecca67b
5
5
  SHA512:
6
- metadata.gz: f1033d200d29053a18f5793cc7d72d0017777c5380dc304f6986f344deb4fb9bbdee9e1e812f68c269e26c075abbdc94b5bf23b00cd0bf2aba6d966fddc4f181
7
- data.tar.gz: 7eee35514938b9b2e814c989dc10132650a3bf5755ec19504a9b1e5edbaa2dd2631ababf8323be8f6199fbed72d77a7120449759a5b50b5cb3129c3bf7d13fc1
6
+ metadata.gz: b7a400d331ea4fcf219543f6652be2c571a8aa11ec2dcd460283b5b4b2a8ff4b577a08d9968260a17e9be38d634f61f92de8dc4c4a2ad5379af6557d0245b5e7
7
+ data.tar.gz: 040ced48fc89779307a76a277bb491d993955b6b04d18054229806b05a8fecc2a5cc09032b75cbb8dd0c5b6c21d0967b56850d785add51d013db7e4a0ab10d6b
data/README.md CHANGED
@@ -10,6 +10,8 @@ Please use [wamp_rails](https://github.com/ericchapman/ruby_wamp_rails) to integ
10
10
 
11
11
  ## Revision History
12
12
 
13
+ - v0.1.4:
14
+ - Wrapped defer logic inside of yield method for cleanliness
13
15
  - v0.1.3:
14
16
  - Improved logging
15
17
  - Minor code cleanup
@@ -161,7 +161,7 @@ module Wamp
161
161
  end
162
162
 
163
163
  class Session
164
- include Wamp::Client::Check
164
+ include Check
165
165
 
166
166
  # on_join callback is called when the session joins the router. It has the following parameters
167
167
  # @param details [Hash] Object containing information about the joined session
@@ -208,7 +208,7 @@ module Wamp
208
208
  attr_accessor :_goodbye_sent, :_requests, :_subscriptions, :_registrations, :_defers
209
209
 
210
210
  # Constructor
211
- # @param transport [Wamp::Client::Transport::Base] The transport that the session will use
211
+ # @param transport [Transport::Base] The transport that the session will use
212
212
  # @param options [Hash] Hash containing different session options
213
213
  # @option options [String] :authid The authentication ID
214
214
  # @option options [Array] :authmethods Different auth methods that this client supports
@@ -268,12 +268,12 @@ module Wamp
268
268
 
269
269
  details = {}
270
270
  details[:roles] = WAMP_FEATURES
271
- details[:agent] = "Ruby-Wamp::Client-#{Wamp::Client::VERSION}"
271
+ details[:agent] = "Ruby-Wamp::Client-#{VERSION}"
272
272
  details[:authid] = self.options[:authid] if self.options[:authid]
273
273
  details[:authmethods] = self.options[:authmethods] if self.options[:authmethods]
274
274
 
275
275
  # Send Hello message
276
- hello = Wamp::Client::Message::Hello.new(realm, details)
276
+ hello = Message::Hello.new(realm, details)
277
277
  self._send_message(hello)
278
278
  end
279
279
 
@@ -291,7 +291,7 @@ module Wamp
291
291
  details[:message] = message
292
292
 
293
293
  # Send Goodbye message
294
- goodbye = Wamp::Client::Message::Goodbye.new(details, reason)
294
+ goodbye = Message::Goodbye.new(details, reason)
295
295
  self._send_message(goodbye)
296
296
  self._goodbye_sent = true
297
297
  end
@@ -302,7 +302,7 @@ module Wamp
302
302
  end
303
303
 
304
304
  # Converts and error message to a hash
305
- # @param msg [Wamp::Client::Message::Error]
305
+ # @param msg [Message::Error]
306
306
  def _error_to_hash(msg)
307
307
  {
308
308
  error: msg.error,
@@ -312,7 +312,7 @@ module Wamp
312
312
  end
313
313
 
314
314
  # Sends a message
315
- # @param msg [Wamp::Client::Message::Base]
315
+ # @param msg [Message::Base]
316
316
  def _send_message(msg)
317
317
  # Log the message
318
318
  logger.debug("#{self.class.name} TX: #{msg.to_s}")
@@ -329,7 +329,7 @@ module Wamp
329
329
  logger.debug("#{self.class.name} RX(raw): #{msg.to_s}")
330
330
 
331
331
  # Parse the WAMP message
332
- message = Wamp::Client::Message.parse(msg)
332
+ message = Message.parse(msg)
333
333
 
334
334
  # Print the parsed WAMP message
335
335
  logger.debug("#{self.class.name} RX: #{message.to_s}")
@@ -338,7 +338,7 @@ module Wamp
338
338
  if self.id.nil?
339
339
 
340
340
  # Parse the welcome message
341
- if message.is_a? Wamp::Client::Message::Welcome
341
+ if message.is_a? Message::Welcome
342
342
  # Get the session ID
343
343
  self.id = message.session
344
344
 
@@ -347,7 +347,7 @@ module Wamp
347
347
 
348
348
  # Call the callback if it is set
349
349
  @on_join.call(message.details) unless @on_join.nil?
350
- elsif message.is_a? Wamp::Client::Message::Challenge
350
+ elsif message.is_a? Message::Challenge
351
351
  # Log challenge received
352
352
  logger.debug("#{self.class.name} auth challenge '#{message.authmethod}', extra: #{message.extra}")
353
353
 
@@ -362,10 +362,10 @@ module Wamp
362
362
  signature ||= ''
363
363
  extra ||= {}
364
364
 
365
- authenticate = Wamp::Client::Message::Authenticate.new(signature, extra)
365
+ authenticate = Message::Authenticate.new(signature, extra)
366
366
  self._send_message(authenticate)
367
367
 
368
- elsif message.is_a? Wamp::Client::Message::Abort
368
+ elsif message.is_a? Message::Abort
369
369
  # Log leaving the session
370
370
  logger.info("#{self.class.name} left session '#{message.reason}'")
371
371
 
@@ -377,11 +377,11 @@ module Wamp
377
377
  else
378
378
 
379
379
  # If goodbye, close the session
380
- if message.is_a? Wamp::Client::Message::Goodbye
380
+ if message.is_a? Message::Goodbye
381
381
 
382
382
  # If we didn't send the goodbye, respond
383
383
  unless self._goodbye_sent
384
- goodbye = Wamp::Client::Message::Goodbye.new({}, 'wamp.error.goodbye_and_out')
384
+ goodbye = Message::Goodbye.new({}, 'wamp.error.goodbye_and_out')
385
385
  self._send_message(goodbye)
386
386
  end
387
387
 
@@ -428,12 +428,12 @@ module Wamp
428
428
  self._requests[:subscribe][request] = {t: topic, h: handler, o: options, c: callback}
429
429
 
430
430
  # Send the message
431
- subscribe = Wamp::Client::Message::Subscribe.new(request, options, topic)
431
+ subscribe = Message::Subscribe.new(request, options, topic)
432
432
  self._send_message(subscribe)
433
433
  end
434
434
 
435
435
  # Processes the response to a subscribe request
436
- # @param msg [Wamp::Client::Message::Subscribed] The response from the subscribe
436
+ # @param msg [Message::Subscribed] The response from the subscribe
437
437
  def _process_SUBSCRIBED(msg)
438
438
 
439
439
  # Remove the pending subscription, add it to the registered ones, and inform the caller
@@ -454,7 +454,7 @@ module Wamp
454
454
  end
455
455
 
456
456
  # Processes an error from a request
457
- # @param msg [Wamp::Client::Message::Error] The response from the subscribe
457
+ # @param msg [Message::Error] The response from the subscribe
458
458
  def _process_SUBSCRIBE_error(msg)
459
459
 
460
460
  # Remove the pending subscription and inform the caller of the failure
@@ -473,7 +473,7 @@ module Wamp
473
473
  end
474
474
 
475
475
  # Processes and event from the broker
476
- # @param msg [Wamp::Client::Message::Event] An event that was published
476
+ # @param msg [Message::Event] An event that was published
477
477
  def _process_EVENT(msg)
478
478
 
479
479
  args = msg.publish_arguments || []
@@ -510,12 +510,12 @@ module Wamp
510
510
  self._requests[:unsubscribe][request] = { s: subscription, c: callback }
511
511
 
512
512
  # Send the message
513
- unsubscribe = Wamp::Client::Message::Unsubscribe.new(request, subscription.id)
513
+ unsubscribe = Message::Unsubscribe.new(request, subscription.id)
514
514
  self._send_message(unsubscribe)
515
515
  end
516
516
 
517
517
  # Processes the response to a unsubscribe request
518
- # @param msg [Wamp::Client::Message::Unsubscribed] The response from the unsubscribe
518
+ # @param msg [Message::Unsubscribed] The response from the unsubscribe
519
519
  def _process_UNSUBSCRIBED(msg)
520
520
 
521
521
  # Remove the pending unsubscription, add it to the registered ones, and inform the caller
@@ -537,7 +537,7 @@ module Wamp
537
537
 
538
538
 
539
539
  # Processes an error from a request
540
- # @param msg [Wamp::Client::Message::Error] The response from the subscribe
540
+ # @param msg [Message::Error] The response from the subscribe
541
541
  def _process_UNSUBSCRIBE_error(msg)
542
542
 
543
543
  # Remove the pending subscription and inform the caller of the failure
@@ -580,12 +580,12 @@ module Wamp
580
580
  self._requests[:publish][request] = {t: topic, a: args, k: kwargs, o: options, c: callback} if options[:acknowledge]
581
581
 
582
582
  # Send the message
583
- publish = Wamp::Client::Message::Publish.new(request, options, topic, args, kwargs)
583
+ publish = Message::Publish.new(request, options, topic, args, kwargs)
584
584
  self._send_message(publish)
585
585
  end
586
586
 
587
587
  # Processes the response to a publish request
588
- # @param msg [Wamp::Client::Message::Published] The response from the subscribe
588
+ # @param msg [Message::Published] The response from the subscribe
589
589
  def _process_PUBLISHED(msg)
590
590
 
591
591
  # Remove the pending publish and alert the callback
@@ -605,7 +605,7 @@ module Wamp
605
605
  end
606
606
 
607
607
  # Processes an error from a publish request
608
- # @param msg [Wamp::Client::Message::Error] The response from the subscribe
608
+ # @param msg [Message::Error] The response from the subscribe
609
609
  def _process_PUBLISH_error(msg)
610
610
 
611
611
  # Remove the pending publish and inform the caller of the failure
@@ -648,12 +648,12 @@ module Wamp
648
648
  self._requests[:register][request] = {p: procedure, h: handler, i: interrupt, o: options, c: callback}
649
649
 
650
650
  # Send the message
651
- register = Wamp::Client::Message::Register.new(request, options, procedure)
651
+ register = Message::Register.new(request, options, procedure)
652
652
  self._send_message(register)
653
653
  end
654
654
 
655
655
  # Processes the response to a register request
656
- # @param msg [Wamp::Client::Message::Registered] The response from the subscribe
656
+ # @param msg [Message::Registered] The response from the subscribe
657
657
  def _process_REGISTERED(msg)
658
658
 
659
659
  # Remove the pending subscription, add it to the registered ones, and inform the caller
@@ -674,7 +674,7 @@ module Wamp
674
674
  end
675
675
 
676
676
  # Processes an error from a request
677
- # @param msg [Wamp::Client::Message::Error] The response from the register
677
+ # @param msg [Message::Error] The response from the register
678
678
  def _process_REGISTER_error(msg)
679
679
 
680
680
  # Remove the pending registration and inform the caller of the failure
@@ -708,7 +708,7 @@ module Wamp
708
708
  error = CallError.new('wamp.error.runtime', [error.to_s], { backtrace: backtrace })
709
709
  end
710
710
 
711
- error_msg = Wamp::Client::Message::Error.new(Wamp::Client::Message::Types::INVOCATION, request, {}, error.error, error.args, error.kwargs)
711
+ error_msg = Message::Error.new(Message::Types::INVOCATION, request, {}, error.error, error.args, error.kwargs)
712
712
  self._send_message(error_msg)
713
713
  end
714
714
 
@@ -722,6 +722,7 @@ module Wamp
722
722
  return
723
723
  end
724
724
 
725
+ # Wrap the result accordingly
725
726
  if result.nil?
726
727
  result = CallResult.new
727
728
  elsif result.is_a?(CallError)
@@ -730,17 +731,23 @@ module Wamp
730
731
  result = CallResult.new([result])
731
732
  end
732
733
 
734
+ # Send either the error or the response
733
735
  if result.is_a?(CallError)
734
736
  self._send_INVOCATION_error(request, result)
735
737
  else
736
- yield_msg = Wamp::Client::Message::Yield.new(request, options, result.args, result.kwargs)
738
+ yield_msg = Message::Yield.new(request, options, result.args, result.kwargs)
737
739
  self._send_message(yield_msg)
738
740
  end
741
+
742
+ # Remove the defer if this was not a progress update
743
+ if check_defer and options[:progress] == nil
744
+ self._defers.delete(request)
745
+ end
739
746
  end
740
747
 
741
748
 
742
749
  # Processes and event from the broker
743
- # @param msg [Wamp::Client::Message::Invocation] An procedure that was called
750
+ # @param msg [Message::Invocation] An procedure that was called
744
751
  def _process_INVOCATION(msg)
745
752
 
746
753
  request = msg.request
@@ -759,7 +766,7 @@ module Wamp
759
766
  value = h.call(args, kwargs, details)
760
767
 
761
768
  # If a defer was returned, handle accordingly
762
- if value.is_a? Wamp::Client::Defer::CallDefer
769
+ if value.is_a? Defer::CallDefer
763
770
  value.request = request
764
771
  value.registration = msg.registered_registration
765
772
 
@@ -769,23 +776,22 @@ module Wamp
769
776
  # On complete, send the result
770
777
  value.on_complete do |defer, result|
771
778
  self.yield(defer.request, result, {}, true)
772
- self._defers.delete(defer.request)
773
779
  end
774
780
 
775
781
  # On error, send the error
776
782
  value.on_error do |defer, error|
777
- self._send_INVOCATION_error(defer.request, error, true)
778
- self._defers.delete(defer.request)
783
+ error = CallError.new("wamp.error.runtime", [error]) if error.is_a?(String)
784
+ self.yield(defer.request, error, {}, true)
779
785
  end
780
786
 
781
787
  # For progressive, return the progress
782
- if value.is_a? Wamp::Client::Defer::ProgressiveCallDefer
788
+ if value.is_a? Defer::ProgressiveCallDefer
783
789
  value.on_progress do |defer, result|
784
790
  self.yield(defer.request, result, {progress: true}, true)
785
791
  end
786
792
  end
787
793
 
788
- # Else it was a normal response
794
+ # Else it was a normal response
789
795
  else
790
796
  self.yield(request, value)
791
797
  end
@@ -799,7 +805,7 @@ module Wamp
799
805
  end
800
806
 
801
807
  # Processes the interrupt
802
- # @param msg [Wamp::Client::Message::Interrupt] An interrupt to a procedure
808
+ # @param msg [Message::Interrupt] An interrupt to a procedure
803
809
  def _process_INTERRUPT(msg)
804
810
 
805
811
  request = msg.invocation_request
@@ -851,12 +857,12 @@ module Wamp
851
857
  self._requests[:unregister][request] = { r: registration, c: callback }
852
858
 
853
859
  # Send the message
854
- unregister = Wamp::Client::Message::Unregister.new(request, registration.id)
860
+ unregister = Message::Unregister.new(request, registration.id)
855
861
  self._send_message(unregister)
856
862
  end
857
863
 
858
864
  # Processes the response to a unregister request
859
- # @param msg [Wamp::Client::Message::Unregistered] The response from the unsubscribe
865
+ # @param msg [Message::Unregistered] The response from the unsubscribe
860
866
  def _process_UNREGISTERED(msg)
861
867
 
862
868
  # Remove the pending unregistration, add it to the registered ones, and inform the caller
@@ -877,7 +883,7 @@ module Wamp
877
883
  end
878
884
 
879
885
  # Processes an error from a request
880
- # @param msg [Wamp::Client::Message::Error] The response from the subscribe
886
+ # @param msg [Message::Error] The response from the subscribe
881
887
  def _process_UNREGISTER_error(msg)
882
888
 
883
889
  # Remove the pending subscription and inform the caller of the failure
@@ -921,7 +927,7 @@ module Wamp
921
927
  self._requests[:call][request] = {p: procedure, a: args, k: kwargs, o: options, c: callback}
922
928
 
923
929
  # Send the message
924
- msg = Wamp::Client::Message::Call.new(request, options, procedure, args, kwargs)
930
+ msg = Message::Call.new(request, options, procedure, args, kwargs)
925
931
  self._send_message(msg)
926
932
 
927
933
  call = Call.new(self, request)
@@ -940,7 +946,7 @@ module Wamp
940
946
  end
941
947
 
942
948
  # Processes the response to a publish request
943
- # @param msg [Wamp::Client::Message::Result] The response from the call
949
+ # @param msg [Message::Result] The response from the call
944
950
  def _process_RESULT(msg)
945
951
 
946
952
  details = msg.details || {}
@@ -962,7 +968,7 @@ module Wamp
962
968
  end
963
969
 
964
970
  # Processes an error from a call request
965
- # @param msg [Wamp::Client::Message::Error] The response from the call
971
+ # @param msg [Message::Error] The response from the call
966
972
  def _process_CALL_error(msg)
967
973
 
968
974
  # Remove the pending publish and inform the caller of the failure
@@ -995,7 +1001,7 @@ module Wamp
995
1001
  self.class.check_nil('call', call, false)
996
1002
 
997
1003
  # Send the message
998
- cancel = Wamp::Client::Message::Cancel.new(call.id, { mode: mode })
1004
+ cancel = Message::Cancel.new(call.id, { mode: mode })
999
1005
  self._send_message(cancel)
1000
1006
  end
1001
1007
 
@@ -27,6 +27,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
27
 
28
28
  module Wamp
29
29
  module Client
30
- VERSION = '0.1.3'
30
+ VERSION = '0.1.4'
31
31
  end
32
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wamp_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Chapman