diff --git a/Octokit/Clients/BlobsClient.cs b/Octokit/Clients/BlobsClient.cs new file mode 100644 index 00000000..13e1a338 --- /dev/null +++ b/Octokit/Clients/BlobsClient.cs @@ -0,0 +1,50 @@ +using System.Threading.Tasks; + +namespace Octokit +{ + public class BlobsClient : ApiClient + { + public BlobsClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Gets a single Blob by SHA. + /// + /// + /// http://developer.github.com/v3/git/blobs/#get-a-blob + /// + /// The owner of the repository + /// The name of the repository + /// The SHA of the blob + /// The for the specified SHA. + public Task Get(string owner, string name, string reference) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + return ApiConnection.Get(ApiUrls.Blob(owner, name, reference)); + } + + /// + /// Creates a new Blob + /// + /// + /// http://developer.github.com/v3/git/blobs/#create-a-blob + /// + /// The owner of the repository + /// The name of the repository + /// The new Blob + /// The that was just created. + public Task Create(string owner, string name, NewBlob newBlob) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(newBlob, "newBlob"); + + return ApiConnection.Post(ApiUrls.Blob(owner, name), newBlob); + } + } +} diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 0b4bdc61..3cb0f09c 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -472,5 +472,30 @@ namespace Octokit { return "users/{0}/events/orgs/{1}".FormatUri(user, organization); } + + /// + /// Returns the for a specifc blob. + /// + /// The owner of the blob + /// The name of the organization + /// + public static Uri Blob(string owner, string name) + { + return "repos/{0}/{1}/git/blobs/{2}".FormatUri(owner, name); + } + + /// + /// Returns the for a specifc blob. + /// + /// The owner of the blob + /// The name of the organization + /// The SHA of the blob + /// + public static Uri Blob(string owner, string name, string reference) + { + var uri = Blob(owner, name).ToString(); + uri += string.Format("/{0}", reference); + return uri.FormatUri(); + } } } diff --git a/Octokit/Models/Request/NewBlob.cs b/Octokit/Models/Request/NewBlob.cs new file mode 100644 index 00000000..ecf9cf43 --- /dev/null +++ b/Octokit/Models/Request/NewBlob.cs @@ -0,0 +1,15 @@ +namespace Octokit +{ + public class NewBlob + { + /// + /// The content of the blob. + /// + public string Content { get; set; } + + /// + /// The encoding of the blob. + /// + public string Encoding { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Models/Response/Blob.cs b/Octokit/Models/Response/Blob.cs new file mode 100644 index 00000000..46ec5a7f --- /dev/null +++ b/Octokit/Models/Response/Blob.cs @@ -0,0 +1,25 @@ +namespace Octokit +{ + public class Blob + { + /// + /// The content of the blob. + /// + public string Content { get; set; } + + /// + /// The encoding of the blob. + /// + public string Encoding { get; set; } + + /// + /// The SHA of the blob. + /// + public string Sha { get; set; } + + /// + /// The size of the blob. + /// + public int Size { get; set; } + } +} \ No newline at end of file diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 613dda2f..cc3492c5 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -53,6 +53,9 @@ Properties\SolutionInfo.cs + + +