/// <summary>
        /// Creates a new authorization for the specified OAuth application if an authorization for that application
        /// doesn’t already exist for the user; otherwise, it fails.
        /// </summary>
        /// <remarks>
        /// This method requires authentication.
        /// See the <a href="http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app">API documentation</a> for more information.
        /// </remarks>
        /// <param name="clientId">Client ID of the OAuth application for the token</param>
        /// <param name="clientSecret">The client secret</param>
        /// <param name="twoFactorAuthenticationCode">The two-factor authentication code in response to the current user's previous challenge</param>
        /// <param name="newAuthorization">Describes the new authorization to create</param>
        /// <exception cref="AuthorizationException">
        /// Thrown when the current user does not have permission to make this request.
        /// </exception>
        /// <exception cref="TwoFactorRequiredException">
        /// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
        /// </exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The created <see cref="Authorization"/>.</returns>
        public Task <ApplicationAuthorization> Create(
            string clientId,
            string clientSecret,
            NewAuthorization newAuthorization,
            string twoFactorAuthenticationCode)
        {
            Ensure.ArgumentNotNullOrEmptyString(clientId, "clientId");
            Ensure.ArgumentNotNullOrEmptyString(clientSecret, "clientSecret");
            Ensure.ArgumentNotNull(newAuthorization, "authorization");
            Ensure.ArgumentNotNullOrEmptyString(twoFactorAuthenticationCode, "twoFactorAuthenticationCode");

            var requestData = new
            {
                client_id     = clientId,
                client_secret = clientSecret,
                scopes        = newAuthorization.Scopes,
                note          = newAuthorization.Note,
                note_url      = newAuthorization.NoteUrl,
                fingerprint   = newAuthorization.Fingerprint
            };

            var endpoint = ApiUrls.Authorizations();

            return(ApiConnection.Post <ApplicationAuthorization>(endpoint, requestData, null, null, twoFactorAuthenticationCode));
        }
        /// <summary>
        /// Updates the specified <see cref="Authorization"/>.
        /// </summary>
        /// <remarks>
        /// This method requires authentication.
        /// See the <a href="http://developer.github.com/v3/oauth/#update-an-existing-authorization">API
        /// documentation</a> for more details.
        /// </remarks>
        /// <param name="id">ID of the <see cref="Authorization"/> to update</param>
        /// <param name="authorizationUpdate">Describes the changes to make to the authorization</param>
        /// <exception cref="AuthorizationException">
        /// Thrown when the current user does not have permission to make the request.
        /// </exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The updated <see cref="Authorization"/>.</returns>
        public Task <Authorization> Update(int id, AuthorizationUpdate authorizationUpdate)
        {
            Ensure.ArgumentNotNull(authorizationUpdate, "authorizationUpdate");

            return(ApiConnection.Patch <Authorization>(
                       ApiUrls.Authorizations(id),
                       authorizationUpdate));
        }
        /// <summary>
        /// Creates a new personal token for the authenticated user.
        /// </summary>
        /// <remarks>
        /// This method requires authentication.
        /// See the <a href="https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization">API documentation</a> for more information.
        /// </remarks>
        /// <param name="newAuthorization">Describes the new authorization to create</param>
        /// <exception cref="AuthorizationException">
        /// Thrown when the current user does not have permission to make this request.
        /// </exception>
        /// <exception cref="TwoFactorRequiredException">
        /// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
        /// </exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The created <see cref="Authorization"/>.</returns>
        public Task <ApplicationAuthorization> Create(NewAuthorization newAuthorization)
        {
            Ensure.ArgumentNotNull(newAuthorization, "authorization");

            var requestData = new
            {
                scopes      = newAuthorization.Scopes,
                note        = newAuthorization.Note,
                note_url    = newAuthorization.NoteUrl,
                fingerprint = newAuthorization.Fingerprint
            };

            var endpoint = ApiUrls.Authorizations();

            return(ApiConnection.Post <ApplicationAuthorization>(endpoint, requestData));
        }
        /// <summary>
        /// Updates the specified <see cref="Authorization"/>.
        /// </summary>
        /// <remarks>
        /// This method requires authentication.
        /// See the <a href="http://developer.github.com/v3/oauth/#update-an-existing-authorization">API
        /// documentation</a> for more details.
        /// </remarks>
        /// <param name="id">ID of the <see cref="Authorization"/> to update</param>
        /// <param name="authorizationUpdate">Describes the changes to make to the authorization</param>
        /// <exception cref="AuthorizationException">
        /// Thrown when the current user does not have permission to make the request.
        /// </exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The updated <see cref="Authorization"/>.</returns>
        public Task <Authorization> Update(int id, AuthorizationUpdate authorizationUpdate)
        {
            Ensure.ArgumentNotNull(authorizationUpdate, "authorizationUpdate");

            if (String.IsNullOrWhiteSpace(authorizationUpdate.Fingerprint))
            {
                return(ApiConnection.Patch <Authorization>(
                           ApiUrls.Authorizations(id),
                           authorizationUpdate));
            }
            else
            {
                return(ApiConnection.Patch <Authorization>(
                           ApiUrls.Authorizations(id),
                           authorizationUpdate,
                           previewAcceptsHeader));
            }
        }
