/// <summary> /// Creates new iHealthAccount with random username and password. /// </summary> /// <returns></returns> private async Task <string> CreateiHealthAccount() { iHealthUserResponseDto response = null; string username = null; // Try create new iHealth account again if generated username already reserved. while (response == null || response.ErrorCode.HasValue && response.ErrorCode.Value != DuplicateUseriHealthErrorCode) { var nickname = iHealthHelper.GenerateRandomiHealthUsernamePrefix(); var request = new CreateiHealthUserRequestDto { UserName = string.Format("{0}@{1}", nickname, this.iHealthSettings.iHealthAccountDomain), UserPassword = iHealthHelper.GeneratePassword(20, 5), Nickname = nickname }; response = await this.iHealthDataProvider.RegisterUser(request); if (response != null && !response.ErrorCode.HasValue) { username = request.UserName; } } return(username); }
/// <summary> /// Creates new account in iHealth API. /// </summary> /// <returns></returns> public async Task <iHealthUserResponseDto> RegisterUser(CreateiHealthUserRequestDto requestDto) { requestDto.Sv = this.iHealthSettings.iHealthSv; requestDto.Sc = this.iHealthSettings.iHealthSc; requestDto.ClientId = this.iHealthSettings.iHealthClientId; requestDto.ClientSecret = this.iHealthSettings.iHealthClientSecret; requestDto.APIName = DefaultApiName; requestDto.RedirectUri = DefaultRedirectUri; var headers = new Dictionary <string, string> { { "Referer", "http://localhost/" } }; return(await this.restApiClient.SendRequestAsync <iHealthUserResponseDto>("/user/register.json", requestDto, Method.POST, headers)); }