public static async Task <TAPIResponse> DELETE <TAPIResponse>(string uri, byte[] deleteData = null, WebHeaderCollection whc = null, Encoding encoding = null) where TAPIResponse : APIResponse { string response = await http.DELETE(uri, deleteData, whc, encoding); return(APIResponse.Parse <TAPIResponse>(response)); }
public static async Task <TAPIResponse> POST <TAPIResponse>(string uri, byte[] postData = null, WebHeaderCollection whc = null, Encoding encoding = null) where TAPIResponse : APIResponse { string response = await http.POST(uri, postData, whc, encoding); return(APIResponse.Parse <TAPIResponse>(response)); }
private static T SendRequest <T>( String url, Object request, String method = "POST", Dictionary <String, String> headers = null, String content_type = "application/json", int timeout = 30000) { String json_post = request != null ? JsonHelper.GetJson(request, request.GetType()) : null; String resp = SendRequest(url, json_post, method, headers, content_type, timeout); if (!url.Contains("token")) { String fn = url.Replace(RequestRootURL, "").Replace("/", "--"); using (FileStream fs = File.OpenWrite(String.Format(@".\response={1}-{0}.txt", fn, method))) { byte[] bytes = Encoding.UTF8.GetBytes(resp); fs.Write(bytes, 0, bytes.Length); } } if (String.IsNullOrEmpty(resp)) { return(default(T)); } T res = APIResponse.Parse <T>(resp); (res as APIResponse)?.CheckDataAndThrowIfHasError(); return(res); }
public static async Task <TAPIResponse> GET <TAPIResponse>(string uri, Dictionary <string, string> param = null, WebHeaderCollection whc = null, Encoding encoding = null) where TAPIResponse : APIResponse { if (param != null) { uri = $"{uri}?{string.Join("&", param.Select(kv => $"{kv.Key}={kv.Value}"))}"; } string response = await http.GET(uri, whc, encoding); return(APIResponse.Parse <TAPIResponse>(response)); }
/// <summary> /// Creates new genotype profile. /// </summary> /// <param name="profile"></param> public static Profile CreateNewProfile(String first_name, String last_name, String genotype_file_path) { CheckAuth(); String url = RequestRootURL + "profiles"; NameValueCollection nvc = new NameValueCollection(); nvc.Add("first_name", first_name); nvc.Add("last_name", last_name); NameValueCollection files = new NameValueCollection(); if (!String.IsNullOrEmpty(genotype_file_path)) { files.Add("genotype.genotype_file", genotype_file_path); } String resp = SendRequest(url, nvc, files); Profile res = APIResponse.Parse <Profile>(resp); return(res); }