Skip to content

Commit acf4b43

Browse files
authored
refactor!: remove json property attributes (#100)
1 parent 406c994 commit acf4b43

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+184
-1228
lines changed

.github/workflows/ci.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
env:
1414
DOTNET_CLI_TELEMETRY_OPTOUT: "true"
15+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "true"
1516
steps:
1617
- uses: actions/checkout@v2
1718
with:
@@ -20,7 +21,7 @@ jobs:
2021
- uses: wagoid/commitlint-github-action@v4
2122

2223
- name: Setup dotnet
23-
uses: actions/setup-dotnet@v1
24+
uses: actions/setup-dotnet@v2
2425
with:
2526
dotnet-version: 6.0.x
2627

.github/workflows/release.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
env:
1515
DOTNET_CLI_TELEMETRY_OPTOUT: "true"
16+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "true"
1617
steps:
1718
- uses: actions/checkout@v2
1819
with:
@@ -30,7 +31,7 @@ jobs:
3031
core.exportVariable('VERSION', version)
3132
3233
- name: Setup dotnet
33-
uses: actions/setup-dotnet@v1
34+
uses: actions/setup-dotnet@v2
3435
with:
3536
dotnet-version: "6.0.x"
3637

.github/workflows/reviewdog.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- uses: reviewdog/action-setup@v1
1717

1818
- name: Setup dotnet
19-
uses: actions/setup-dotnet@v1
19+
uses: actions/setup-dotnet@v2
2020
with:
2121
dotnet-version: 6.0.x
2222

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ messageClient.SendMessageAsync(channel.Type, channel.Id, bob.Id, "Hey, I'm Bob!"
178178

179179
// With custom data
180180
var msgReq = new MessageRequest { Text = "Hi june!" };
181-
msgReq.SetData('location', 'amsterdam');
181+
msgReq.SetData("location", "amsterdam");
182182

183183
var bobMessageResp = await messageClient.SendMessageAsync(channelType, channel.Id, msgReq, bob.Id);
184184

@@ -242,7 +242,7 @@ var junePhone = new Device
242242
{
243243
ID = "iOS Device Token",
244244
PushProvider = PushProvider.APN,
245-
UserID = june.ID
245+
UserId = june.ID
246246
};
247247

248248
await deviceClient.AddDeviceAsync(junePhone);
@@ -268,14 +268,15 @@ while (!complete && iterations < 1000)
268268
if (resp.Status == AsyncTaskStatus.Completed)
269269
{
270270
complete = true;
271+
break;
271272
}
272273
iterations++;
273274
await Task.Delay(100);
274275
}
275276

276277
if (complete)
277278
{
278-
Console.WriteLine(resp.Result.URL);
279+
Console.WriteLine(resp.Result["url"]);
279280
}
280281
```
281282

src/Clients/AppClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public bool VerifyWebhook(string requestBody, string xSignature)
7171
using (var sha = new HMACSHA256(Encoding.UTF8.GetBytes(_apiSecret)))
7272
{
7373
var sigBytes = sha.ComputeHash(Encoding.UTF8.GetBytes(requestBody));
74-
var sig = BitConverter.ToString(sigBytes).Replace("-", string.Empty).ToLower();
74+
var sig = BitConverter.ToString(sigBytes).Replace("-", string.Empty).ToLowerInvariant();
7575
return sig == xSignature;
7676
}
7777
}

src/Clients/ChannelClient.Crud.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public async Task<ChannelGetResponse> GetOrCreateAsync(string channelType, strin
1616
Data = new ChannelRequest
1717
{
1818
CreatedBy = new UserRequest { Id = createdBy },
19-
Members = members.Select(x => new ChannelMember { UserID = x }),
19+
Members = members.Select(x => new ChannelMember { UserId = x }),
2020
},
2121
});
2222

src/Clients/ClientBase.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
using System.Net;
44
using System.Net.Http;
55
using System.Threading.Tasks;
6-
using Newtonsoft.Json;
76
using StreamChat.Exceptions;
87
using StreamChat.Models;
98
using StreamChat.Rest;
9+
using StreamChat.Utils;
1010
using HttpMethod = StreamChat.Rest.HttpMethod;
1111

1212
namespace StreamChat.Clients
@@ -38,7 +38,7 @@ protected async Task<T> ExecuteRequestAsync<T>(
3838

3939
try
4040
{
41-
deserialized = JsonConvert.DeserializeObject<T>(resp.Content);
41+
deserialized = StreamJsonConverter.DeserializeObject<T>(resp.Content);
4242
}
4343
catch (Exception ex)
4444
{

src/Clients/CommandClient.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Generic;
21
using System.Net;
32
using System.Threading.Tasks;
43
using StreamChat.Models;

src/Clients/JwtGeneratorClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public string GenerateJwt(object payload, string apiSecret)
3434
segments.Add(Base64UrlEncode(signature));
3535
}
3636

37-
return string.Join(".", segments.ToArray());
37+
return string.Join(".", segments);
3838
}
3939

4040
private static string Base64UrlEncode(byte[] input)

src/Clients/MessageClient.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
using System.Net;
44
using System.Net.Http;
55
using System.Threading.Tasks;
6-
using Newtonsoft.Json;
76
using StreamChat.Models;
87
using StreamChat.Rest;
8+
using StreamChat.Utils;
99
using HttpMethod = StreamChat.Rest.HttpMethod;
1010

1111
namespace StreamChat.Clients
@@ -135,7 +135,7 @@ public async Task<FileUrlResponse> UploadFileAsync(string channelType, string ch
135135
{
136136
var body = new MultipartFormDataContent();
137137
body.Add(new ByteArrayContent(file), "file", fileName);
138-
body.Add(new StringContent(JsonConvert.SerializeObject(user)), "user");
138+
body.Add(new StringContent(StreamJsonConverter.SerializeObject(user)), "user");
139139

140140
return await ExecuteRequestAsync<FileUrlResponse>($"channels/{channelType}/{channelId}/file",
141141
HttpMethod.POST,
@@ -164,11 +164,11 @@ public async Task<FileUrlResponse> UploadImageAsync(string channelType,
164164
{
165165
var body = new MultipartFormDataContent();
166166
body.Add(new ByteArrayContent(file), "file", fileName);
167-
body.Add(new StringContent(JsonConvert.SerializeObject(user)), "user");
167+
body.Add(new StringContent(StreamJsonConverter.SerializeObject(user)), "user");
168168

169169
if (uploadSizes != null)
170170
{
171-
body.Add(new StringContent(JsonConvert.SerializeObject(uploadSizes)), "upload_sizes");
171+
body.Add(new StringContent(StreamJsonConverter.SerializeObject(uploadSizes)), "upload_sizes");
172172
}
173173

174174
return await ExecuteRequestAsync<FileUrlResponse>($"channels/{channelType}/{channelId}/image",

src/Clients/StreamClientFactory.cs

+3-14
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class StreamClientFactory : IStreamClientFactory
2929
/// Initializes a new instance of the <see cref="StreamClientFactory"/> class.
3030
/// This constructor uses STREAM_KEY and STREAM_SECRET environment
3131
/// variables to initialize the client.
32-
/// If they don't exist, it'll throw an <see cref="ArgumentNullException"/>.
32+
/// If they don't exist, <see cref="ArgumentNullException"/> will be thrown.
3333
/// </summary>
3434
/// <exception cref="ArgumentNullException">If API key or API secret is null.</exception>
3535
public StreamClientFactory() : this(null, null, null)
@@ -67,11 +67,12 @@ public StreamClientFactory(string apiKey, string apiSecret, Action<ClientOptions
6767
var opts = new ClientOptions();
6868
opts.OverrideWithEnvVars();
6969
clientOptionsConfigurer?.Invoke(opts);
70+
opts.EnsureValid();
7071

7172
var jwtGeneratorClient = new JwtGeneratorClient();
7273
var generatedJwt = jwtGeneratorClient.GenerateServerSideJwt(apiSecret);
7374
var assemblyVersion = typeof(StreamClientFactory).GetTypeInfo().Assembly.GetName().Version;
74-
var sdkVersion = string.Join(".", assemblyVersion.Major, assemblyVersion.Minor, assemblyVersion.Build);
75+
var sdkVersion = assemblyVersion.ToString(3);
7576
var restClient = new RestClient(opts, generatedJwt, apiKey, sdkVersion);
7677

7778
_appClient = new AppClient(restClient, apiSecret);
@@ -90,29 +91,17 @@ public StreamClientFactory(string apiKey, string apiSecret, Action<ClientOptions
9091
}
9192

9293
public IAppClient GetAppClient() => _appClient;
93-
9494
public IBlocklistClient GetBlocklistClient() => _blocklistClient;
95-
9695
public IChannelClient GetChannelClient() => _channelClient;
97-
9896
public IChannelTypeClient GetChannelTypeClient() => _channelTypeClient;
99-
10097
public ICommandClient GetCommandClient() => _commandClient;
101-
10298
public IDeviceClient GetDeviceClient() => _deviceClient;
103-
10499
public IEventClient GetEventClient() => _eventClient;
105-
106100
public IFlagClient GetFlagClient() => _flagClient;
107-
108101
public IMessageClient GetMessageClient() => _messageClient;
109-
110102
public IPermissionClient GetPermissionClient() => _permissionClient;
111-
112103
public IReactionClient GetReactionClient() => _reactionClient;
113-
114104
public ITaskClient GetTaskClient() => _taskClient;
115-
116105
public IUserClient GetUserClient() => _userClient;
117106
}
118107
}

src/Clients/UserClient.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
using System.Linq;
44
using System.Net;
55
using System.Threading.Tasks;
6-
using Newtonsoft.Json;
76
using StreamChat.Models;
87
using StreamChat.Rest;
8+
using StreamChat.Utils;
99

1010
namespace StreamChat.Clients
1111
{
@@ -202,7 +202,7 @@ public async Task<QueryUsersResponse> QueryAsync(QueryUserOptions opts)
202202
HttpStatusCode.OK,
203203
queryParams: new List<KeyValuePair<string, string>>
204204
{
205-
new KeyValuePair<string, string>("payload", JsonConvert.SerializeObject(payload)),
205+
new KeyValuePair<string, string>("payload", StreamJsonConverter.SerializeObject(payload)),
206206
});
207207
}
208208
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace StreamChat.Exceptions
2+
{
3+
/// <summary>
4+
/// Thrown when invalid ClientOptions are provided.
5+
/// </summary>
6+
public class InvalidClientOptionsException : StreamBaseException
7+
{
8+
internal InvalidClientOptionsException(string message) : base(message)
9+
{
10+
}
11+
}
12+
}

src/Exceptions/StreamChatException.cs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System;
21
using System.Collections.Generic;
32
using System.Net;
4-
using Newtonsoft.Json;
53
using StreamChat.Models;
64
using StreamChat.Rest;
5+
using StreamChat.Utils;
76

87
namespace StreamChat.Exceptions
98
{
@@ -42,7 +41,7 @@ internal static StreamChatException FromResponse(RestResponse response)
4241

4342
if (!string.IsNullOrWhiteSpace(response.Content))
4443
{
45-
resp = JsonConvert.DeserializeObject<ExceptionResponse>(response.Content);
44+
resp = StreamJsonConverter.DeserializeObject<ExceptionResponse>(response.Content);
4645
resp.HttpStatusCode = response.StatusCode;
4746
}
4847

@@ -58,17 +57,10 @@ internal static StreamChatException FromResponse(RestResponse response)
5857
internal class ExceptionResponse
5958
{
6059
public int Code { get; set; }
61-
6260
public string Message { get; set; }
63-
64-
[JsonProperty("exception_fields")]
6561
public Dictionary<string, string> ExceptionFields { get; set; }
66-
67-
[JsonProperty("more_info")]
6862
public string MoreInfo { get; set; }
69-
7063
public HttpStatusCode HttpStatusCode { get; set; }
71-
7264
public RateLimitsInfo RateLimit { get; set; }
7365
}
7466
}

src/Models/ApiResponse.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,9 @@ public RateLimitsInfo GetRateLimit()
3535
/// </summary>
3636
public bool TryGetRateLimit(out RateLimitsInfo rateLimits)
3737
{
38-
if (_rateLimits == null)
39-
{
40-
rateLimits = null;
41-
return false;
42-
}
43-
4438
rateLimits = _rateLimits;
45-
return true;
39+
40+
return rateLimits != null;
4641
}
4742
}
4843

0 commit comments

Comments
 (0)