Ejemplo n.º 1
0
        //TODO Still need to complete
        public async Task <String> SignUpWithCustomerAsync(string email, string password, string orgSlug)
        {
            ParticleGeneralResponse particleResponse = null;

            var requestContent = new FormUrlEncodedContent(new[] {
                new KeyValuePair <string, string> ("productIdOrSlug", orgSlug),
                new KeyValuePair <string, string> ("email", email),
                new KeyValuePair <string, string> ("password", password)
            });

            try
            {
                using (var client = new HttpClient(new NativeMessageHandler()))
                {
                    var response = await client.PostAsync(
                        CUSTOMERS_URI_ENDPOINT + orgSlug + "/customers/" + "?access_token=" + AccessToken.Token, requestContent);

                    particleResponse = DeserializeObject <ParticleGeneralResponse>(await response.Content.ReadAsStringAsync());

                    if (particleResponse.Ok)
                    {
                        return("Success");
                    }
                }
            }
            catch (Exception e)
            {
                WriteLine(e.Message);
            }

            return(particleResponse.Errors[0] ?? "UnknownError");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sign-up a new user with Particle.
        /// </summary>
        /// <returns>A string of either "Success" or the specific error</returns>
        /// <param name="username">Username.</param>
        /// <param name="password">Password.</param>
        public async Task <string> SignupWithUserAsync(string username, string password)
        {
            ParticleGeneralResponse particleResponse = null;

            var requestContent = new FormUrlEncodedContent(new[] {
                new KeyValuePair <string, string> ("username", username),
                new KeyValuePair <string, string> ("password", password),
            });

            try
            {
                using (var client = new HttpClient(new NativeMessageHandler()))
                {
                    var response = await client.PostAsync(USER_URI_ENDPOINT, requestContent);

                    particleResponse = DeserializeObject <ParticleGeneralResponse>(await response.Content.ReadAsStringAsync());

                    if (particleResponse.Ok)
                    {
                        return("Success");
                    }
                }
            }
            catch (Exception e)
            {
                WriteLine(e.Message);
            }

            return(particleResponse.Errors[0] ?? "UnknownError");
        }