public void CreateApiCredentials() { string responseJson = GetJsonPayload("/account/meApi/response/createApiCredentials.json"); string requestJson = GetJsonPayload("/account/meApi/request/createApiCredentials.json"); var restRequest = MockRestResponse(responseJson); var credentials = new ApiCredentials { Name = "api_20_account" }; var apiCredentials = Client.MeApi.CreateApiCredentials(credentials); Assert.That(Serializer.Serialize(apiCredentials), Is.EqualTo(responseJson)); Assert.AreEqual(Method.POST, restRequest.Value.Method); var requestBodyParam = restRequest.Value.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody); Assert.That(requestBodyParam.Value, Is.EqualTo(requestJson)); }
public void CreateGetDeleteApiCredentials() { var credentials = new ApiCredentials { Name = "test1" }; var created = Client.MeApi.CreateApiCredentials(credentials); Console.WriteLine(created); Assert.AreEqual(credentials.Name, created.Name); Assert.IsTrue((bool)created.Enabled); Assert.NotNull(created.Id); created = Client.MeApi.GetApiCredentials((long)created.Id, "id,name,enabled"); Assert.AreEqual(credentials.Name, created.Name); Assert.IsTrue((bool)created.Enabled); Assert.NotNull(created.Id); Assert.Null(created.Password); Client.MeApi.DeleteApiCredentials((long)created.Id); Assert.Throws<ResourceNotFoundException>(() => Client.MeApi.GetApiCredentials((long)created.Id, "name,enabled")); }
/// <summary> /// Create API credentials for the CallFire API. This endpoint requires full CallFire account /// credentials to be used, authenticated using Basic Authentication. At this time, the user /// can only supply the name for the credentials. The generated credentials can be used to /// access any endpoint on the CallFire API. ApiCredentials.name property required /// </summary> /// <param name="credentials">API credentials to create</param> /// <returns>created credentials</returns> /// <exception cref="BadRequestException"> in case HTTP response code is 400 - Bad request, the request was formatted improperly.</exception> /// <exception cref="UnauthorizedException"> in case HTTP response code is 401 - Unauthorized, API Key missing or invalid.</exception> /// <exception cref="AccessForbiddenException"> in case HTTP response code is 403 - Forbidden, insufficient permissions.</exception> /// <exception cref="ResourceNotFoundException"> in case HTTP response code is 404 - NOT FOUND, the resource requested does not exist.</exception> /// <exception cref="InternalServerErrorException"> in case HTTP response code is 500 - Internal Server Error.</exception> /// <exception cref="CallfireApiException"> in case HTTP response code is something different from codes listed above.</exception> /// <exception cref="CallfireClientException"> in case error has occurred in client.</exception> public ApiCredentials CreateApiCredentials(ApiCredentials credentials) { return Client.Post<ApiCredentials>(ME_API_CREDS_PATH, credentials); }