public static Tuple <File, ApiCallResponse> update(string access_token, string file_id, string name = null, List <Annotation> annotations = null, FileQueryParameters parameter = null) { ApiCallResponse apiCallResponse = new ApiCallResponse(); File file = new File(); if (string.IsNullOrEmpty(access_token)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter access_token"; return(new Tuple <File, ApiCallResponse>(new File(), apiCallResponse)); } if (string.IsNullOrEmpty(file_id)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter file_id"; return(new Tuple <File, ApiCallResponse>(new File(), apiCallResponse)); } if (string.IsNullOrEmpty(name) && annotations == null) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter name or annotations - at least one of those must be set"; return(new Tuple <File, ApiCallResponse>(new File(), apiCallResponse)); } try { FileUpdateParameters tempFile = new FileUpdateParameters(); tempFile.name = name; tempFile.annotations = annotations; string requestUrl = Common.baseUrl + "/stream/0/files/" + file_id; JsonSerializerSettings settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; string jsonString = JsonConvert.SerializeObject(tempFile, Formatting.None, settings); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("Authorization", "Bearer " + access_token); Helper.Response response = Helper.SendPutRequestStringDataOnly( requestUrl, jsonString, headers, true, contentType: "application/json"); return(Helper.getData <File>(response)); } catch (WebException e) { WebResponse response = e.Response; HttpWebResponse httpResponse = (HttpWebResponse)response; Console.WriteLine("Error code: {0}", httpResponse.StatusCode); System.IO.Stream data = response.GetResponseStream(); string text = new System.IO.StreamReader(data).ReadToEnd(); Console.WriteLine(text); } catch (Exception exp) { apiCallResponse.success = false; apiCallResponse.errorMessage = exp.Message; apiCallResponse.errorDescription = exp.StackTrace; } return(new Tuple <File, ApiCallResponse>(file, apiCallResponse)); }
public static Tuple<File, ApiCallResponse> update(string access_token, string file_id, string name = null, List<Annotation> annotations = null, FileQueryParameters parameter = null) { ApiCallResponse apiCallResponse = new ApiCallResponse(); File file = new File(); if (string.IsNullOrEmpty(access_token)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter access_token"; return new Tuple<File, ApiCallResponse>(new File(), apiCallResponse); } if (string.IsNullOrEmpty(file_id)) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter file_id"; return new Tuple<File, ApiCallResponse>(new File(), apiCallResponse); } if (string.IsNullOrEmpty(name) && annotations == null) { apiCallResponse.success = false; apiCallResponse.errorMessage = "Missing parameter name or annotations - at least one of those must be set"; return new Tuple<File, ApiCallResponse>(new File(), apiCallResponse); } try { FileUpdateParameters tempFile = new FileUpdateParameters(); tempFile.name = name; tempFile.annotations = annotations; string requestUrl = Common.baseUrl + "/stream/0/files/" + file_id; JsonSerializerSettings settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; string jsonString = JsonConvert.SerializeObject(tempFile, Formatting.None, settings); Dictionary<string, string> headers = new Dictionary<string, string>(); headers.Add("Authorization", "Bearer " + access_token); Helper.Response response = Helper.SendPutRequestStringDataOnly( requestUrl, jsonString, headers, true, contentType: "application/json"); return Helper.getData<File>(response); } catch (WebException e) { WebResponse response = e.Response; HttpWebResponse httpResponse = (HttpWebResponse)response; Console.WriteLine("Error code: {0}", httpResponse.StatusCode); System.IO.Stream data = response.GetResponseStream(); string text = new System.IO.StreamReader(data).ReadToEnd(); Console.WriteLine(text); } catch (Exception exp) { apiCallResponse.success = false; apiCallResponse.errorMessage = exp.Message; apiCallResponse.errorDescription = exp.StackTrace; } return new Tuple<File, ApiCallResponse>(file, apiCallResponse); }