diff --git a/Octokit/Clients/OrganizationsClient.cs b/Octokit/Clients/OrganizationsClient.cs index dad301a06c..113247c113 100644 --- a/Octokit/Clients/OrganizationsClient.cs +++ b/Octokit/Clients/OrganizationsClient.cs @@ -44,8 +44,7 @@ public Task Get(string org) { Ensure.ArgumentNotNullOrEmptyString(org, "org"); - var endpoint = "orgs/{0}".FormatUri(org); - return ApiConnection.Get(endpoint); + return ApiConnection.Get(ApiUrls.Organization(org)); } /// diff --git a/Octokit/Clients/RepoCollaboratorsClient.cs b/Octokit/Clients/RepoCollaboratorsClient.cs index 73ac70b6c0..d72ea21794 100644 --- a/Octokit/Clients/RepoCollaboratorsClient.cs +++ b/Octokit/Clients/RepoCollaboratorsClient.cs @@ -73,12 +73,10 @@ public async Task IsCollaborator(string owner, string repo, string user) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - - var endpoint = "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user); - + try { - var response = await Connection.Get(endpoint, null, null).ConfigureAwait(false); + var response = await Connection.Get(ApiUrls.RepoCollaborator(owner, repo, user), null, null).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch (NotFoundException) @@ -100,10 +98,8 @@ public Task Add(string owner, string repo, string user) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - - var endpoint = "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user); - - return ApiConnection.Put(endpoint); + + return ApiConnection.Put(ApiUrls.RepoCollaborator(owner, repo, user)); } /// @@ -119,10 +115,8 @@ public Task Delete(string owner, string repo, string user) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repo, "repo"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); - - var endpoint = "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user); - - return ApiConnection.Delete(endpoint); + + return ApiConnection.Delete(ApiUrls.RepoCollaborator(owner, repo, user)); } } } diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index dfb3806e62..2f901af2d0 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -151,9 +151,8 @@ public Task Delete(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - - var endpoint = "repos/{0}/{1}".FormatUri(owner, name); - return ApiConnection.Delete(endpoint); + + return ApiConnection.Delete(ApiUrls.Repository(owner, name)); } /// @@ -205,8 +204,7 @@ public Task Get(string owner, string name) Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - var endpoint = "repos/{0}/{1}".FormatUri(owner, name); - return ApiConnection.Get(endpoint); + return ApiConnection.Get(ApiUrls.Repository(owner, name)); } /// diff --git a/Octokit/Clients/SshKeysClient.cs b/Octokit/Clients/SshKeysClient.cs index 49764f8ff9..544d15afbd 100644 --- a/Octokit/Clients/SshKeysClient.cs +++ b/Octokit/Clients/SshKeysClient.cs @@ -30,9 +30,7 @@ public SshKeysClient(IApiConnection apiConnection) : base(apiConnection) [Obsolete("This method is obsolete. Please use User.Keys.Get(int) instead.")] public Task Get(int id) { - var endpoint = "user/keys/{0}".FormatUri(id); - - return ApiConnection.Get(endpoint); + return ApiConnection.Get(ApiUrls.Keys(id)); } /// @@ -85,8 +83,7 @@ public Task Update(int id, SshKeyUpdate key) { Ensure.ArgumentNotNull(key, "key"); - var endpoint = "user/keys/{0}".FormatUri(id); - return ApiConnection.Patch(endpoint, key); + return ApiConnection.Patch(ApiUrls.Keys(id), key); } /// @@ -98,9 +95,7 @@ public Task Update(int id, SshKeyUpdate key) [Obsolete("This method is obsolete. Please use User.Keys.Delete(int) instead.")] public Task Delete(int id) { - var endpoint = "user/keys/{0}".FormatUri(id); - - return ApiConnection.Delete(endpoint); + return ApiConnection.Delete(ApiUrls.Keys(id)); } } } diff --git a/Octokit/Clients/StatisticsClient.cs b/Octokit/Clients/StatisticsClient.cs index d55207d2da..e8bc929e19 100644 --- a/Octokit/Clients/StatisticsClient.cs +++ b/Octokit/Clients/StatisticsClient.cs @@ -44,8 +44,7 @@ public Task> GetContributors(string owner, string rep Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - var endpoint = "repos/{0}/{1}/stats/contributors".FormatUri(owner, repositoryName); - return ApiConnection.GetQueuedOperation(endpoint, cancellationToken); + return ApiConnection.GetQueuedOperation(ApiUrls.StatsContributors(owner, repositoryName), cancellationToken); } /// @@ -71,8 +70,8 @@ public async Task GetCommitActivity(string owner, string reposit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - var endpoint = "repos/{0}/{1}/stats/commit_activity".FormatUri(owner, repositoryName); - var activity = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); + var activity = await ApiConnection.GetQueuedOperation( + ApiUrls.StatsCommitActivity(owner, repositoryName), cancellationToken).ConfigureAwait(false); return new CommitActivity(activity); } @@ -99,8 +98,8 @@ public async Task GetCodeFrequency(string owner, string repositor Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - var endpoint = "repos/{0}/{1}/stats/code_frequency".FormatUri(owner, repositoryName); - var rawFrequencies = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); + var rawFrequencies = await ApiConnection.GetQueuedOperation( + ApiUrls.StatsCodeFrequency(owner, repositoryName), cancellationToken).ConfigureAwait(false); return new CodeFrequency(rawFrequencies); } @@ -127,8 +126,8 @@ public async Task GetParticipation(string owner, string repositor Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - var endpoint = "repos/{0}/{1}/stats/participation".FormatUri(owner, repositoryName); - var result = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); + var result = await ApiConnection.GetQueuedOperation( + ApiUrls.StatsParticipation(owner, repositoryName), cancellationToken).ConfigureAwait(false); return result.FirstOrDefault(); } @@ -155,8 +154,8 @@ public async Task GetPunchCard(string owner, string repositoryName, C Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName"); - var endpoint = "repos/{0}/{1}/stats/punch_card".FormatUri(owner, repositoryName); - var punchCardData = await ApiConnection.GetQueuedOperation(endpoint, cancellationToken).ConfigureAwait(false); + var punchCardData = await ApiConnection.GetQueuedOperation( + ApiUrls.StatsPunchCard(owner, repositoryName), cancellationToken).ConfigureAwait(false); return new PunchCard(punchCardData); } } diff --git a/Octokit/Clients/UsersClient.cs b/Octokit/Clients/UsersClient.cs index 39372a3522..4e835142cc 100644 --- a/Octokit/Clients/UsersClient.cs +++ b/Octokit/Clients/UsersClient.cs @@ -49,8 +49,7 @@ public Task Get(string login) { Ensure.ArgumentNotNullOrEmptyString(login, "login"); - var endpoint = "users/{0}".FormatUri(login); - return ApiConnection.Get(endpoint); + return ApiConnection.Get(ApiUrls.User(login)); } /// diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index f37f9c7b69..f03a8b9c53 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -88,6 +88,16 @@ public static Uri Organizations(string login) return "users/{0}/orgs".FormatUri(login); } + /// + /// Returns the that returns the organization for the specified organization name + /// + /// The name of the organization + /// The that returns the organization for the specified organization name + public static Uri Organization(string organizationName) + { + return "orgs/{0}".FormatUri(organizationName); + } + /// /// Returns the that returns all of the SSH keys for the currently logged in user. /// @@ -469,6 +479,17 @@ public static Uri CheckMember(string org, string name) return "orgs/{0}/members/{1}".FormatUri(org, name); } + /// + /// Returns the that returns member of organization + /// + /// The organization being inquired about + /// The user being inquired about + /// The that returns member of organization + public static Uri OrganizationMember(string org, string user) + { + return "orgs/{0}/members/{1}".FormatUri(org, user); + } + /// /// Returns the that returns a 204 if the user is a public member of the /// organization. @@ -1305,6 +1326,18 @@ public static Uri RepoCollaborators(string owner, string name) return "repos/{0}/{1}/collaborators".FormatUri(owner, name); } + /// + /// Returns the to check user is collaborator + /// + /// The owner of repo + /// The name of repo + /// The name of user + /// The to check user is collaborator + public static Uri RepoCollaborator(string owner, string repo, string user) + { + return "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user); + } + /// /// returns the for branches /// @@ -1570,6 +1603,16 @@ public static Uri IsFollowing(string login, string following) return "users/{0}/following/{1}".FormatUri(login, following); } + /// + /// Returns the for the user for the given login + /// + /// Name of the user + /// The for the user for the given login + public static Uri User(string login) + { + return "users/{0}".FormatUri(login); + } + /// /// Creates the relative for initiating the OAuth Web login Flow /// @@ -1681,6 +1724,61 @@ public static Uri RepositoryPageBuildsLatest(string owner, string name) return "repos/{0}/{1}/pages/builds/latest".FormatUri(owner, name); } + /// + /// Returns the for the contributors for the given repository + /// + /// Owner of the repository + /// Name of the repository + /// The for the contributors for the given repository + public static Uri StatsContributors(string owner, string name) + { + return "repos/{0}/{1}/stats/contributors".FormatUri(owner, name); + } + + /// + /// Returns the for the commit activity for the given repository + /// + /// Owner of the repository + /// Name of the repository + /// The for the commit activity for the given repository + public static Uri StatsCommitActivity(string owner, string name) + { + return "repos/{0}/{1}/stats/commit_activity".FormatUri(owner, name); + } + + /// + /// Returns the for the code frequency for the given repository + /// + /// Owner of the repository + /// Name of the repository + /// The for the code frequency for the given repository + public static Uri StatsCodeFrequency(string owner, string name) + { + return "repos/{0}/{1}/stats/code_frequency".FormatUri(owner, name); + } + + /// + /// Returns the for the participation for the given repository + /// + /// Owner of the repository + /// Name of the repository + /// The for the participation for the given repository + public static Uri StatsParticipation(string owner, string name) + { + return "repos/{0}/{1}/stats/participation".FormatUri(owner, name); + } + + /// + /// Returns the for the punch card for the given repository + /// + /// Owner of the repository + /// Name of the repository + /// The for the punch card for the given repository + public static Uri StatsPunchCard(string owner, string name) + { + return "repos/{0}/{1}/stats/punch_card".FormatUri(owner, name); + } + private static Uri EnterpriseAdminStats(string type) { return "enterprise/stats/{0}".FormatUri(type); diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 44e007ab42..0aefa896e8 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -80,6 +80,7 @@ + @@ -314,7 +315,6 @@ -