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

Cleanup format #49

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,8 @@ csharp_style_expression_bodied_properties = when_on_single_line:warning
csharp_style_implicit_object_creation_when_type_is_apparent = false
# 変数宣言をインライン化する
csharp_style_inlined_variable_declaration = true:warning
# 名前空間宣言をブロックスコープにする
csharp_style_namespace_declarations = block_scoped:silent
# 名前空間宣言をファイルスコープにする
csharp_style_namespace_declarations = file_scoped:warning
# パターンローカル変数を使用する
csharp_style_pattern_local_over_anonymous_function = true:warning
# nullチェックを伴うas演算子よりもパターンマッチングを使用する
Expand Down
11 changes: 5 additions & 6 deletions SharpChatwork.Test/src/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using SharpChatwork.Query;

namespace SharpChatwork.Test
namespace SharpChatwork.Test;

public class UnitTest1
{
public class UnitTest1
[Fact]
public void Test1()
{
[Fact]
public void Test1()
{
}
}
}
45 changes: 22 additions & 23 deletions SharpChatwork/src/Attribute/EnumAliasAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
using System;
using System.Linq;

namespace SharpChatwork
namespace SharpChatwork;

[AttributeUsage(AttributeTargets.Field)]
internal sealed class EnumAliasAttribute : Attribute
{
[AttributeUsage(AttributeTargets.Field)]
internal sealed class EnumAliasAttribute : Attribute
public EnumAliasAttribute(string aliasName)
{
public string AliasName { get; set; }
public EnumAliasAttribute(string aliasName)
{
this.AliasName = aliasName;
}
this.AliasName = aliasName;
}
internal static class EnumAliasExtension
public string AliasName { get; set; }
}

internal static class EnumAliasExtension
{
public static string ToAliasOrDefault(this Enum value)
{
public static string ToAliasOrDefault(this Enum value)
{
var i = value.GetType()
.GetField(value.ToString())
.GetCustomAttributes(typeof(EnumAliasAttribute), false)
.Cast<EnumAliasAttribute>()
.FirstOrDefault();
var i = value.GetType()
.GetField(value.ToString())
.GetCustomAttributes(typeof(EnumAliasAttribute), false)
.Cast<EnumAliasAttribute>()
.FirstOrDefault();

// use default name
if(i == null)
return Enum.GetName(value.GetType(), value);
// use alias
else
return i.AliasName;
}
// use default name
if(i == null)
return Enum.GetName(value.GetType(), value);
// use alias
return i.AliasName;
}
}
56 changes: 27 additions & 29 deletions SharpChatwork/src/Client/AccessToken/AccessTokenClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,38 @@
using System.Threading;
using System.Threading.Tasks;

namespace SharpChatwork.AccessToken
namespace SharpChatwork.AccessToken;

public class AccessTokenClient(string accessToken, HttpMessageInvoker messageInvoker = null) : ChatworkClient
{
public class AccessTokenClient(string accessToken, HttpMessageInvoker messageInvoker = null) : ChatworkClient
{
public override string clientName => nameof(AccessTokenClient);
private readonly HttpMessageInvoker _messageInvoker = messageInvoker ?? new HttpClient();
private readonly HttpMessageInvoker _messageInvoker = messageInvoker ?? new HttpClient();
public override string clientName => nameof(AccessTokenClient);

private string accessToken { get; } = accessToken;
private string accessToken { get; } = accessToken;

private HttpRequestMessage GenerateRequestMessage(Uri uri, HttpMethod method)
private HttpRequestMessage GenerateRequestMessage(Uri uri, HttpMethod method)
{
var request = new HttpRequestMessage
{
var request = new HttpRequestMessage
{
Method = method,
RequestUri = uri,
};
request.Headers.Add("X-ChatWorkToken", this.accessToken);
return request;
}
Method = method,
RequestUri = uri,
};
request.Headers.Add("X-ChatWorkToken", this.accessToken);
return request;
}

public override async ValueTask<ResponseWrapper> QueryAsync(Uri uri, HttpMethod method, HttpContent content, CancellationToken cancellation = default)
public override async ValueTask<ResponseWrapper> QueryAsync(Uri uri, HttpMethod method, HttpContent content, CancellationToken cancellation = default)
{
var requestMessage = this.GenerateRequestMessage(uri, method);
requestMessage.Content = content;
var client = this._messageInvoker;
var result = await client.SendAsync(requestMessage, cancellation);
var code = (int)result.StatusCode;
return new ResponseWrapper
{
var requestMessage = this.GenerateRequestMessage(uri, method);
requestMessage.Content = content;
var client = this._messageInvoker;
var result = await client.SendAsync(requestMessage, cancellation);
var code = (int)result.StatusCode;

return new ResponseWrapper
{
content = await result.Content.ReadAsStringAsync(),
headers = result.Headers.ToDictionary(m => m.Key, m => m.Value),
statusCode = code,
};
}
content = await result.Content.ReadAsStringAsync(),
headers = result.Headers.ToDictionary(m => m.Key, m => m.Value),
statusCode = code,
};
}
}
43 changes: 21 additions & 22 deletions SharpChatwork/src/Client/ChatworkQueryError.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
using System.Text.Json.Serialization;

namespace SharpChatwork
namespace SharpChatwork;

