diff --git a/src/Gitee.Api/Dto/CreateRepo.cs b/src/Gitee.Api/Dto/CreateRepo.cs
index 89e470634c857ae71b6732253c483cfb0bbb9e23..c235dd0f0c706202e9358bcc44d8b820f7429714 100644
--- a/src/Gitee.Api/Dto/CreateRepo.cs
+++ b/src/Gitee.Api/Dto/CreateRepo.cs
@@ -9,42 +9,51 @@ namespace Gitee.Api.Dto
public class CreateRepo
{
///
- ///
+ ///
///
public string access_token { get; set; }
+
///
- ///
+ ///
///
public string name { get; set; }
+
///
- ///
+ ///
///
public string description { get; set; }
+
///
- ///
+ ///
///
public string homepage { get; set; }
+
///
- ///
+ ///
///
public bool has_issues { get; set; }
+
///
- ///
+ ///
///
public bool has_wiki { get; set; }
+
///
- ///
+ ///
///
public bool auto_init { get; set; }
+
///
- ///
+ ///
///
public string gitignore_template { get; set; }
+
///
- ///
+ ///
///
public string license_template { get; set; }
+
[Newtonsoft.Json.JsonProperty("private")]
public bool IsPrivate { get; set; }
-}
-}
+ }
+}
\ No newline at end of file
diff --git a/src/Gitee.Api/Dto/GiteeApiException.cs b/src/Gitee.Api/Dto/GiteeApiException.cs
index e960344f0cde4ce06c9cf3f9090858cc4263ce1f..ea33f291146fce63fd2c50f50038921dbf7de5ab 100644
--- a/src/Gitee.Api/Dto/GiteeApiException.cs
+++ b/src/Gitee.Api/Dto/GiteeApiException.cs
@@ -6,35 +6,39 @@ using System.Threading.Tasks;
namespace Gitee.Api.Dto
{
-
public class GiteeApiException : Exception
{
- public GiteeApiException() { }
+ public GiteeApiException()
+ {
+ }
+
public GiteeApiException(ApiError error) : base(error.error_description)
{
ApiError = error;
-
}
+
public GiteeApiException(ApiError error, Exception inner) : base(error.error_description, inner)
{
ApiError = error;
}
+
public GiteeApiException(string message, Exception inner) : base(message, inner)
{
-
}
+
public ApiError ApiError { get; private set; }
}
public class ApiError
{
///
- ///
+ ///
///
public string error { get; set; }
+
///
/// 授权方式无效,或者登录回调地址无效、过期或已被撤销
///
public string error_description { get; set; }
}
-}
+}
\ No newline at end of file
diff --git a/src/Gitee.Api/Dto/TokenDto.cs b/src/Gitee.Api/Dto/TokenDto.cs
index cfcc1db64e1a31dc8e4a604458ebc80347596389..5c57752c80429b7295fdd1db2be6bcb8d2587b45 100644
--- a/src/Gitee.Api/Dto/TokenDto.cs
+++ b/src/Gitee.Api/Dto/TokenDto.cs
@@ -9,30 +9,35 @@ namespace Gitee.Api.Dto
public class TokenDto
{
///
- ///
+ ///
///
public string access_token { get; set; }
+
///
- ///
+ ///
///
public string token_type { get; set; }
+
///
- ///
+ ///
///
public int expires_in { get; set; }
public DateTime Expires => DateTime.Now.AddSeconds(expires_in);
+
///
- ///
+ ///
///
public string refresh_token { get; set; }
+
///
- ///
+ ///
///
public string scope { get; set; }
+
///
- ///
+ ///
///
public int created_at { get; set; }
}
-}
+}
\ No newline at end of file
diff --git a/src/Gitee.Api/Gitee.Api.csproj b/src/Gitee.Api/Gitee.Api.csproj
index 58ae8d48e42094d47961fa6ad41785466c61627b..e8e570f2ca9c8053ad03355bb6b0cd2ec86d321a 100644
--- a/src/Gitee.Api/Gitee.Api.csproj
+++ b/src/Gitee.Api/Gitee.Api.csproj
@@ -2,6 +2,15 @@
net461;netstandard2.0
+ https://gitee.com/GitGroup/Gitee.VisualStudio/tree/master/src/Gitee.Api
+ https://gitee.com/logo_icon.png
+ https://gitee.com/GitGroup/Gitee.VisualStudio
+ https://gitee.com/GitGroup/Gitee.VisualStudio/raw/master/LICENSE
+ gitee.com 的.Net SDK
+ gitee,git
+ maikebing
+ Gitee.com
+ true
diff --git a/src/Gitee.Api/SDK.cs b/src/Gitee.Api/SDK.cs
index e5345629516c079321ac4c5ab514daedd1ba7b01..0c512015ab5425189561d7b14ea708d59c3c0407 100644
--- a/src/Gitee.Api/SDK.cs
+++ b/src/Gitee.Api/SDK.cs
@@ -13,8 +13,8 @@ namespace Gitee.Api
{
public static class SDK
{
- public static string client_id { get; set; }
- public static string client_secret { get; set; }
+ public static string client_id { get; set; }
+ public static string client_secret { get; set; }
public static Task GetUserAsync(this Session session) => session.Client.GetV5UserAsync(session.Token.access_token);
@@ -24,12 +24,13 @@ namespace Gitee.Api
///
///
///
- public static Task> GetReposAsync(this Session session,int page,int per_page=20)
+ public static Task> GetReposAsync(this Session session, int page, int per_page = 20)
{
- return Request>(session, "v5/user/repos", new { sort = "full_name", page , per_page });
+ return Request>(session, "v5/user/repos", new { sort = "full_name", page, per_page });
}
+
///
- ///
+ ///
///
///
///
@@ -37,21 +38,22 @@ namespace Gitee.Api
///
///
///
- public static async Task CreateRepoAsync(this Session session, string name, string description,bool isPrivate)
+ public static async Task CreateRepoAsync(this Session session, string name, string description, bool isPrivate)
{
- return await Request(session, "v5/user/repos", new CreateRepo() { access_token= session.Token.access_token, description=description, has_issues=true, has_wiki=true, IsPrivate=isPrivate, name=name } ,Method.POST,true);
+ return await Request(session, "v5/user/repos", new CreateRepo() { access_token = session.Token.access_token, description = description, has_issues = true, has_wiki = true, IsPrivate = isPrivate, name = name }, Method.POST, true);
}
- ///
- /// 此请求方法主要用来弥补自动生成的部分api无法正常使用,使用RestSharp重新实现, 在未来,可能完全取消自动生成部分
- ///
- ///
- /// 会话必要信息
- /// 请求资源连接字符串
- /// 参数类, 根据来决定处理为json还是query条件
- /// Http方法,默认GET
- /// Gitee大部分api是作为Query传送的,只有少数是 json,因此默认为false
- ///
- public static async Task Request(this Session session, string resource, object parameters, Method method = Method.GET,bool paramAsJson=false) where T : class
+
+ ///
+ /// 此请求方法主要用来弥补自动生成的部分api无法正常使用,使用RestSharp重新实现, 在未来,可能完全取消自动生成部分
+ ///
+ ///
+ /// 会话必要信息
+ /// 请求资源连接字符串
+ /// 参数类, 根据来决定处理为json还是query条件
+ /// Http方法,默认GET
+ /// Gitee大部分api是作为Query传送的,只有少数是 json,因此默认为false
+ ///
+ public static async Task Request(this Session session, string resource, object parameters, Method method = Method.GET, bool paramAsJson = false) where T : class
{
T result = default(T);
try
@@ -73,7 +75,7 @@ namespace Gitee.Api
}
}
var response = await new RestClient(session.BaseURL).ExecuteTaskAsync(request);
- if ((response.StatusCode == HttpStatusCode.OK || response.StatusCode== HttpStatusCode.Created || response.StatusCode == HttpStatusCode.Accepted) && !string.IsNullOrEmpty(response.Content))
+ if ((response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Created || response.StatusCode == HttpStatusCode.Accepted) && !string.IsNullOrEmpty(response.Content))
{
var jtk = Newtonsoft.Json.Linq.JToken.Parse(response.Content);
result = jtk.ToObject();
@@ -103,14 +105,14 @@ namespace Gitee.Api
public static async Task LoginAsync(string username, string password)
{
var _session = new Session();
- _session.Token = await _session.Request("../oauth/token", new { grant_type = "password", username, password, client_id, client_secret, scope = "projects user_info issues notes" }, Method.POST);
+ _session.Token = await _session.Request("../oauth/token", new { grant_type = "password", username, password, client_id, client_secret, scope = "projects user_info issues notes" }, Method.POST);
_session.Client = new Client(new HttpClient());
_session.Client.BaseUrl = _session.BaseURL;
return _session;
-
}
+
///
- ///
+ ///
///
///
///
@@ -118,11 +120,12 @@ namespace Gitee.Api
public static async Task RefreshToken(string refresh_token)
{
var _session = new Session();
- _session.Token = await _session.Request("../oauth/token", new { grant_type = "refresh_token", refresh_token}, Method.POST);
+ _session.Token = await _session.Request("../oauth/token", new { grant_type = "refresh_token", refresh_token }, Method.POST);
_session.Client = new Client(new HttpClient());
_session.Client.BaseUrl = _session.BaseURL;
return _session;
}
+
///
/// 根据缓存的 token信息继续使用, 如果没过期的话
///
diff --git a/src/Gitee.Api/Session.cs b/src/Gitee.Api/Session.cs
index 2671b555c75ddca3ee2a2808c03e8498d76210d6..b7943e582a8ff43edc7961359f66bab7130863e0 100644
--- a/src/Gitee.Api/Session.cs
+++ b/src/Gitee.Api/Session.cs
@@ -12,5 +12,5 @@ namespace Gitee.Api
public string BaseURL { get; private set; } = "https://gitee.com/api";
public Client Client { get; set; } = null;
public TokenDto Token { get; set; } = null;
- }
-}
+ }
+}
\ No newline at end of file