Exemplo n.º 1
0
        /// <summary>
        /// Logins with credentials and returns a .
        /// </summary>
        /// <param name="resource">The resource.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns>A new instance of Todoist client.</returns>
        /// <exception cref="HttpRequestException">API exception.</exception>
        /// <exception cref="TodoistException">Unable to get token.</exception>
        private static async Task <TodoistClient> LoginWithCredentialsAsync(
            string resource,
            KeyValuePair <string, string>[] parameters)
        {
            var tokenlessClient = new TodoistClient();
            var userInfo        = await tokenlessClient.ProcessPostAsync <UserInfo>(resource, parameters).ConfigureAwait(false);

            return(new TodoistClient(userInfo.Token));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers a new user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>The user info.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="user"/> is <see langword="null"/></exception>
        /// <exception cref="HttpRequestException">API exception.</exception>
        public static async Task <UserInfo> RegisterUserAsync(UserBase user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var tokenlessClient = new TodoistClient();
            var userInfo        =
                await tokenlessClient.ProcessPostAsync <UserInfo>("user/register", user.ToParameters())
                .ConfigureAwait(false);

            return(userInfo);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TodoistTokenlessClient" /> class.
 /// </summary>
 /// <param name="restClient">The rest client.</param>
 public TodoistTokenlessClient(ITodoistRestClient restClient)
 {
     _todoistClient = new TodoistClient(restClient);
 }