Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix usage of FormatUri method #1290

Merged
merged 22 commits into from
May 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
a1a4683
updated xml documentation of Deployments method
alexander-efremov May 10, 2016
dbd2d73
fixed in OrganizationMembersClient.Delete method.
alexander-efremov May 5, 2016
face368
Revert "fixed in OrganizationMembersClient.Delete method."
alexander-efremov May 5, 2016
f0d430d
fixed usage of "repos/{0}/{1}".FormatUri(owner, name);
alexander-efremov May 5, 2016
b54435e
fixed usage of "user/keys/{0}".FormatUri(id)
alexander-efremov May 5, 2016
db98810
fixed usage of "users/{0}".FormatUri(login)
alexander-efremov May 5, 2016
896032d
added ApiUrls.StatsContributors method
alexander-efremov May 5, 2016
6794424
added method ApiUrls.StatsCommitActivity
alexander-efremov May 5, 2016
e033e10
fix to prev. commit
alexander-efremov May 5, 2016
927deff
added method ApiUrls.StatsCodeFrequency
alexander-efremov May 5, 2016
641a749
added method ApiUrls.StatsParticipation
alexander-efremov May 5, 2016
e041d12
added method ApiUrls.StatsPunchCard
alexander-efremov May 5, 2016
9c02709
added method ApiUrls.RepoCollaborator
alexander-efremov May 5, 2016
7102cc2
added method ApiUrls.OrganizationMember
alexander-efremov May 5, 2016
5ecf12e
added method ApiUrls.Organization
alexander-efremov May 5, 2016
e83f9b2
updated XML documentation of ApiUrls
alexander-efremov May 10, 2016
5b9f817
Fixed inconsistency in ApiUrls.cs (#1287)
alexander-efremov May 5, 2016
e9ff1eb
fixed after merge errors
alexander-efremov May 10, 2016
23191be
fxied after merge errors
alexander-efremov May 10, 2016
81dcbcc
added OrganizationMembersClient accidentaly missed during rebase
alexander-efremov May 10, 2016
e45f8e0
errors fixed arises during merging
alexander-efremov May 10, 2016
18766dd
fixed by remarks
alexander-efremov May 10, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Octokit/Clients/OrganizationsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public Task<Organization> Get(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");

var endpoint = "orgs/{0}".FormatUri(org);
return ApiConnection.Get<Organization>(endpoint);
return ApiConnection.Get<Organization>(ApiUrls.Organization(org));
}

/// <summary>
Expand Down
18 changes: 6 additions & 12 deletions Octokit/Clients/RepoCollaboratorsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,10 @@ public async Task<bool> 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<object>(endpoint, null, null).ConfigureAwait(false);
var response = await Connection.Get<object>(ApiUrls.RepoCollaborator(owner, repo, user), null, null).ConfigureAwait(false);
return response.HttpResponse.IsTrue();
}
catch (NotFoundException)
Expand All @@ -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));
}

/// <summary>
Expand All @@ -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));
}
}
}
8 changes: 3 additions & 5 deletions Octokit/Clients/RepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/// <summary>
Expand Down Expand Up @@ -205,8 +204,7 @@ public Task<Repository> Get(string owner, string name)
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

var endpoint = "repos/{0}/{1}".FormatUri(owner, name);
return ApiConnection.Get<Repository>(endpoint);
return ApiConnection.Get<Repository>(ApiUrls.Repository(owner, name));
}

/// <summary>
Expand Down
11 changes: 3 additions & 8 deletions Octokit/Clients/SshKeysClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public SshKeysClient(IApiConnection apiConnection) : base(apiConnection)
[Obsolete("This method is obsolete. Please use User.Keys.Get(int) instead.")]
public Task<SshKey> Get(int id)
{
var endpoint = "user/keys/{0}".FormatUri(id);

return ApiConnection.Get<SshKey>(endpoint);
return ApiConnection.Get<SshKey>(ApiUrls.Keys(id));
}

/// <summary>
Expand Down Expand Up @@ -85,8 +83,7 @@ public Task<SshKey> Update(int id, SshKeyUpdate key)
{
Ensure.ArgumentNotNull(key, "key");

var endpoint = "user/keys/{0}".FormatUri(id);
return ApiConnection.Patch<SshKey>(endpoint, key);
return ApiConnection.Patch<SshKey>(ApiUrls.Keys(id), key);
}

