/// <summary> /// Performs a POST request. /// </summary> /// <param name="apiUrl">The URL to perform the request on.</param> /// <param name="uidParam">The Unique ID (i.e. the thing after the /).</param> /// <param name="body">A JSON body with additional details.</param> /// <returns>The HTTP Response information.</returns> /// <exception cref="System.InvalidOperationException">Thrown when the URL is null or invalid.</exception> public HttpResponse Post(string apiUrl, UniqueIdParameter uidParam, JsonBodyParameter body) { HttpRequest postRequest = new HttpRequest(_client, apiUrl); _client.SetBearerToken(_authToken); return(postRequest.Send(HttpVerb.POST, uidParam, body).Result); }
/// <summary> /// Performs a PUT request. /// </summary> /// <param name="apiUrl">The URL to perform the request on.</param> /// <param name="body">A JSON body with additional details.</param> /// <returns>The HTTP Response information.</returns> /// <exception cref="System.InvalidOperationException">Thrown when the URL is null or invalid.</exception> public HttpResponse Put(string apiUrl, JsonBodyParameter body) { HttpRequest putRequest = new HttpRequest(_client, apiUrl); _client.SetBearerToken(_authToken); return(putRequest.Send(HttpVerb.PUT, null, body).Result); }
/// <summary> /// Creates a stock entry /// </summary> /// <param name="entry">The entry</param> /// <returns>True if successful, false if not</returns> public bool CreateStockItemEntry(StockEntry entry) { string CREATE_STOCK_ENTRY_ENDPOINT = $"{_artsApiUrl}/{STOCK_ENTRY_ENDPOINT}"; JsonBodyParameter body = new JsonBodyParameter(); body.AddValue(STOCK_ITEM_ID_KEY, entry.StockItemId.ToString()); body.AddValue(ENTRY_DATE_KEY, entry.EntryDate.ToString()); body.AddValue(AVERAGE_PRICE_KEY, entry.StockItemId.ToString()); body.AddValue(LOWEST_PRICE_KEY, entry.StockItemId.ToString()); body.AddValue(HIGHEST_PRICE_KEY, entry.StockItemId.ToString()); body.AddValue(DATA_POINTS_KEY, entry.StockItemId.ToString()); HttpResponse createStockEntryResponse = _restClient.Put(CREATE_STOCK_ENTRY_ENDPOINT, body); _logger.LogInfo($"PUT {createStockEntryResponse.RequestUrl}", "CreateStockItemEntry"); _logger.LogInfo($"Body: {body.ToString()}"); _logger.LogInfo($"Status: {createStockEntryResponse.Status}", "CreateStockItemEntry"); _logger.LogInfo($"Response: {createStockEntryResponse.Response}", "CreateStockItemEntry"); if (!createStockEntryResponse.Success) { _logger.LogInfo("Create stock item entry failed.", "CreateStockItemEntry"); return(false); } int?status = ParseStatusResult(createStockEntryResponse.Response); return(status == SUCCESS_STATUS); }
public async Task Send_PostRequest_ReturnsResponse() { JsonBodyParameter body = new JsonBodyParameter(); body.AddValue(TEST_KEY, TEST_VALUE); MockResponse(HttpVerb.POST, HttpStatusCode.OK, TEST_RESPONSE); HttpResponse response = await _testRequest.Send(HttpVerb.POST, null, body); Assert.IsTrue(response.Success); Assert.AreEqual(HttpStatusCode.OK, response.Status); }
public void SetUp() { _parameter = new JsonBodyParameter(); }