internal dynamic SendRequest(string url, MethodsType method = MethodsType.GET, Dictionary <string, string> query = null, object objectToSend = null) { SendRequestAndGetResponse(method, url, query, objectToSend); return(TryGetResponseDynamic(client)); }
internal Excepted SendRequest <Excepted>(string url, MethodsType method = MethodsType.GET, Dictionary <string, string> query = null, object objectToSend = null) { SendRequestAndGetResponse(method, url, query, objectToSend); return(TryGetResponse <Excepted>(client)); }
public WhereOptions(MethodsType methodType, string[] parameters, string property, bool exact = false) { Method = new WhereMethodCall { MethodType = methodType, Parameters = parameters, Property = property }; Exact = exact; }
internal Excepted SendRequest <Excepted>(string url, MethodsType method = MethodsType.GET, Dictionary <string, string> query = null, object objectToSend = null, ICustomDeserializer <Excepted> customDeserializer = null) { SendRequestAndGetResponse(method, url, query, objectToSend); if (customDeserializer == null) { return(TryGetResponse <Excepted>(client)); } else { return(TryGetResponseWithCustomDeserializer <Excepted>(client, customDeserializer)); } }
void SendRequestAndGetResponse(MethodsType method, string url, Dictionary <string, string> query = null, object objectToSend = null) { client = new RestClient(url); string queryString = ""; if (query != null) { queryString = client.AddQuery(query); } Autorize(queryString); client.Send(method, objectToSend); }
/// <summary> /// Send request with data using checked method. /// </summary> /// <param name="method">Method type.</param> /// <param name="objectToSend">Data to send.</param> public void Send(MethodsType method, object objectToSend = null, bool serializeDataToSend = true) { if (method != MethodsType.POST || method != MethodsType.PUT) { Send(method); } switch (method) { case MethodsType.POST: SendPOST(objectToSend, serializeDataToSend); break; case MethodsType.PUT: SendPUT(objectToSend, serializeDataToSend); break; } }
/// <summary> /// Send request using checked method. /// </summary> /// <param name="method">Method type.</param> public void Send(MethodsType method) { switch (method) { case MethodsType.GET: SendGET(); break; case MethodsType.DELETE: SendDELETE(); break; case MethodsType.POST: SendPOST <object>(null); break; case MethodsType.PUT: SendPUT <object>(null); break; } }
void SendRequestAndGetResponse(MethodsType method, string url, Dictionary <string, string> query = null, object objectToSend = null) { if (method != MethodsType.POST) { client = new RestClient(url); } else { client = new RestClient(url, "application/x-www-form-urlencoded"); } Dictionary <string, string> newQuery = AddTwoDictionary(query, this.query); string bodyString = AddQueryAndAutorize(method, newQuery, objectToSend); if (bodyString == string.Empty) { client.Send(method); } else { client.Send(method, bodyString, false); } }
string AddQueryAndAutorize(MethodsType method, Dictionary <string, string> query = null, object objectBody = null) { if (autorization == Autorization.NONE) { client.AddQuery(query); } else if (autorization == Autorization.MARKET) { if (!session.IsMarketAutorized) { throw new UnautorizedClientException("Client is unautorized, use SetAutorizationData() method for autorize client, " + "method required public api key."); } client.AddQuery(query); client.AddOwnHeaderToRequest("X-MBX-APIKEY", session.PublicKey); } else if (autorization == Autorization.TRADING) { if (!session.IsTradingAutorized) { throw new UnautorizedClientException("Client is unautorized, use SetAutorizationData() method for autorize client, " + "method required public and private api key."); } client.AddOwnHeaderToRequest("X-MBX-APIKEY", session.PublicKey); string totalParmas = string.Empty; if (query != null) { totalParmas += client.AddQuery(query); } string body = string.Empty; if (objectBody != null) { body = ObjectToQueryConverter.Convert(objectBody); if (method != MethodsType.POST) { totalParmas += client.AddStringToEndOfQuery("&" + body); } else { totalParmas += body; } } else { if (method == MethodsType.POST) { body = "null"; totalParmas += body; } } if (query != null) { client.AddStringToEndOfQuery("&signature=" + HashManager.HashHMACHex(session.PrivateKey, totalParmas.Substring(1))); } else { client.AddStringToEndOfQuery("?signature=" + HashManager.HashHMACHex(session.PrivateKey, totalParmas.Substring(1))); } if (method == MethodsType.POST) { return(body); } } return(""); }