Syncano.Net.Api.ApiKeySyncanoClient.New C# (CSharp) 메소드

New() 공개 메소드

Creates a new API client (for backend or user-aware usage) in current instance. Only Admin permission role can create new API clients.
public New ( string description, ApiKeyType type = ApiKeyType.Backend, string roleId = null ) : Task
description string Description of new API client.
type ApiKeyType Type of new API client.
roleId string New API client's permission role id (see role.get()). Not used when creating User API key (type = user)
리턴 Task
        public Task<ApiKey> New(string description, ApiKeyType type = ApiKeyType.Backend, string roleId = null)
        {
            if(description == null)
                throw new ArgumentNullException();

            if(type == ApiKeyType.User && roleId != null)
                throw new ArgumentException();

            return _syncanoClient.PostAsync<ApiKey>("apikey.new", new {description, type = type.ToString(), role_id = roleId}, "apikey");
        }

Usage Example

        public async Task New_BackendType_CreatesNewApiKey(ApiKeySyncanoClient client)
        {
            //given
            var description = "apiKey description";

            //when
            var apiKey = await client.New(description, ApiKeyType.Backend, TestData.RoleId);

            //then
            apiKey.ShouldNotBeNull();
            apiKey.Description.ShouldEqual(description);

            //cleanup
            await client.Delete(apiKey.Id);
        }
All Usage Examples Of Syncano.Net.Api.ApiKeySyncanoClient::New