internal void AddSegment(IRestRequest request) { if (_parent != null && _parent.Index != -1) // don't add a segemnt for the root element { _parent.AddSegment(request); } request.AddUrlSegment(Index.ToString(), _name); }
public RestRequest BuildRequest(InvokeMemberBinder binder, object[] args) { Debug.Assert(binder.IsVerb()); // total number of segments is the number or parts of the call chain not including the root // example: proxy.location.geo.get() has two url segments - the verb doesn't count // Index is zero based so add one string template = CreateUrlSegmentTemplate(_proxy.Index + 1); var request = new RestRequest(template); request.RequestFormat = DataFormat.Json; // we only talk json request.AddHeader("Accept", "application/json, text/json, text/x-json, text/javascript"); // fill in the url segments with the names of each call chain member _proxy.AddSegment(request); // this recurses up the instance chain int unnamedArgCount = binder.UnnamedArgCount(); // all named arguments are added as parameters for (int i = 0; i < binder.CallInfo.ArgumentNames.Count; i++) { var arg = args[i + unnamedArgCount]; if (arg is IDictionary <string, object> ) // if the arg is a dictionary, add each item as a parameter key value pair { request.AddDictionary((IDictionary <string, object>)arg); } else { request.AddParameter(binder.CallInfo.ArgumentNames[i].TrimStart(_proxy.KeywordEscapeCharacter), arg); } } // all unnamed args get added to the request body for (int i = 0; i < unnamedArgCount; i++) { request.AddBody(args[i]); } return(request); }