/// <summary>
Expand All @@ -98,9 +95,7 @@ public Task<SshKey> 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));
}
}
}
19 changes: 9 additions & 10 deletions Octokit/Clients/StatisticsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public Task<IReadOnlyList<Contributor>> 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<Contributor>(endpoint, cancellationToken);
return ApiConnection.GetQueuedOperation<Contributor>(ApiUrls.StatsContributors(owner, repositoryName), cancellationToken);
}

/// <summary>
Expand All @@ -71,8 +70,8 @@ public async Task<CommitActivity> 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<WeeklyCommitActivity>(endpoint, cancellationToken).ConfigureAwait(false);
var activity = await ApiConnection.GetQueuedOperation<WeeklyCommitActivity>(
ApiUrls.StatsCommitActivity(owner, repositoryName), cancellationToken).ConfigureAwait(false);
return new CommitActivity(activity);
}

Expand All @@ -99,8 +98,8 @@ public async Task<CodeFrequency> 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<long[]>(endpoint, cancellationToken).ConfigureAwait(false);
var rawFrequencies = await ApiConnection.GetQueuedOperation<long[]>(
ApiUrls.StatsCodeFrequency(owner, repositoryName), cancellationToken).ConfigureAwait(false);
return new CodeFrequency(rawFrequencies);
}

Expand All @@ -127,8 +126,8 @@ public async Task<Participation> 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<Participation>(endpoint, cancellationToken).ConfigureAwait(false);
var result = await ApiConnection.GetQueuedOperation<Participation>(
ApiUrls.StatsParticipation(owner, repositoryName), cancellationToken).ConfigureAwait(false);
return result.FirstOrDefault();
}

Expand All @@ -155,8 +154,8 @@ public async Task<PunchCard> 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<int[]>(endpoint, cancellationToken).ConfigureAwait(false);
var punchCardData = await ApiConnection.GetQueuedOperation<int[]>(
ApiUrls.StatsPunchCard(owner, repositoryName), cancellationToken).ConfigureAwait(false);
return new PunchCard(punchCardData);
}
}
Expand Down
3 changes: 1 addition & 2 deletions Octokit/Clients/UsersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public Task<User> Get(string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");

var endpoint = "users/{0}".FormatUri(login);
return ApiConnection.Get<User>(endpoint);
return ApiConnection.Get<User>(ApiUrls.User(login));
}

/// <summary>
Expand Down
98 changes: 98 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ public static Uri Organizations(string login)
return "users/{0}/orgs".FormatUri(login);
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns the organization for the specified organization name
/// </summary>
/// <param name="organizationName">The name of the organization</param>
/// <returns>The <see cref="Uri"/> that returns the organization for the specified organization name</returns>
public static Uri Organization(string organizationName)
{
return "orgs/{0}".FormatUri(organizationName);
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns all of the SSH keys for the currently logged in user.
/// </summary>
Expand Down Expand Up @@ -469,6 +479,17 @@ public static Uri CheckMember(string org, string name)
return "orgs/{0}/members/{1}".FormatUri(org, name);
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns member of organization
/// </summary>
/// <param name="org">The organization being inquired about</param>
/// <param name="user">The user being inquired about</param>
/// <returns>The <see cref="Uri"/> that returns member of organization</returns>
public static Uri OrganizationMember(string org, string user)
{
return "orgs/{0}/members/{1}".FormatUri(org, user);
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns a 204 if the user is a public member of the
/// organization.
Expand Down Expand Up @@ -1305,6 +1326,18 @@ public static Uri RepoCollaborators(string owner, string name)
return "repos/{0}/{1}/collaborators".FormatUri(owner, name);
}

/// <summary>
/// Returns the <see cref="Uri"/> to check user is collaborator
/// </summary>
/// <param name="owner">The owner of repo</param>
/// <param name="repo">The name of repo</param>
/// <param name="user">The name of user</param>
/// <returns>The <see cref="Uri"/> to check user is collaborator</returns>
public static Uri RepoCollaborator(string owner, string repo, string user)
{
return "repos/{0}/{1}/collaborators/{2}".FormatUri(owner, repo, user);
}

/// <summary>
/// returns the <see cref="Uri"/> for branches
/// </summary>
Expand Down Expand Up @@ -1570,6 +1603,16 @@ public static Uri IsFollowing(string login, string following)
return "users/{0}/following/{1}".FormatUri(login, following);
}

