Skip to content

Commit 57c8e3a

Browse files
dwybandwyban
authored andcommitted
Correct example in readme to reflect that certain parameters are strings.
Fixed ISStreamer to properly dispose of HttpContent and HttpResponseMessage objects. Bumped build number in Assembly information.
1 parent 2ea117f commit 57c8e3a

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

InitialState.NET/ISStreamer.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -238,22 +238,23 @@ public CreateBucketStatus CreateBucket(string accessKey, string bucketKey, strin
238238
_jsonStrBuilder.Remove(_jsonStrBuilder.Length - 3, 3); // Remove the last ",\r\n"
239239
_jsonStrBuilder.Append("\r\n]");
240240

241-
var response = await sendToApi(_jsonStrBuilder.ToString());
242-
243-
sr.Success = response.StatusCode == System.Net.HttpStatusCode.NoContent;
244-
sr.StatusCode = response.StatusCode;
245-
int.TryParse(response.Headers.GetValues("X-RateLimit-Limit").First(), out sr.RateLimit);
246-
int.TryParse(response.Headers.GetValues("X-RateLimit-Remaining").First(), out sr.RateLimitRemaining);
247-
int.TryParse(response.Headers.GetValues("X-RateLimit-Reset").First(), out int epochTimestamp);
248-
249-
sr.RateLimitReset = _epochDateTime.AddSeconds(epochTimestamp).ToLocalTime();
250-
251-
// Data is sent so clear out the buffer
252-
if (sr.Success)
241+
using (var response = await sendToApi(_jsonStrBuilder.ToString()))
253242
{
254-
this.EventData.Clear();
255-
}
256243

244+
sr.Success = response.StatusCode == System.Net.HttpStatusCode.NoContent;
245+
sr.StatusCode = response.StatusCode;
246+
int.TryParse(response.Headers.GetValues("X-RateLimit-Limit").First(), out sr.RateLimit);
247+
int.TryParse(response.Headers.GetValues("X-RateLimit-Remaining").First(), out sr.RateLimitRemaining);
248+
int.TryParse(response.Headers.GetValues("X-RateLimit-Reset").First(), out int epochTimestamp);
249+
250+
sr.RateLimitReset = _epochDateTime.AddSeconds(epochTimestamp).ToLocalTime();
251+
252+
// Data is sent so clear out the buffer
253+
if (sr.Success)
254+
{
255+
this.EventData.Clear();
256+
}
257+
}
257258
return sr;
258259
}
259260

@@ -272,9 +273,11 @@ public void Close()
272273
//----------------
273274
private async Task<HttpResponseMessage> sendToApi(string jsonData)
274275
{
275-
var response = await _httpClient.PostAsync("events",
276-
new StringContent(jsonData, Encoding.UTF8, "application/json"));
277-
return response;
276+
using (var content = new StringContent(jsonData, Encoding.UTF8, "application/json"))
277+
{
278+
var response = await _httpClient.PostAsync("events", content);
279+
return response;
280+
}
278281
}
279282
private void closeHttpClient()
280283
{

InitialState.NET/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.0.0.0")]
36-
[assembly: AssemblyFileVersion("1.0.0.0")]
35+
[assembly: AssemblyVersion("1.0.0.1")]
36+
[assembly: AssemblyFileVersion("1.0.0.1")]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ The following example shows you basic use of InitialState<nolink/>.NET. This ex
88

99
```csharp
1010
ISStreamer stream = new ISStreamer(); // Create a new streamer
11-
stream.ConnectBucket(api_key, bucket_key); // Connect the streamer to an event data bucket
12-
stream.Eventsdata.Add(new ISEventData(itemKey, itemValue)) // Add event data to be streamed
11+
stream.ConnectBucket("api_key", "bucket_key"); // Connect the streamer to an event data bucket
12+
stream.Eventsdata.Add(new ISEventData("itemKey", "itemValue")) // Add event data to be streamed
1313
stream.Stream(); // Stream the event data to Initial State
1414
stream.Close(); // Close the streamer when finished
1515
```

0 commit comments

Comments
 (0)