lib/transport/messages.rb in servicy-0.0.3 vs lib/transport/messages.rb in servicy-0.0.5

- old
+ new

@@ -13,11 +13,12 @@ # class methods {#registration}, {#query}, etc. def initialize(stuff) if stuff.is_a?(Hash) @struct = stuff else - @struct = JSON.parse(stuff) + # TODO: should this be a formatter that I can swap out? + @struct = JSON.parse(stuff || stuff.to_s) end end def method_missing(name, *args, &block) return struct[name] if struct.keys.include?(name) @@ -112,9 +113,28 @@ # @param [Hash,nil] stats The stats to report, if any. def self.statistics(stats=nil) new({ message: "stats", stats: stats + }) + end + + # Make a remote API call. + # @param [String] method The method to call on the remote implementor. + # @param [Hash{String => Object}] args The arguments to pass to the method. + # These are expected to be pre-formatted by an appropriate Formatter + def self.api(method, args) + new({ + message: 'api', + method_name: method, + args: args + }) + end + + def self.api_response(result) + new({ + message: 'api_response', + result: result }) end # Allow comparing of messages. This doesn't make for useful sorting, at # the moment, but does make it easy to know if two things are saying the