Example #5
0
        /// <summary>
        /// Creates a new personal token for the authenticated user.
        /// </summary>
        /// <remarks>
        /// This method requires authentication.
        /// See the <a href="https://developer.github.com/v3/oauth_authorizations/#create-a-new-authorization">API documentation</a> for more information.
        /// </remarks>
        /// <param name="twoFactorAuthenticationCode">The two-factor authentication code in response to the current user's previous challenge</param>
        /// <param name="newAuthorization">Describes the new authorization to create</param>
        /// <exception cref="AuthorizationException">
        /// Thrown when the current user does not have permission to make this request.
        /// </exception>
        /// <exception cref="TwoFactorRequiredException">
        /// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
        /// </exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The created <see cref="Authorization"/>.</returns>
        public Task <ApplicationAuthorization> Create(
            NewAuthorization newAuthorization,
            string twoFactorAuthenticationCode)
        {
            Ensure.ArgumentNotNull(newAuthorization, nameof(newAuthorization));
            Ensure.ArgumentNotNullOrEmptyString(twoFactorAuthenticationCode, nameof(twoFactorAuthenticationCode));

            var requestData = new
            {
                scopes      = newAuthorization.Scopes,
                note        = newAuthorization.Note,
                note_url    = newAuthorization.NoteUrl,
                fingerprint = newAuthorization.Fingerprint
            };

            var endpoint = ApiUrls.Authorizations();

            return(ApiConnection.Post <ApplicationAuthorization>(endpoint, requestData, null, null, twoFactorAuthenticationCode));
        }
Example #6
0
        /// <summary>
        /// Creates a new authorization for the specified OAuth application if an authorization for that application
        /// doesn’t already exist for the user; otherwise, it fails.
        /// </summary>
        /// <remarks>
        /// This method requires authentication.
        /// See the <a href="http://developer.github.com/v3/oauth/#get-or-create-an-authorization-for-a-specific-app">API documentation</a> for more information.
        /// </remarks>
        /// <param name="clientId">Client Id of the OAuth application for the token</param>
        /// <param name="clientSecret">The client secret</param>
        /// <param name="newAuthorization">Describes the new authorization to create</param>
        /// <exception cref="AuthorizationException">
        /// Thrown when the current user does not have permission to make this request.
        /// </exception>
        /// <exception cref="TwoFactorRequiredException">
        /// Thrown when the current account has two-factor authentication enabled and an authentication code is required.
        /// </exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The created <see cref="Authorization"/>.</returns>
        public Task <ApplicationAuthorization> Create(
            string clientId,
            string clientSecret,
            NewAuthorization newAuthorization)
        {
            Ensure.ArgumentNotNullOrEmptyString(clientId, nameof(clientId));
            Ensure.ArgumentNotNullOrEmptyString(clientSecret, nameof(clientSecret));
            Ensure.ArgumentNotNull(newAuthorization, nameof(newAuthorization));

            var requestData = new
            {
                client_id     = clientId,
                client_secret = clientSecret,
                scopes        = newAuthorization.Scopes,
                note          = newAuthorization.Note,
                note_url      = newAuthorization.NoteUrl,
                fingerprint   = newAuthorization.Fingerprint
            };

            var endpoint = ApiUrls.Authorizations();

            return(ApiConnection.Post <ApplicationAuthorization>(endpoint, requestData));
        }
 /// <summary>
 /// Gets a specific <see cref="Authorization"/> for the authenticated user.
 /// </summary>
 /// <remarks>
 /// This method requires authentication.
 /// See the <a href="http://developer.github.com/v3/oauth/#get-a-single-authorization">API documentation</a> for more information.
 /// </remarks>
 /// <param name="id">The ID of the <see cref="Authorization"/> to get</param>
 /// <exception cref="AuthorizationException">
 /// Thrown when the current user does not have permission to make this request.
 /// </exception>
 /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
 /// <returns>The specified <see cref="Authorization"/>.</returns>
 public Task <Authorization> Get(int id)
 {
     return(ApiConnection.Get <Authorization>(ApiUrls.Authorizations(id), null));
 }
 /// <summary>
 /// Deletes the specified <see cref="Authorization"/>.
 /// </summary>
 /// <remarks>
 /// This method requires authentication.
 /// See the <a href="http://developer.github.com/v3/oauth/#delete-an-authorization">API
 /// documentation</a> for more details.
 /// </remarks>
 /// <param name="id">The system-wide ID of the authorization to delete</param>
 /// <param name="twoFactorAuthenticationCode">Two factor authorization code</param>
 /// <exception cref="AuthorizationException">
 /// Thrown when the current user does not have permission to make the request.
 /// </exception>
 /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
 /// <returns>A <see cref="Task"/> for the request's execution.</returns>
 public Task Delete(int id, string twoFactorAuthenticationCode)
 {
     return(ApiConnection.Delete(ApiUrls.Authorizations(id), twoFactorAuthenticationCode));
 }
 /// <summary>
 /// Deletes the specified <see cref="Authorization"/>.
 /// </summary>
 /// <remarks>
 /// This method requires authentication.
 /// See the <a href="http://developer.github.com/v3/oauth/#delete-an-authorization">API
 /// documentation</a> for more details.
 /// </remarks>
 /// <param name="id">The system-wide ID of the authorization to delete</param>
 /// <exception cref="AuthorizationException">
 /// Thrown when the current user does not have permission to make the request.
 /// </exception>
 /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
 /// <returns>A <see cref="Task"/> for the request's execution.</returns>
 public Task Delete(int id)
 {
     return(ApiConnection.Delete(ApiUrls.Authorizations(id)));
 }
 /// <summary>
 /// Gets all <see cref="Authorization"/>s for the authenticated user.
 /// </summary>
 /// <remarks>
 /// This method requires authentication.
 /// See the <a href="http://developer.github.com/v3/oauth/#list-your-authorizations">API documentation</a> for more information.
 /// </remarks>
 /// <exception cref="AuthorizationException">
 /// Thrown when the current user does not have permission to make the request.
 /// </exception>
 /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
 /// <returns>A list of <see cref="Authorization"/>s.</returns>
 public Task <IReadOnlyList <Authorization> > GetAll()
 {
     return(ApiConnection.GetAll <Authorization>(ApiUrls.Authorizations(), null));
 }
