class Stargate::Client::Protocol
Constants
- DEFAULT_TIMEOUT
- UnsupportedProtocolError
Attributes
Public: Codec
used to serialize/deserialize payload.
Public: Transport configuration.
Public: URL without credentials part.
Public: Remote URL of the endpoint.
Public Class Methods
Public: Finds implementation for given protocol.
Returns transport if found. Raises UnsupportedProtocolError
if not found.
# File lib/stargate/client/protocol.rb, line 27 def self.[](protocol) transports[protocol.downcase] or raise UnsupportedProtocolError, "Unsupported protocol: #{protocol}" end
Public: Constructor.
# File lib/stargate/client/protocol.rb, line 44 def initialize(codec, uri) @codec = codec @uri = uri @safe_uri = uri.dup.tap { |safe_uri| safe_uri.user, safe_uri.password = nil, nil } @options = default_options.merge(parse_options_from_uri_fragment) @unmarshaller = Unmarshaller.new end
Public: Registers new implementation for given protocols.
# File lib/stargate/client/protocol.rb, line 19 def self.register(protocols, transport) protocols.each { |protocol| transports[protocol] = transport } end
Public: List of registered transports (protocol implementations).
# File lib/stargate/client/protocol.rb, line 14 def self.transports @@transports end
Public Instance Methods
Public: Shall execute class method with given arguments. Executes method remotely of course.
# File lib/stargate/client/protocol.rb, line 58 def call(klass, method, *args) raise NotImplementedError end
Public: Shall load all definitions from remote server.
# File lib/stargate/client/protocol.rb, line 53 def fetch_definitions raise NotImplementedError end
Protected Instance Methods
# File lib/stargate/client/protocol.rb, line 64 def default_options { timeout: DEFAULT_TIMEOUT } end
Internal: Parses options from URI fragment. Example http+json://example.com/v1#timeout=0.3
Returns hash with options.
# File lib/stargate/client/protocol.rb, line 81 def parse_options_from_uri_fragment uri.fragment.to_s.split(';').inject({}) do |options, entry| k, v = entry.split('=') options[k.to_sym] = v options end end
Internal: A helper to unpack remote definitions.
# File lib/stargate/client/protocol.rb, line 74 def unpack_definitions(definitions) definitions.map { |metadata| ::Stargate::Metadata.from_hash(metadata) } end
Internal: A helper to unpack loaded data.
# File lib/stargate/client/protocol.rb, line 69 def unpack_payload(data) @unmarshaller.unmarshal(data) end