/// <summary> /// Create a new snippet /// POST /snippets /// </summary> /// <param name="name">The name of the new snippet</param> /// <param name="body">The body of the new snippet</param> /// <returns>A response with the success status and new snippet</returns> /// <exception cref="AggregateException">Thrown when the API response status code is not success or when the API call times out</exception> /// <exception cref="InvalidOperationException">Thrown when making a Batch API Request that has already reached the maxmimum API calls per batch request</exception> public static async Task <SnippetResponse> CreateSnippetAsync(string name, string body) { // Build the SnippetDefinition var newSnippet = new SnippetDefinition(name, body); // Send the POST request var resource = "snippets"; var jsonResponse = await RequestManager.SendPostRequestAsync(resource, newSnippet); // Convert the JSON result into an object return(JsonConvert.DeserializeObject <SnippetResponse>(jsonResponse)); }
/// <summary> /// Update an existing snippet /// PUT /snippets/(:id) /// </summary> /// <param name="snippetId">The ID of the snippet to update</param> /// <param name="name">The new name of the snippet</param> /// <param name="body">The new body of the snippet</param> /// <returns>A response with the success status and snippet</returns> /// <exception cref="AggregateException">Thrown when the API response status code is not success or when the API call times out</exception> /// <exception cref="InvalidOperationException">Thrown when making a Batch API Request that has already reached the maxmimum API calls per batch request</exception> public static async Task <SnippetResponse> UpdateSnippetAsync(string snippetId, string name, string body) { // Build the SnippetDefinition var newSnippet = new SnippetDefinition(name, body); // Send the PUT request var resource = String.Format("snippets/{0}", snippetId); var jsonResponse = await RequestManager.SendPutRequestAsync(resource, newSnippet); // Convert the JSON result into an object return(JsonConvert.DeserializeObject <SnippetResponse>(jsonResponse)); }