/// <summary> /// Delete API key asynchronously. /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.DeleteApiKeyAsync(string)"/> method. /// <code> /// try /// { /// var key = accountApi.GetApiKey() /// await accountApi.DeleteApiKeyAsync(key.Id); /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <param name="apiKeyId">Id</param> /// <returns><see cref="Task"/> with <see cref="ApiKey"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public async Task DeleteApiKeyAsync(string apiKeyId) { try { await DeveloperApi.DeleteApiKeyAsync(apiKeyId); } catch (iam.Client.ApiException e) { HandleNotFound <string, iam.Client.ApiException>(e); } }
/// <summary> /// Get API key details. Returns currently used key for empty argument. /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.GetApiKey(string)"/> method. /// <code> /// try /// { /// var key = accountApi.GetApiKey(); /// return key; /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <param name="apiKeyId">Id</param> /// <returns><see cref="ApiKey"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public ApiKey GetApiKey(string apiKeyId = null) { try { return(!string.IsNullOrEmpty(apiKeyId) ? ApiKey.Map(DeveloperApi.GetApiKey(apiKeyId)) : ApiKey.Map(DeveloperApi.GetMyApiKey())); } catch (iam.Client.ApiException e) { return(HandleNotFound <ApiKey, iam.Client.ApiException>(e)); } }
/// <summary> /// Get API key details asynchronously. Returns currently used key for empty argument. /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.GetApiKeyAsync(string)"/> method. /// <code> /// try /// { /// var key = awaut accountApi.GetApiKeyAsync(); /// return key; /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <param name="apiKeyId">Id</param> /// <returns><see cref="Task"/> with <see cref="ApiKey"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public async Task <ApiKey> GetApiKeyAsync(string apiKeyId = null) { try { return(!string.IsNullOrEmpty(apiKeyId) ? ApiKey.Map(await DeveloperApi.GetApiKeyAsync(apiKeyId)) : ApiKey.Map(await DeveloperApi.GetMyApiKeyAsync())); } catch (iam.Client.ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }
/// <summary> /// Update API key asynchronously. /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.UpdateApiKeyAsync(string, ApiKey)"/> method. /// <code> /// try /// { /// var key = await accountApi.GetApiKeyAsync() /// key.Name = "updated api key"; /// var updatedApiKey = await accountApi.UpdateApiKeyAsync(key.Id, key); /// return updatedApiKey; /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <param name="apiKeyId">Id</param> /// <param name="key"><see cref="ApiKey"/></param> /// <returns><see cref="Task"/> with <see cref="ApiKey"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public async Task <ApiKey> UpdateApiKeyAsync(string apiKeyId, ApiKey key) { try { var req = key.CreatePutRequest(); return(ApiKey.Map(await DeveloperApi.UpdateApiKeyAsync(apiKeyId, req))); } catch (iam.Client.ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }
/// <summary> /// Create new Api key asynchronously. /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.AddApiKeyAsync(ApiKey)"/> method. /// <code> /// try /// { /// var key = new ApiKey /// { /// Name = "example api key", /// }; /// var newKey = await accountApi.AddApiKeyAsync(key); /// return newKey; /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <param name="key"><see cref="ApiKey"/></param> /// <returns><see cref="Task"/> with <see cref="ApiKey"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public async Task <ApiKey> AddApiKeyAsync(ApiKey key) { try { var keyBody = key.CreatePostRequest(); return(ApiKey.Map(await DeveloperApi.CreateApiKeyAsync(keyBody))); } catch (iam.Client.ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }
/// <summary> /// Get details of a group. /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.GetGroup(string)"/> method. /// <code> /// try /// { /// var group = accountApi.GetGroup("015b5c9279ee02420a01041200000000"); /// return group; /// } /// catch (CloudApiException) /// { /// throw; /// } /// </code> /// </example> /// <param name="groupId">Id</param> /// <returns><see cref="Group"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public Group GetGroup(string groupId) { try { var groupData = DeveloperApi.GetGroupSummary(groupId); return(Group.Map(groupData)); } catch (iam.Client.ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }
/// <summary> /// Get details of account associated with current API key /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.GetAccount"/> method. /// <code> /// using MbedCloudSDK.AccountManagement.Model.Account; /// using MbedCloudSDK.Exceptions; /// try /// { /// var account = accountApi.GetAccount(); /// return account; /// } /// catch (CloudApiException e) /// { /// throw e; /// } /// </code> /// </example> /// <returns><see cref="Account"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public Account GetAccount() { try { var account = DeveloperApi.GetMyAccountInfo("limits, policies"); return(Account.Map(account)); } catch (ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }
/// <summary> /// Get details of account associated with current API key asynchronously. /// </summary> /// <example> /// This example shows how to use the <see cref="AccountManagementApi.GetAccountAsync"/> method. /// <code> /// using MbedCloudSDK.AccountManagement.Model.Account; /// using MbedCloudSDK.Exceptions; /// try /// { /// var account = await accountApi.GetAccountAsync(); /// return account; /// } /// catch (CloudApiException e) /// { /// throw e; /// } /// </code> /// </example> /// <returns><see cref="Task"/> with an <see cref="Account"/></returns> /// <exception cref="CloudApiException">CloudApiException</exception> public async Task <Account> GetAccountAsync() { try { var account = await DeveloperApi.GetMyAccountInfoAsync(); return(Account.Map(account)); } catch (ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }
private async Task <ResponsePage <ApiKey> > ListGroupApiKeysFunc(QueryOptions options) { try { var resp = await DeveloperApi.GetApiKeysOfGroupAsync(groupID : options.Id, limit : options.Limit, after : options.After, order : options.Order, include : options.Include); var responsePage = new ResponsePage <ApiKey>(after: resp.After, hasMore: resp.HasMore, totalCount: resp.TotalCount); responsePage.MapData <ApiKeyInfoResp>(resp.Data, ApiKey.Map); return(responsePage); } catch (device_directory.Client.ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }
private async Task <ResponsePage <ApiKey> > ListApiKeysFuncAsync(QueryOptions options = null) { if (options == null) { options = new QueryOptions(); } try { var resp = await DeveloperApi.GetAllApiKeysAsync(limit : options.Limit, after : options.After, order : options.Order, include : options.Include, ownerEq : options.Filter.GetFirstValueByKey("owner_id")); var responsePage = new ResponsePage <ApiKey>(after: resp.After, hasMore: resp.HasMore, resp.TotalCount); responsePage.MapData <ApiKeyInfoResp>(resp.Data, ApiKey.Map); return(responsePage); } catch (iam.Client.ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }
private async Task <ResponsePage <Group> > ListGroupsFunc(QueryOptions options = null) { if (options == null) { options = new QueryOptions(); } try { var resp = await DeveloperApi.GetAllGroupsAsync(limit : options.Limit, after : options.After, order : options.Order, include : options.Include); var responsePage = new ResponsePage <Group>(after: resp.After, hasMore: resp.HasMore, totalCount: resp.TotalCount); responsePage.MapData(resp.Data, Group.Map); return(responsePage); } catch (device_directory.Client.ApiException e) { throw new CloudApiException(e.ErrorCode, e.Message, e.ErrorContent); } }