Skip to content
Open
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
102 changes: 51 additions & 51 deletions RollbarDotNet/RollbarClient.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace RollbarDotNet
{
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace RollbarDotNet
{
public class RollbarClient : IRollbarClient
{
public RollbarConfig Config { get; }
Expand All @@ -19,76 +19,76 @@ public async Task<Guid> PostItemAsync(Payload payload)
{
var stringResult = await SendPostAsync("item/", payload);
return ParseResponse(stringResult);
}

public Guid PostItem(Payload payload)
{
var stringResult = SendPost("item/", payload);
return ParseResponse(stringResult);
}
public Guid PostItem(Payload payload)
{
var stringResult = SendPost("item/", payload);
return ParseResponse(stringResult);
}

static Guid ParseResponse(string stringResult)
{
try
{
try
{
if (string.IsNullOrEmpty(stringResult))
return Guid.Empty;

var response = JsonConvert.DeserializeObject<RollbarResponse>(stringResult);
if (response.Error > 0 || response.Result == null)
{
Debug.WriteLine("[RollbarDotNet] Unable to deserialize the response of the request.");
Debug.WriteLine("[RollbarDotNet] Unable to deserialize the response of the request.\nResponse:" + stringResult);
return Guid.Empty;
}

Guid uuid;
if (Guid.TryParse(response.Result.Uuid, out uuid))
return uuid;

return Guid.Empty;
}
catch (Exception ex)
{
Debug.WriteLine("[RollbarDotNet] Unable to parse the response of the request.");
Debug.WriteLine(ex);
return Guid.Empty;
return Guid.Empty;
}
catch (Exception ex)
{
Debug.WriteLine("[RollbarDotNet] Unable to parse the response of the request.\nResponse:" + stringResult);
Debug.WriteLine(ex);
return Guid.Empty;
}
}

async Task<string> SendPostAsync<T>(string url, T payload)
{
try
{
try
{
var httpClient = new HttpClient();
httpClient.BaseAddress = (new Uri(Config.EndPoint));
httpClient.BaseAddress = (new Uri(Config.EndPoint));

var result = await httpClient.PostAsync(url, new StringContent(JsonConvert.SerializeObject(payload)));
return await result.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
Debug.WriteLine("[RollbarDotNet] The request sent to the api failed.");
Debug.WriteLine(ex);
return string.Empty;
return await result.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
Debug.WriteLine("[RollbarDotNet] The request sent to the api failed.\nUrl:" + url);
Debug.WriteLine(ex);
return string.Empty;
}
}

string SendPost<T>(string url, T payload)
{
try
{
var httpClient = new HttpClient();
httpClient.BaseAddress = (new Uri(Config.EndPoint));

var result = httpClient.PostAsync(url, new StringContent(JsonConvert.SerializeObject(payload))).Result;
return result.Content.ReadAsStringAsync().Result;
}
catch (Exception ex)
{
Debug.WriteLine("[RollbarDotNet] The request sent to the api failed.");
Debug.WriteLine(ex);
return string.Empty;
}
string SendPost<T>(string url, T payload)
{
try
{
var httpClient = new HttpClient();
httpClient.BaseAddress = (new Uri(Config.EndPoint));
var result = httpClient.PostAsync(url, new StringContent(JsonConvert.SerializeObject(payload))).Result;
return result.Content.ReadAsStringAsync().Result;
}
catch (Exception ex)
{
Debug.WriteLine("[RollbarDotNet] The request sent to the api failed.\nUrl:" + url);
Debug.WriteLine(ex);
return string.Empty;
}
}
}
}
}
}