public Dictionary <string, string> GetParams() { var result = new Dictionary <string, string>(); if (AuthMethod == AuthMethod.Basic) { result["key"] = AuthValue; } else { result["accessToken"] = AuthValue; } result["v"] = Defaults.ProtocolVersion; result["lib"] = Defaults.LibraryVersion; //Url encode all the params at the time of creating the query string result["format"] = UseBinaryProtocol ? "msgpack" : "json"; result["echo"] = EchoMessages.ToString().ToLower(); if (ConnectionKey.IsNotEmpty()) { result["resume"] = ConnectionKey; if (ConnectionSerial.HasValue) { result["connection_serial"] = ConnectionSerial.Value.ToString(); } } else if (RecoverValue.IsNotEmpty()) { var pattern = new Regex(@"^([\w!-]+):(\-?\w+)$"); var match = pattern.Match(RecoverValue); if (match.Success) { result["recover"] = match.Groups[1].Value; result["connection_serial"] = match.Groups[2].Value; } } if (ClientId.IsNotEmpty()) { result["clientId"] = ClientId; } return(result); }
/// <summary> /// Merges two another instance of TokenParams with the current instance. /// </summary> /// <param name="otherParams">other instance.</param> /// <returns>a new instance of merged token params.</returns> public TokenParams Merge(TokenParams otherParams) { if (otherParams == null) { return(this); } var result = new TokenParams { ClientId = ClientId.IsNotEmpty() ? ClientId : otherParams.ClientId, Capability = Capability ?? otherParams.Capability, Ttl = Ttl ?? otherParams.Ttl, Timestamp = Timestamp ?? otherParams.Timestamp, Nonce = Nonce ?? otherParams.Nonce, }; return(result); }
internal Dictionary <string, string> ToQueryParams() { var queryParams = new Dictionary <string, string>(); if (ClientId.IsNotEmpty()) { queryParams.Add("clientId", ClientId); } if (DeviceId.IsNotEmpty()) { queryParams.Add("deviceId", DeviceId); } if (Limit.HasValue) { queryParams.Add("limit", Limit.Value.ToString()); } return(queryParams); }
/// <summary> /// Populates a dictionary of strings and optionally merges with /// an existing one. Internal method. /// </summary> /// <param name="mergeWith">optional, dictionary of strings to merge with.</param> /// <returns>returns a merge.</returns> public Dictionary <string, string> ToRequestParams(Dictionary <string, string> mergeWith = null) { var dictionary = new Dictionary <string, string>(); if (Ttl.HasValue) { dictionary.Add("ttl", Ttl.Value.TotalMilliseconds.ToString(CultureInfo.InvariantCulture)); } if (ClientId.IsNotEmpty()) { dictionary.Add("clientId", ClientId); } if (Nonce.IsNotEmpty()) { dictionary.Add("nonce", Nonce); } if (Capability != null) { dictionary.Add("capability", Capability.ToJson()); } if (Timestamp.HasValue) { dictionary.Add("timestamp", Timestamp.Value.ToUnixTimeInMilliseconds().ToString()); } if (mergeWith != null) { return(dictionary.Merge(mergeWith)); } return(dictionary); }