Example #11
0
        /// <summary>
        /// Gets all <see cref="Authorization"/>s for the authenticated user.
        /// </summary>
        /// <remarks>
        /// This method requires authentication.
        /// See the <a href="http://developer.github.com/v3/oauth/#list-your-authorizations">API documentation</a> for more information.
        /// </remarks>
        /// <param name="options">Options for changing the API response</param>
        /// <exception cref="AuthorizationException">
        /// Thrown when the current user does not have permission to make the request.
        /// </exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>A list of <see cref="Authorization"/>s for the authenticated user.</returns>
        public Task <IReadOnlyList <Authorization> > GetAll(ApiOptions options)
        {
            Ensure.ArgumentNotNull(options, nameof(options));

            return(ApiConnection.GetAll <Authorization>(ApiUrls.Authorizations(), options));
        }
        /// <summary>
        /// Creates a new <see cref="Authorization"/>.
        /// </summary>
        /// <remarks>
        /// This method requires authentication.
        /// See the <a href="http://developer.github.com/v3/oauth/#create-a-new-authorization">API documentation</a> for more information.
        /// </remarks>
        /// <param name="newAuthorization">Describes the new authorization to create</param>
        /// <exception cref="AuthorizationException">
        /// Thrown when the current user does not have permission to make the request.
        /// </exception>
        /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
        /// <returns>The created <see cref="Authorization"/>.</returns>
        public Task <Authorization> Create(NewAuthorization newAuthorization)
        {
            Ensure.ArgumentNotNull(newAuthorization, "newAuthorization");

            return(ApiConnection.Post <Authorization>(ApiUrls.Authorizations(), newAuthorization));
        }
 /// <summary>
 /// Gets a specific <see cref="Authorization"/> for the authenticated user.
 /// </summary>
 /// <remarks>
 /// This method requires authentication.
 /// See the <a href="http://developer.github.com/v3/oauth/#get-a-single-authorization">API documentation</a> for more information.
 /// </remarks>
 /// <param name="id">The ID of the <see cref="Authorization"/> to get</param>
 /// <exception cref="AuthorizationException">
 /// Thrown when the current user does not have permission to make this request.
 /// </exception>
 /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
 /// <returns>The specified <see cref="Authorization"/>.</returns>
 public Task <Authorization> Get(int id)
 {
     return(ApiConnection.Get <Authorization>(ApiUrls.Authorizations(id), null, previewAcceptsHeader));
 }
 /// <summary>
 /// Gets all <see cref="Authorization"/>s for the authenticated user.
 /// </summary>
 /// <remarks>
 /// This method requires authentication.
 /// See the <a href="http://developer.github.com/v3/oauth/#list-your-authorizations">API documentation</a> for more information.
 /// </remarks>
 /// <exception cref="AuthorizationException">
 /// Thrown when the current user does not have permission to make the request.
 /// </exception>
 /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
 /// <returns>A list of <see cref="Authorization"/>s.</returns>
 public Task <IReadOnlyList <Authorization> > GetAll()
 {
     return(ApiConnection.GetAll <Authorization>(ApiUrls.Authorizations(), null, previewAcceptsHeader));
 }
 /// <summary>
 /// Gets all <see cref="Authorization"/>s for the authenticated user.
 /// </summary>
 /// <remarks>
 /// This method requires authentication.
 /// See the <a href="http://developer.github.com/v3/oauth/#list-your-authorizations">API documentation</a> for more information.
 /// </remarks>
 /// <exception cref="AuthorizationException">
 /// Thrown when the current user does not have permission to make the request.
 /// </exception>
 /// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
 /// <returns>A list of <see cref="Authorization"/>s.</returns>
 public async Task <IReadOnlyList <Authorization> > GetAll()
 {
     return(await ApiConnection.GetAll <Authorization>(ApiUrls.Authorizations()));
 }