/// <summary> /// Performs a GET request with a unique ID (i.e. www.url.com/items/1). /// </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> /// <returns>The HTTP Response information.</returns> /// <exception cref="System.InvalidOperationException">Thrown when the URL and UID are null or the /// URL is invalid.</exception> public HttpResponse Get(string apiUrl, UniqueIdParameter uidParam) { HttpRequest getRequest = new HttpRequest(_client, apiUrl); _client.SetBearerToken(_authToken); return(getRequest.Send(HttpVerb.GET, uidParam).Result); }
/// <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); }
public void Format_WithWhiteSpace_ThrowsException() { Assert.Throws <ArgumentException>(() => { _parameter = new UniqueIdParameter(" "); }); }
/// <summary> /// Performs a DELETE 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> /// <returns>The HTTP Response information.</returns> /// <exception cref="System.InvalidOperationException">Thrown when the URL is null or invalid or when the /// operation has already been received by the server.</exception> public HttpResponse Delete(string apiUrl, UniqueIdParameter uidParam) { HttpRequest deleteRequest = new HttpRequest(_client, apiUrl); _client.SetBearerToken(_authToken); return(deleteRequest.Send(HttpVerb.DELETE, uidParam).Result); }
public void Format_WithEmptyString_ThrowsException() { Assert.Throws <ArgumentException>(() => { _parameter = new UniqueIdParameter(string.Empty); }); }
public void Format_WithNull_ThrowsException() { Assert.Throws <ArgumentNullException>(() => { _parameter = new UniqueIdParameter(null); }); }
public async Task Send_DeleteRequest_ReturnsResponse() { UniqueIdParameter uid = new UniqueIdParameter(TEST_VALUE); MockResponse(HttpVerb.DELETE, HttpStatusCode.OK, TEST_RESPONSE); HttpResponse response = await _testRequest.Send(HttpVerb.DELETE, uid); Assert.IsTrue(response.Success); Assert.AreEqual(HttpStatusCode.OK, response.Status); }
public async Task Send_PutRequest_ReturnsResponse() { JsonBodyParameter body = new JsonBodyParameter(); UniqueIdParameter uid = new UniqueIdParameter(TEST_VALUE); body.AddValue(TEST_KEY, TEST_VALUE); MockResponse(HttpVerb.PUT, HttpStatusCode.OK, TEST_RESPONSE); HttpResponse response = await _testRequest.Send(HttpVerb.PUT, uid, body); Assert.IsTrue(response.Success); Assert.AreEqual(HttpStatusCode.OK, response.Status); }
public void Format_WithValue_ReturnsUidString() { _parameter = new UniqueIdParameter(TEST_VALUE); Assert.AreEqual($"/{TEST_VALUE}", _parameter.Format()); }