using System; using Octokit.Internal; namespace Octokit { /// /// A Client for the GitHub API v3. You can read more about the api here: http://developer.github.com. /// public class GitHubClient : IGitHubClient { /// /// The base address for the GitHub API /// public static readonly Uri GitHubApiUrl = new Uri("https://api.github.com/"); internal static readonly Uri GitHubDotComUrl = new Uri("https://github.com/"); /// /// Create a new instance of the GitHub API v3 client pointing to /// https://api.github.com/ /// /// /// The name (and optionally version) of the product using this library. This is sent to the server as part of /// the user agent for analytics purposes. /// public GitHubClient(ProductHeaderValue productInformation) : this(new Connection(productInformation, GitHubApiUrl)) { } /// /// Create a new instance of the GitHub API v3 client pointing to /// https://api.github.com/ /// /// /// The name (and optionally version) of the product using this library. This is sent to the server as part of /// the user agent for analytics purposes. /// /// Provides credentials to the client when making requests public GitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore) : this(new Connection(productInformation, credentialStore)) { } /// /// Create a new instance of the GitHub API v3 client pointing to the specified baseAddress. /// /// /// The name (and optionally version) of the product using this library. This is sent to the server as part of /// the user agent for analytics purposes. /// /// /// The address to point this client to. Typically used for GitHub Enterprise /// instances public GitHubClient(ProductHeaderValue productInformation, Uri baseAddress) : this(new Connection(productInformation, FixUpBaseUri(baseAddress))) { } /// /// Create a new instance of the GitHub API v3 client pointing to the specified baseAddress. /// /// /// The name (and optionally version) of the product using this library. This is sent to the server as part of /// the user agent for analytics purposes. /// /// Provides credentials to the client when making requests /// /// The address to point this client to. Typically used for GitHub Enterprise /// instances public GitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore, Uri baseAddress) : this(new Connection(productInformation, FixUpBaseUri(baseAddress), credentialStore)) { } /// /// Create a new instance of the GitHub API v3 client using the specified connection. /// /// The underlying used to make requests public GitHubClient(IConnection connection) { Ensure.ArgumentNotNull(connection, "connection"); Connection = connection; var apiConnection = new ApiConnection(connection); Authorization = new AuthorizationsClient(apiConnection); Activity = new ActivitiesClient(apiConnection); Issue = new IssuesClient(apiConnection); Miscellaneous = new MiscellaneousClient(connection); Notification = new NotificationsClient(apiConnection); Oauth = new OauthClient(connection); Organization = new OrganizationsClient(apiConnection); PullRequest = new PullRequestsClient(apiConnection); Repository = new RepositoriesClient(apiConnection); Gist = new GistsClient(apiConnection); Release = new ReleasesClient(apiConnection); User = new UsersClient(apiConnection); SshKey = new SshKeysClient(apiConnection); GitDatabase = new GitDatabaseClient(apiConnection); Search = new SearchClient(apiConnection); Deployment = new DeploymentsClient(apiConnection); } /// /// Convenience property for getting and setting credentials. /// /// /// You can use this property if you only have a single hard-coded credential. Otherwise, pass in an /// to the constructor. /// Setting this property will change the to use /// the default with just these credentials. /// public Credentials Credentials { get { return Connection.Credentials; } // Note this is for convenience. We probably shouldn't allow this to be mutable. set { Ensure.ArgumentNotNull(value, "value"); Connection.Credentials = value; } } /// /// The base address of the GitHub API. This defaults to https://api.github.com, /// but you can change it if needed (to talk to a GitHub:Enterprise server for instance). /// public Uri BaseAddress { get { return Connection.BaseAddress; } } /// /// Provides a client connection to make rest requests to HTTP endpoints. /// public IConnection Connection { get; private set; } /// /// Access GitHub's Authorization API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/oauth_authorizations/ /// public IAuthorizationsClient Authorization { get; private set; } /// /// Access GitHub's Activity API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/activity/ /// public IActivitiesClient Activity { get; private set; } /// /// Access GitHub's Issue API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/issues/ /// public IIssuesClient Issue { get; private set; } /// /// Access GitHub's Miscellaneous API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/misc/ /// public IMiscellaneousClient Miscellaneous { get; private set; } /// /// Access GitHub's OAuth API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/oauth/ /// public IOauthClient Oauth { get; private set; } /// /// Access GitHub's Organizations API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/orgs/ /// public IOrganizationsClient Organization { get; private set; } /// /// Access GitHub's Pull Requests API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/pulls/ /// public IPullRequestsClient PullRequest { get; private set; } /// /// Access GitHub's Repositories API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/repos/ /// public IRepositoriesClient Repository { get; private set; } /// /// Access GitHub's Gists API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/gists/ /// public IGistsClient Gist { get; private set; } // TODO: this should be under Repositories to align with the API docs /// /// Access GitHub's Releases API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/repos/releases/ /// public IReleasesClient Release { get; private set; } // TODO: this should be under Users to align with the API docs // TODO: this should be named PublicKeys to align with the API docs /// /// Access GitHub's Public Keys API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/users/keys/ /// public ISshKeysClient SshKey { get; private set; } /// /// Access GitHub's Users API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/users/ /// public IUsersClient User { get; private set; } // TODO: this should be under Activities to align with the API docs /// /// Access GitHub's Notifications API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/activity/notifications/ /// public INotificationsClient Notification { get; private set; } /// /// Access GitHub's Git Data API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/git/ /// public IGitDatabaseClient GitDatabase { get; private set; } /// /// Access GitHub's Search API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/search/ /// public ISearchClient Search { get; private set; } // TODO: this should be under Repositories to align with the API docs /// /// Access GitHub's Deployments API. /// /// /// Refer to the API docmentation for more information: https://developer.github.com/v3/repos/deployments/ /// public IDeploymentsClient Deployment { get; private set; } static Uri FixUpBaseUri(Uri uri) { Ensure.ArgumentNotNull(uri, "uri"); if (uri.Host.Equals("github.com") || uri.Host.Equals("api.github.com")) { return GitHubApiUrl; } return new Uri(uri, new Uri("/api/v3/", UriKind.Relative)); } } }