# class MCollective::RPC::Request

Simple class to manage compliant requests for MCollective::RPC agents

### Attributes

action[RW]
agent[RW]
caller[RW]
data[RW]
ddl[RW]
sender[RW]
time[RW]
uniqid[RW]

### Public Class Methods

new(msg, ddl) click to toggle source

    # File lib/mcollective/rpc/request.rb, line 7
    def initialize(msg, ddl)
      @time = msg[:msgtime]
      @action = msg[:body][:action]
      @data = msg[:body][:data]
      @sender = msg[:senderid]
      @agent = msg[:body][:agent]
      @uniqid = msg[:requestid]
      @caller = msg[:callerid] || "unknown"
      @ddl = ddl
    end

### Public Instance Methods

[](key) click to toggle source

If data is a hash, gives easy access to its members, else returns nil

    # File lib/mcollective/rpc/request.rb, line 34
    def [](key)
      return nil unless @data.is_a?(Hash)
      return @data[key]
    end

fetch(key, default) click to toggle source

    # File lib/mcollective/rpc/request.rb, line 39
    def fetch(key, default)
      return nil unless @data.is_a?(Hash)
      return @data.fetch(key, default)
    end

include?(key) click to toggle source

If data is a hash, quick helper to get access to it’s include? method else returns false

    # File lib/mcollective/rpc/request.rb, line 20
    def include?(key)
      return false unless @data.is_a?(Hash)
      return @data.include?(key)
    end

should_respond?() click to toggle source

If no :process_results is specified always respond else respond based on the supplied property

    # File lib/mcollective/rpc/request.rb, line 27
    def should_respond?
      return @data[:process_results] if @data.include?(:process_results)

      return true
    end

to_hash() click to toggle source

    # File lib/mcollective/rpc/request.rb, line 44
    def to_hash
      return {:agent => @agent,
              :action => @action,
              :data => @data}
    end

to_json() click to toggle source

    # File lib/mcollective/rpc/request.rb, line 55
    def to_json
      to_hash.merge!({:sender   => @sender,
                      :callerid => @callerid,
                      :uniqid   => @uniqid}).to_json
    end

validate!() click to toggle source

Validate the request against the DDL

    # File lib/mcollective/rpc/request.rb, line 51
    def validate!
      @ddl.validate_rpc_request(@action, @data)
    end