Implement response objects for license info

This commit is contained in:
Haacked
2015-03-17 13:18:28 -07:00
parent abe8f2e9d8
commit 6bb2f30302
8 changed files with 164 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class License : LicenseMetadata
{
public License(
string key,
string name,
Uri url,
Uri htmlUrl,
bool featured,
string description,
string category,
string implementation,
string body,
IEnumerable<string> required,
IEnumerable<string> permitted,
IEnumerable<string> forbidden) : base(key, name, url)
{
Ensure.ArgumentNotNull(htmlUrl, "htmlUrl");
Ensure.ArgumentNotNull(description, "description");
Ensure.ArgumentNotNull(category, "category");
Ensure.ArgumentNotNull(implementation, "implementation");
Ensure.ArgumentNotNull(body, "body");
Ensure.ArgumentNotNull(required, "required");
Ensure.ArgumentNotNull(permitted, "permitted");
Ensure.ArgumentNotNull(forbidden, "forbidden");
HtmlUrl = htmlUrl;
Featured = featured;
Description = description;
Category = category;
Implementation = implementation;
Body = body;
Required = new ReadOnlyCollection<string>(required.ToList());
Permitted = new ReadOnlyCollection<string>(permitted.ToList());
Forbidden = new ReadOnlyCollection<string>(forbidden.ToList());
}
public License()
{
}
/// <summary>
/// Url to the license on https://choosealicense.com
/// </summary>
public Uri HtmlUrl { get; protected set; }
/// <summary>
/// Whether the license is one of the licenses featured on https://choosealicense.com
/// </summary>
public bool Featured { get; protected set; }
/// <summary>
/// A description of the license.
/// </summary>
public string Description { get; protected set; }
/// <summary>
/// A group or family that the license belongs to such as the GPL family of licenses.
/// </summary>
public string Category { get; protected set; }
/// <summary>
/// Notes on how to properly apply the license.
/// </summary>
public string Implementation { get; protected set; }
/// <summary>
/// Set of codes for what is required under the terms of the license. For example, "include-copyright"
/// </summary>
public IReadOnlyCollection<string> Required { get; protected set; }
/// <summary>
/// Set of codes for what is permitted under the terms of the license. For example, "commerical-use"
/// </summary>
public IReadOnlyCollection<string> Permitted { get; protected set; }
/// <summary>
/// Set of codes for what is forbidden under the terms of the license. For example, "no-liability"
/// </summary>
public IReadOnlyCollection<string> Forbidden { get; protected set; }
/// <summary>
/// The text of the license
/// </summary>
public string Body { get; set; }
internal override string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "{0} Category: {1}", base.DebuggerDisplay, Category);
}
}
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class LicenseMetadata
{
public LicenseMetadata(string key, string name, Uri url)
{
Ensure.ArgumentNotNullOrEmptyString(key, "key");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(url, "url");
Key = key;
Name = name;
Url = url;
}
public LicenseMetadata()
{
}
/// <summary>
/// The
/// </summary>
public string Key { get; protected set; }
/// <summary>
/// Friendly name of the license.
/// </summary>
public string Name { get; protected set; }
/// <summary>
/// URL to retrieve details about a license.
/// </summary>
public Uri Url { get; protected set; }
internal virtual string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "Key: {0} Name: {1}", Key, Name);
}
}
}
}

View File

@@ -379,6 +379,8 @@
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
<Compile Include="Models\Request\RepositoryRequest.cs" />
<Compile Include="Models\Response\GitIgnoreTemplate.cs" />
<Compile Include="Models\Response\License.cs" />
<Compile Include="Models\Response\LicenseMetadata.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -391,6 +391,8 @@
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
<Compile Include="Models\Request\RepositoryRequest.cs" />
<Compile Include="Models\Response\GitIgnoreTemplate.cs" />
<Compile Include="Models\Response\License.cs" />
<Compile Include="Models\Response\LicenseMetadata.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>

View File

@@ -384,6 +384,8 @@
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
<Compile Include="Models\Request\RepositoryRequest.cs" />
<Compile Include="Models\Response\GitIgnoreTemplate.cs" />
<Compile Include="Models\Response\License.cs" />
<Compile Include="Models\Response\LicenseMetadata.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

View File

@@ -377,6 +377,8 @@
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
<Compile Include="Models\Request\RepositoryRequest.cs" />
<Compile Include="Models\Response\GitIgnoreTemplate.cs" />
<Compile Include="Models\Response\License.cs" />
<Compile Include="Models\Response\LicenseMetadata.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">

View File

@@ -381,6 +381,8 @@
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
<Compile Include="Models\Request\RepositoryRequest.cs" />
<Compile Include="Models\Response\GitIgnoreTemplate.cs" />
<Compile Include="Models\Response\License.cs" />
<Compile Include="Models\Response\LicenseMetadata.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">

View File

@@ -105,6 +105,8 @@
<Compile Include="Models\Response\CombinedCommitStatus.cs" />
<Compile Include="Models\Response\CommitContent.cs" />
<Compile Include="Models\Response\GitIgnoreTemplate.cs" />
<Compile Include="Models\Response\License.cs" />
<Compile Include="Models\Response\LicenseMetadata.cs" />
<Compile Include="Models\Response\Merge.cs" />
<Compile Include="Models\Response\ContentType.cs" />
<Compile Include="Models\Response\ApplicationAuthorization.cs" />