Ejemplo n.º 1
0
        public IObservable <IUser> SignUp(
            Email email,
            Password password,
            bool termsAccepted,
            int countryId,
            string timezone
            )
        {
            if (!email.IsValid)
            {
                throw new ArgumentException(nameof(email));
            }

            var dto = new SignUpParameters
            {
                Email     = email,
                Password  = password,
                Workspace = new WorkspaceParameters
                {
                    InitialPricingPlan = PricingPlans.Free
                },
                TermsAccepted = termsAccepted,
                CountryId     = countryId,
                Timezone      = timezone
            };
            var json = serializer.Serialize(dto, SerializationReason.Post, null);

            return(SendRequest <User>(endPoints.Post, new HttpHeader[0], json)
                   .Catch <IUser, BadRequestException>(badRequestException
                                                       => badRequestException.LocalizedApiErrorMessage == userAlreadyExistsApiErrorMessage
                        ? Observable.Throw <IUser>(new EmailIsAlreadyUsedException(badRequestException))
                        : Observable.Throw <IUser>(badRequestException)));
        }
Ejemplo n.º 2
0
        public IObservable <IUser> SignUp(Email email, string password)
        {
            if (!email.IsValid)
            {
                throw new ArgumentException(nameof(email));
            }

            var dto = new SignUpParameters
            {
                Email     = email.ToString(),
                Password  = password,
                Workspace = new SignUpParameters.WorkspaceParameters
                {
                    Name = $"{email.ToFullName()}'s workspace",
                    InitialPricingPlan = PricingPlans.Free
                }
            };
            var json = serializer.Serialize(dto, SerializationReason.Post, null);

            return(CreateObservable <User>(endPoints.Post, new HttpHeader[0], json));
        }
Ejemplo n.º 3
0
        public async Task <IUser> SignUp(
            Email email,
            Password password,
            bool termsAccepted,
            int countryId,
            string timezone
            )
        {
            if (!email.IsValid)
            {
                throw new ArgumentException(nameof(email));
            }

            var dto = new SignUpParameters
            {
                Email     = email,
                Password  = password,
                Workspace = new WorkspaceParameters
                {
                    InitialPricingPlan = PricingPlans.Free
                },
                TermsAccepted = termsAccepted,
                CountryId     = countryId,
                Timezone      = timezone
            };
            var json = serializer.Serialize(dto, SerializationReason.Post);

            try
            {
                var user = await SendRequest <User>(endPoints.Post, new HttpHeader[0], json)
                           .ConfigureAwait(false);

                return(user);
            }
            catch (BadRequestException ex)
                when(ex.LocalizedApiErrorMessage == userAlreadyExistsApiErrorMessage)
                {
                    throw new EmailIsAlreadyUsedException(ex);
                }
        }
Ejemplo n.º 4
0
        public IObservable <IUser> SignUp(Email email, Password password)
        {
            if (!email.IsValid)
            {
                throw new ArgumentException(nameof(email));
            }

            var dto = new SignUpParameters
            {
                Email     = email,
                Password  = password,
                Workspace = new WorkspaceParameters
                {
                    InitialPricingPlan = PricingPlans.Free
                }
            };
            var json = serializer.Serialize(dto, SerializationReason.Post, null);

            return(CreateObservable <User>(endPoints.Post, new HttpHeader[0], json, checkForApiToken)
                   .Catch <IUser, BadRequestException>(badRequestException
                                                       => badRequestException.LocalizedApiErrorMessage == userAlreadyExistsApiErrorMessage
                        ? Observable.Throw <IUser>(new EmailIsAlreadyUsedException(badRequestException))
                        : Observable.Throw <IUser>(badRequestException)));
        }