/// <summary>
/// Returns the <see cref="System.Uri"/> for the user for the given login
/// </summary>
/// <param name="login">Name of the user</param>
/// <returns>The <see cref="System.Uri"/> for the user for the given login</returns>
public static Uri User(string login)
{
return "users/{0}".FormatUri(login);
}

/// <summary>
/// Creates the relative <see cref="Uri"/> for initiating the OAuth Web login Flow
/// </summary>
Expand Down Expand Up @@ -1681,6 +1724,61 @@ public static Uri RepositoryPageBuildsLatest(string owner, string name)
return "repos/{0}/{1}/pages/builds/latest".FormatUri(owner, name);
}

/// <summary>
/// Returns the <see cref="System.Uri"/> for the contributors for the given repository
/// </summary>
/// <param name="owner">Owner of the repository</param>
/// <param name="name">Name of the repository</param>
/// <returns>The <see cref="System.Uri"/> for the contributors for the given repository</returns>
public static Uri StatsContributors(string owner, string name)
{
return "repos/{0}/{1}/stats/contributors".FormatUri(owner, name);
}

/// <summary>
/// Returns the <see cref="System.Uri"/> for the commit activity for the given repository
/// </summary>
/// <param name="owner">Owner of the repository</param>
/// <param name="name">Name of the repository</param>
/// <returns>The <see cref="System.Uri"/> for the commit activity for the given repository</returns>
public static Uri StatsCommitActivity(string owner, string name)
{
return "repos/{0}/{1}/stats/commit_activity".FormatUri(owner, name);
}

/// <summary>
/// Returns the <see cref="System.Uri"/> for the code frequency for the given repository
/// </summary>
/// <param name="owner">Owner of the repository</param>
/// <param name="name">Name of the repository</param>
/// <returns>The <see cref="System.Uri"/> for the code frequency for the given repository</returns>
public static Uri StatsCodeFrequency(string owner, string name)
{
return "repos/{0}/{1}/stats/code_frequency".FormatUri(owner, name);
}

/// <summary>
/// Returns the <see cref="System.Uri"/> for the participation for the given repository
/// </summary>
/// <param name="owner">Owner of the repository</param>
/// <param name="name">Name of the repository</param>
/// <returns>The <see cref="System.Uri"/> for the participation for the given repository</returns>
public static Uri StatsParticipation(string owner, string name)
{
return "repos/{0}/{1}/stats/participation".FormatUri(owner, name);
}

/// <summary>
/// Returns the <see cref="System.Uri"/> for the punch card for the given repository
/// </summary>
/// <param name="owner">Owner of the repository</param>
/// <param name="name">Name of the repository</param>
/// <returns>The <see cref="System.Uri"/> for the punch card for the given repository</returns>
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);
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Compile Include="Clients\MergingClient.cs" />
<Compile Include="Clients\OAuthClient.cs" />
<Compile Include="Clients\IRepositoryContentsClient.cs" />
<Compile Include="Clients\OrganizationMembersClient.cs" />
<Compile Include="Clients\RepositoryCommentsClient.cs" />
<Compile Include="Clients\IRepositoryCommentsClient.cs" />
<Compile Include="Clients\FeedsClient.cs" />
Expand Down Expand Up @@ -314,7 +315,6 @@
<Compile Include="Clients\MilestonesClient.cs" />
<Compile Include="Clients\RepositoryForksClient.cs" />
<Compile Include="Clients\RepositoryHooksClient.cs" />
<Compile Include="Clients\OrganizationMembersClient.cs" />
<Compile Include="Clients\StarredClient.cs" />
<Compile Include="Clients\TagsClient.cs" />
<Compile Include="Exceptions\NotFoundException.cs" />
Expand Down