Skip to content

Commit 1bb4025

Browse files
committed
Primary constructors
1 parent 2e3d98e commit 1bb4025

26 files changed

+86
-163
lines changed

SlackNet/Blocks/Block.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
namespace SlackNet.Blocks;
22

3-
public abstract class Block
3+
public abstract class Block(string type)
44
{
5-
protected Block(string type) => Type = type;
6-
7-
public string Type { get; }
5+
public string Type { get; } = type;
86

97
/// <summary>
108
/// A string acting as a unique identifier for a block. You can use this when you receive an interaction payload

SlackNet/Blocks/Button.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
/// An interactive element that inserts a button. The button can be a trigger for anything from opening a simple link to starting a complex workflow.
55
/// </summary>
66
[SlackType("button")]
7-
public class Button : ActionElement
7+
public class Button() : ActionElement("button")
88
{
9-
public Button() : base("button") { }
10-
119
/// <summary>
1210
/// A text object that defines the button's text.
1311
/// </summary>

SlackNet/Interaction/Button.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
namespace SlackNet.Interaction;
22

3-
public class Button : ActionElement
3+
public class Button() : ActionElement("button")
44
{
5-
public Button() : base("button") { }
6-
75
public Style Style { get; set; }
86
public string Url { get; set; }
97
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
namespace SlackNet;
22

3-
public class ConfigurationModalViewDefinition : ViewDefinition
4-
{
5-
public ConfigurationModalViewDefinition() : base("workflow_step") { }
6-
}
3+
public class ConfigurationModalViewDefinition() : ViewDefinition("workflow_step");

SlackNet/Objects/ViewDefinition.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
namespace SlackNet;
66

7-
public abstract class ViewDefinition
7+
public abstract class ViewDefinition(string type)
88
{
9-
protected ViewDefinition(string type) => Type = type;
10-
11-
public string Type { get; set; }
9+
public string Type { get; set; } = type;
1210

1311
/// <summary>
1412
/// A list of blocks that defines the content of the view.

SlackNet/SlackUrlBuilder.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ public interface ISlackUrlBuilder
1212
string Url(string apiMethod, Args args);
1313
}
1414

15-
class SlackUrlBuilder : ISlackUrlBuilder
15+
class SlackUrlBuilder(SlackJsonSettings jsonSettings) : ISlackUrlBuilder
1616
{
17-
private readonly SlackJsonSettings _jsonSettings;
18-
public SlackUrlBuilder(SlackJsonSettings jsonSettings) => _jsonSettings = jsonSettings;
19-
2017
public string Url(string apiMethod, Args args) =>
2118
$"https://slack.com/api/{apiMethod}{Query(args)}";
2219

@@ -41,5 +38,5 @@ private string SerializeEnumerable(IEnumerable enumerable) =>
4138
string.Join(",", enumerable.Cast<object>().Select(SerializeObject));
4239

4340
private string SerializeObject(object value) =>
44-
JsonConvert.SerializeObject(value, _jsonSettings.SerializerSettings).Trim('"');
41+
JsonConvert.SerializeObject(value, jsonSettings.SerializerSettings).Trim('"');
4542
}

SlackNet/WebApi/ApiApi.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,11 @@ public interface IApiApi
2121
Task<IReadOnlyDictionary<string, string>> Test(string error, Args args, CancellationToken cancellationToken = default);
2222
}
2323

24-
public class ApiApi : IApiApi
24+
public class ApiApi(ISlackApiClient client) : IApiApi
2525
{
26-
private readonly ISlackApiClient _client;
27-
public ApiApi(ISlackApiClient client) => _client = client;
28-
2926
public async Task<IReadOnlyDictionary<string, string>> Test(string error, Args args, CancellationToken cancellationToken = default)
3027
{
3128
var query = new Args(args) { ["error"] = error };
32-
return (await _client.Post<TestResponse>("api.test", query, cancellationToken).ConfigureAwait(false)).Args;
29+
return (await client.Post<TestResponse>("api.test", query, cancellationToken).ConfigureAwait(false)).Args;
3330
}
3431
}

SlackNet/WebApi/AppsEventAuthorizationsApi.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,15 @@ Task<AppsEventsAuthorizationsListResponse> List(
2525
CancellationToken cancellationToken = default);
2626
}
2727

28-
public class AppsEventAuthorizationsApi : IAppsEventAuthorizationsApi
28+
public class AppsEventAuthorizationsApi(ISlackApiClient client) : IAppsEventAuthorizationsApi
2929
{
30-
private readonly ISlackApiClient _client;
31-
public AppsEventAuthorizationsApi(ISlackApiClient client) => _client = client;
32-
3330
public Task<AppsEventsAuthorizationsListResponse> List(
3431
string eventContext,
3532
int limit = 100,
3633
string cursor = null,
3734
CancellationToken cancellationToken = default
3835
) =>
39-
_client.Post<AppsEventsAuthorizationsListResponse>("apps.event.authorizations.list", new Args
36+
client.Post<AppsEventsAuthorizationsListResponse>("apps.event.authorizations.list", new Args
4037
{
4138
{ "event_context", eventContext },
4239
{ "cursor", cursor },

SlackNet/WebApi/AuthApi.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,16 @@ public interface IAuthApi
3434
Task<AuthTeamsListResponse> TeamsList(string cursor = null, bool includeIcon = false, int limit = 100, CancellationToken cancellationToken = default);
3535
}
3636

37-
public class AuthApi : IAuthApi
37+
public class AuthApi(ISlackApiClient client) : IAuthApi
3838
{
39-
private readonly ISlackApiClient _client;
40-
public AuthApi(ISlackApiClient client) => _client = client;
41-
4239
public async Task<bool> Revoke(bool test, CancellationToken cancellationToken = default) =>
43-
(await _client.Get<RevokeResponse>("auth.revoke", new Args { { "test", test } }, cancellationToken).ConfigureAwait(false)).Revoked;
40+
(await client.Get<RevokeResponse>("auth.revoke", new Args { { "test", test } }, cancellationToken).ConfigureAwait(false)).Revoked;
4441

4542
public Task<AuthTestResponse> Test(CancellationToken cancellationToken = default) =>
46-
_client.Post<AuthTestResponse>("auth.test", new Args(), cancellationToken);
43+
client.Post<AuthTestResponse>("auth.test", new Args(), cancellationToken);
4744

4845
public Task<AuthTeamsListResponse> TeamsList(string cursor = null, bool includeIcon = false, int limit = 100, CancellationToken cancellationToken = default) =>
49-
_client.Get<AuthTeamsListResponse>("auth.teams.list", new Args
46+
client.Get<AuthTeamsListResponse>("auth.teams.list", new Args
5047
{
5148
{ "cursor", cursor },
5249
{ "include_icon", includeIcon },

SlackNet/WebApi/ChatApi.cs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -145,45 +145,36 @@ Task Unfurl(
145145
Task<PermalinkResponse> GetPermalink(string channelId, string messageTs, CancellationToken cancellationToken = default);
146146
}
147147

148-
public class ChatApi : IChatApi
148+
public class ChatApi(ISlackApiClient client, SlackJsonSettings jsonSettings) : IChatApi
149149
{
150-
private readonly ISlackApiClient _client;
151-
private readonly SlackJsonSettings _jsonSettings;
152-
153-
public ChatApi(ISlackApiClient client, SlackJsonSettings jsonSettings)
154-
{
155-
_client = client;
156-
_jsonSettings = jsonSettings;
157-
}
158-
159150
public Task<MessageTsResponse> Delete(string ts, string channelId, bool asUser = false, CancellationToken cancellationToken = default) =>
160-
_client.Post<MessageTsResponse>("chat.delete", new Args
151+
client.Post<MessageTsResponse>("chat.delete", new Args
161152
{
162153
{ "ts", ts },
163154
{ "channel", channelId },
164155
{ "as_user", asUser }
165156
}, cancellationToken);
166157

167158
public Task<PermalinkResponse> GetPermalink(string channelId, string messageTs, CancellationToken cancellationToken = default) =>
168-
_client.Get<PermalinkResponse>("chat.getPermalink", new Args
159+
client.Get<PermalinkResponse>("chat.getPermalink", new Args
169160
{
170161
{ "channel", channelId },
171162
{ "message_ts", messageTs }
172163
}, cancellationToken);
173164

174165
public Task<MessageTsResponse> MeMessage(string channel, string text, CancellationToken cancellationToken = default) =>
175-
_client.Post<MessageTsResponse>("chat.meMessage", new Args
166+
client.Post<MessageTsResponse>("chat.meMessage", new Args
176167
{
177168
{ "channel", channel },
178169
{ "text", text }
179170
}, cancellationToken);
180171

181172
public Task<PostMessageResponse> PostMessage(Message message, CancellationToken cancellationToken = default) =>
182-
_client.Post<PostMessageResponse>("chat.postMessage", PopulateMessageArgs(message, new Args()),
173+
client.Post<PostMessageResponse>("chat.postMessage", PopulateMessageArgs(message, new Args()),
183174
cancellationToken);
184175

185176
public Task<ScheduleMessageResponse> ScheduleMessage(Message message, DateTime postAt, CancellationToken cancellationToken = default) =>
186-
_client.Post<ScheduleMessageResponse>("chat.scheduleMessage", PopulateMessageArgs(message, new Args
177+
client.Post<ScheduleMessageResponse>("chat.scheduleMessage", PopulateMessageArgs(message, new Args
187178
{
188179
{ "post_at", postAt.ToTimestamp() }
189180
}),
@@ -205,12 +196,12 @@ private Args PopulateMessageArgs(Message message, Args args)
205196
args["icon_emoji"] = message.IconEmoji;
206197
args["thread_ts"] = message.ThreadTs;
207198
args["reply_broadcast"] = message.ReplyBroadcast;
208-
args["metadata"] = message.MetadataJson ?? MessageMetadata.FromObject(message.MetadataObject, _jsonSettings);
199+
args["metadata"] = message.MetadataJson ?? MessageMetadata.FromObject(message.MetadataObject, jsonSettings);
209200
return args;
210201
}
211202

212203
public Task DeleteScheduledMessage(string messageId, string channelId, bool? asUser = null, CancellationToken cancellationToken = default) =>
213-
_client.Post("chat.deleteScheduledMessage", new Args
204+
client.Post("chat.deleteScheduledMessage", new Args
214205
{
215206
{ "scheduled_message_id", messageId },
216207
{ "channel", channelId },
@@ -219,7 +210,7 @@ public Task DeleteScheduledMessage(string messageId, string channelId, bool? asU
219210
cancellationToken);
220211

221212
public Task<PostEphemeralResponse> PostEphemeral(string userId, Message message, CancellationToken cancellationToken = default) =>
222-
_client.Post<PostEphemeralResponse>("chat.postEphemeral", new Args
213+
client.Post<PostEphemeralResponse>("chat.postEphemeral", new Args
223214
{
224215
{ "channel", message.Channel },
225216
{ "text", message.Text },
@@ -243,7 +234,7 @@ public Task Unfurl(
243234
string userAuthUrl = null,
244235
CancellationToken cancellationToken = default
245236
) =>
246-
_client.Post("chat.unfurl", new Args
237+
client.Post("chat.unfurl", new Args
247238
{
248239
{ "channel", channelId },
249240
{ "ts", ts },
@@ -264,7 +255,7 @@ public Task Unfurl(
264255
string userAuthUrl = null,
265256
CancellationToken cancellationToken = default
266257
) =>
267-
_client.Post("chat.unfurl", new Args
258+
client.Post("chat.unfurl", new Args
268259
{
269260
{ "source", source },
270261
{ "unfurl_id", unfurlId },
@@ -276,7 +267,7 @@ public Task Unfurl(
276267
}, cancellationToken);
277268

278269
public Task<MessageUpdateResponse> Update(MessageUpdate messageUpdate, CancellationToken cancellationToken = default) =>
279-
_client.Post<MessageUpdateResponse>("chat.update", new Args
270+
client.Post<MessageUpdateResponse>("chat.update", new Args
280271
{
281272
{ "ts", messageUpdate.Ts },
282273
{ "channel", messageUpdate.ChannelId },

0 commit comments

Comments
 (0)