internal sealed class ChatworkQueryError
{
internal sealed class ChatworkQueryError
{
public int statusCode { get; set; }
public string jsonBody { get; set; }
public int statusCode { get; set; }
public string jsonBody { get; set; }

/// <summary>
/// 一定期間におけるAPIの最大利用回数
/// </summary>
[JsonPropertyName("x-ratelimit-limit")]
public int rateLimitLimit { get; set; }
/// <summary>
/// 一定期間におけるAPIの残り利用回数
/// </summary>
[JsonPropertyName("x-ratelimit-remaining")]
public int rateLimitRemaining { get; set; }
/// <summary>
/// API利用回数制限が次にリセットされる時間。
/// Unix時間(秒)で示されます。
/// </summary>
[JsonPropertyName("x-ratelimit-reset")]
public int rateLimitReset { get; set; }
}
/// <summary>
/// 一定期間におけるAPIの最大利用回数
/// </summary>
[JsonPropertyName("x-ratelimit-limit")]
public int rateLimitLimit { get; set; }
/// <summary>
/// 一定期間におけるAPIの残り利用回数
/// </summary>
[JsonPropertyName("x-ratelimit-remaining")]
public int rateLimitRemaining { get; set; }
/// <summary>
/// API利用回数制限が次にリセットされる時間。
/// Unix時間(秒)で示されます。
/// </summary>
[JsonPropertyName("x-ratelimit-reset")]
public int rateLimitReset { get; set; }
}
117 changes: 58 additions & 59 deletions SharpChatwork/src/Client/EndPoints.cs
Original file line number Diff line number Diff line change
@@ -1,76 +1,75 @@
using System;

namespace SharpChatwork
namespace SharpChatwork;

public class EndPoints
{
public class EndPoints
{
public static readonly Uri Token = new Uri($@"https://oauth.chatwork.com/token");
public static readonly Uri Oauth2 = new Uri($@"https://www.chatwork.com/packages/oauth2/login.php");
public static readonly Uri Me = new Uri($@"https://api.chatwork.com/v2/me");
public static readonly Uri MyStatus = new Uri($@"https://api.chatwork.com/v2/my/status");
public static readonly Uri MyTasks = new Uri($@"https://api.chatwork.com/v2/my/tasks");
public static readonly Uri Rooms = new Uri($@"https://api.chatwork.com/v2/Rooms");
public static readonly Uri Contacts = new Uri($@"https://api.chatwork.com/v2/contacts");
public static readonly Uri IncomingRequests = new Uri($@"https://api.chatwork.com/v2/incoming_requests");
public static readonly Uri Token = new Uri(@"https://oauth.chatwork.com/token");
public static readonly Uri Oauth2 = new Uri(@"https://www.chatwork.com/packages/oauth2/login.php");
public static readonly Uri Me = new Uri(@"https://api.chatwork.com/v2/me");
public static readonly Uri MyStatus = new Uri(@"https://api.chatwork.com/v2/my/status");
public static readonly Uri MyTasks = new Uri(@"https://api.chatwork.com/v2/my/tasks");
public static readonly Uri Rooms = new Uri(@"https://api.chatwork.com/v2/Rooms");
public static readonly Uri Contacts = new Uri(@"https://api.chatwork.com/v2/contacts");
public static readonly Uri IncomingRequests = new Uri(@"https://api.chatwork.com/v2/incoming_requests");

public static Uri RoomOf(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}");
}
public static Uri RoomOf(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}");
}

public static Uri RoomMember(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/members");
}
public static Uri RoomMember(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/members");
}

public static Uri RoomMessages(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/messages");
}
public static Uri RoomMessages(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/messages");
}

public static Uri RoomMessagesOf(long roomId, long messageId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/messages/{messageId}");
}
public static Uri RoomMessagesOf(long roomId, long messageId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/messages/{messageId}");
}

public static Uri RoomMessagesRead(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/messages/read");
}
public static Uri RoomMessagesRead(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/messages/read");
}

public static Uri RoomMessagesUnread(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/messages/unread");
}
public static Uri RoomMessagesUnread(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/messages/unread");
}

public static Uri RoomTasks(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/tasks");
}
public static Uri RoomTasks(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/tasks");
}

public static Uri RoomTasksOf(long roomId, long taskId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/tasks/{taskId}");
}
public static Uri RoomTasksOf(long roomId, long taskId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/tasks/{taskId}");
}

public static Uri RoomFiles(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/files");
}
public static Uri RoomFiles(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/files");
}

public static Uri RoomFilesOf(long roomId, long fileId)
{
return new Uri($@"https://api.chatwork.com/v 2/rooms/{roomId}/files/{fileId}");
}
public static Uri RoomFilesOf(long roomId, long fileId)
{
return new Uri($@"https://api.chatwork.com/v 2/rooms/{roomId}/files/{fileId}");
}

public static Uri RoomLink(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/link");
}
public static Uri RoomLink(long roomId)
{
return new Uri($@"https://api.chatwork.com/v2/rooms/{roomId}/link");
}

public static Uri IncomingRequestsOf(long requestId)
{
return new Uri($@"https://api.chatwork.com/v2/incoming_requests/{requestId}");
}
public static Uri IncomingRequestsOf(long requestId)
{
return new Uri($@"https://api.chatwork.com/v2/incoming_requests/{requestId}");
}
}
10 changes: 4 additions & 6 deletions SharpChatwork/src/Client/Exceptions/ChatworkClientException.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using System.Runtime.Serialization;

namespace SharpChatwork.Client.Exceptions
namespace SharpChatwork.Client.Exceptions;

public class ChatworkClientException(ResponseWrapper response) : Exception
{
public class ChatworkClientException(ResponseWrapper response) : Exception
{
public readonly ResponseWrapper response = response;
}
public readonly ResponseWrapper response = response;

Check warning on line 7 in SharpChatwork/src/Client/Exceptions/ChatworkClientException.cs

View workflow job for this annotation

GitHub Actions / build

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)

Check warning on line 7 in SharpChatwork/src/Client/Exceptions/ChatworkClientException.cs

View workflow job for this annotation

GitHub Actions / build

Do not declare visible instance fields (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1051)
}
Loading
Loading