Пример #1
0
 /// <summary>
 /// Get the user for the given identifier
 /// </summary>
 /// <param name="service"></param>
 /// <param name="identifier">The user identifier</param>
 /// <returns>The user, or <code>null</code> if the request failed</returns>
 public static async Task <User?> FetchUser(this HttpService service, string identifier)
 {
     return(await service.Session.Send <User>(() => HttpRequestMessageExtensions.Create(service.Session, string.Format("v1/users/{0}", identifier), HttpMethod.Get)));
 }
Пример #2
0
 /// <summary>
 /// Save the given user
 /// </summary>
 /// <param name="service"></param>
 /// <param name="user">The user to save</param>
 /// <returns><code>true</code> if the request succeeded, <code>false</code> otherwise</returns>
 public static async Task <bool> Save(this HttpService service, User user)
 {
     return(await service.Session.Send(() => HttpRequestMessageExtensions.Create(service.Session, string.Format("v1/users/{0}", user.Id), HttpMethod.Put, user)));
 }
Пример #3
0
 public ICredentials?CredentialsForHttpService(HttpService service)
 {
     return(this.CurrentCredentials);
 }
Пример #4
0
 public static async Task <UserCommunityDetail?> FetchUserCommunity(this HttpService service, string userIdentifier, string communityId)
 {
     return(await service.Send <UserCommunityDetail>(() => HttpRequestMessageExtensions.Create(service, string.Format("v1/users/{0}/communities/{1}", userIdentifier, communityId), HttpMethod.Get)));
 }
Пример #5
0
        /// <summary>
        /// Send a request to create a new user with a secret key
        /// </summary>
        /// <param name="service"></param>
        /// <param name="user">The user to create</param>
        /// <param name="usernameCredentials">The user's key credentials</param>
        /// <returns>An authentication token and user information, or <code>null</code> if the request failed</returns>
        public static async Task <AuthResponse?> Register(this HttpService service, User user, KeyCredentials keyCredentials)
        {
            var registration = new KeyRegistration(keyCredentials, user);

            return(await service.Send <AuthResponse>(() => HttpRequestMessageExtensions.Create(service, "v1/register/key", HttpMethod.Post, registration)));
        }
Пример #6
0
        /// <summary>
        /// Send a request to authenticate with key based credentials
        /// </summary>
        /// <param name="service"></param>
        /// <param name="keyCredentials">The key credentials</param>
        /// <returns>An authentication token and user information, or <code>null</code> if the request failed</returns>
        public static async Task <AuthResponse?> AuthenticateKey(this HttpService service, KeyCredentials keyCredentials)
        {
            var body = new AuthKeyRequest(keyCredentials.Key);

            return(await service.Send <AuthResponse>(() => HttpRequestMessageExtensions.Create(service, "v1/auth/key", HttpMethod.Post, body)));
        }
Пример #7
0
        /// <summary>
        /// Send a reqeust to authenticate with username based credentials
        /// </summary>
        /// <param name="service"></param>
        /// <param name="usernameCredentials">The username credentials</param>
        /// <returns>An authentication token and user information, or <code>null</code> if the request failed</returns>
        public static async Task <AuthResponse?> AuthenticateUsername(this HttpService service, UsernameCredentials usernameCredentials)
        {
            var body = new AuthUsernameRequest(usernameCredentials.Username, usernameCredentials.Password);

            return(await service.Send <AuthResponse>(() => HttpRequestMessageExtensions.Create(service, "v1/auth/username", HttpMethod.Post, body)));
        }