Skip to content

Commit

Permalink
Added ConfigureAwait(false) to the JSON API Calls. This will fix dead…
Browse files Browse the repository at this point in the history
…lock issues where the wrapper methods are called from a non-async method.

Fixed an issue where the PlaceBetResponseStatus and PlaceBetErrorCode enums were named in correctly.
  • Loading branch information
anderj017 committed Apr 18, 2015
1 parent 67815ec commit 7dd69ac
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
36 changes: 18 additions & 18 deletions Enums/PlaceBetErrorCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ namespace PinnacleWrapper.Enums
[JsonConverter(typeof(StringEnumConverter))]
public enum PlaceBetErrorCode
{
AllBettingClosed, //ALL_BETTING_CLOSED Betting is not allowed at this moment
AllLiveBettingClosed, //ALL_LIVE_BETTING_CLOSED Live betting is not allowed at this moment
BlockedClient, //BLOCKED_CLIENT Client is no longer active
InvalidCountry, //INVALID_COUNTRY Client country is not allowed for betting
BlockedBetting, //BLOCKED_BETTING Not allowed betting for the client
InvalidEvent, //INVALID_EVENT Invalid eventid
AboveMaxBetAmount, //ABOVE_MAX_BET_AMOUNT Stake is above allowed maximum amount
BelowMinBetAmount, //BELOW_MIN_BET_AMOUNT Stake is below allowed minimum amount
OfflineEvent, //OFFLINE_EVENT Bet is submitted on a event that is offline
InsufficientFunds, //INSUFFICIENT_FUNDS Bet is submitted by a client with insufficient funds
LineChanged, //LINE_CHANGED Bet is submitted on a line that has changed
RedCardsChanged, //RED_CARDS_CHANGED Bet is submitted on a live soccer event with changed red card count
ScoreChanged, //SCORE_CHANGED Bet is submitted on a live soccer event with changed score
TimeRestriction, //TIME_RESTRICTION Bet is submitted within too short of a period from the same bet previously placed by a client
PastCutOffTime, //PAST_CUTOFFTIME Bet is submitted on a game after the betting cutoff time
AboveEventMax, //ABOVE_EVENT_MAX Bet cannot be placed because client exceeded allowed maximum of risk on a line
InvalidOddsFormat, //INVALID_ODDS_FORMAT If a bet was submitted with the odds format that is not allowed for the client
ListedPitchersSelectionError //LISTED_PITCHERS_SELECTION_ERROR If bet was submitted with pitcher1MustStart and/or pitcher2MustStart parameters in Place Bet request with values that are not allowed.
ALL_BETTING_CLOSED, //Betting is not allowed at this moment
ALL_LIVE_BETTING_CLOSED, //Live betting is not allowed at this moment
BLOCKED_CLIENT, //Client is no longer active
INVALID_COUNTRY, //Client country is not allowed for betting
BLOCKED_BETTING, //Not allowed betting for the client
INVALID_EVENT, //Invalid eventid
ABOVE_MAX_BET_AMOUNT, //Stake is above allowed maximum amount
BELOW_MIN_BET_AMOUNT, //Stake is below allowed minimum amount
OFFLINE_EVENT, //Bet is submitted on a event that is offline
INSUFFICIENT_FUNDS, //Bet is submitted by a client with insufficient funds
LINE_CHANGED, //Bet is submitted on a line that has changed
RED_CARDS_CHANGED, //Bet is submitted on a live soccer event with changed red card count
SCORE_CHANGED, //Bet is submitted on a live soccer event with changed score
TIME_RESTRICTION, //Bet is submitted within too short of a period from the same bet previously placed by a client
PAST_CUTOFFTIME, //Bet is submitted on a game after the betting cutoff time
ABOVE_EVENT_MAX, //Bet cannot be placed because client exceeded allowed maximum of risk on a line
INVALID_ODDS_FORMAT, //If a bet was submitted with the odds format that is not allowed for the client
LISTED_PITCHERS_SELECTION_ERROR, //If bet was submitted with pitcher1MustStart and/or pitcher2MustStart parameters in Place Bet request with values that are not allowed.
}
}
4 changes: 2 additions & 2 deletions Enums/PlaceBetResponseStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ namespace PinnacleWrapper.Enums
[JsonConverter(typeof(StringEnumConverter))]
public enum PlaceBetResponseStatus
{
Accepted,
PendingAcceptance, // live bets in the danger zone
ACCEPTED,
PENDING_ACCEPTANCE, // live bets in the danger zone
PROCESSED_WITH_ERROR
}
}
32 changes: 16 additions & 16 deletions PinnacleClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected T GetXmlAsync<T>(string requestType, params object[] values)
{
var response = _httpClient.GetAsync(string.Format(requestType, values)).Result;

var str = _httpClient.GetStringAsync(string.Format(requestType, values)).Result;
//var str = _httpClient.GetStringAsync(string.Format(requestType, values)).Result;

response.EnsureSuccessStatusCode(); // throw if web request failed

Expand Down Expand Up @@ -178,14 +178,14 @@ public Feed GetFeed(int sportId, int[] leagueIds, OddsFormat format, string curr

protected async Task<T> GetJsonAsync<T>(string requestType, params object[] values)
{
var response = _httpClient.GetAsync(string.Format(requestType, values)).Result;
var response = await _httpClient.GetAsync(string.Format(requestType, values)).ConfigureAwait(false);

response.EnsureSuccessStatusCode(); // throw if web request failed

var json = await response.Content.ReadAsStringAsync();

// deserialise json async
return JsonConvert.DeserializeObject<T>(json);
return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<T>(json));
}

// ToDo: replace requestData object type with "IJsonSerialisable"
Expand All @@ -194,7 +194,7 @@ protected async Task<T> PostJsonAsync<T>(string requestType, object requestData)
var requestPostData = JsonConvert.SerializeObject(requestData);

var response = await _httpClient.PostAsync(requestType,
new StringContent(requestPostData, Encoding.UTF8, "application/json"));
new StringContent(requestPostData, Encoding.UTF8, "application/json")).ConfigureAwait(false);

response.EnsureSuccessStatusCode(); // throw if web request failed

Expand All @@ -204,13 +204,13 @@ protected async Task<T> PostJsonAsync<T>(string requestType, object requestData)
return await Task.Factory.StartNew(() => JsonConvert.DeserializeObject<T>(json));
}

public ClientBalance GetClientBalance()
public Task<ClientBalance> GetClientBalance()
{
const string uri = "client/balance";
return GetJsonAsync<ClientBalance>(uri).Result;
return GetJsonAsync<ClientBalance>(uri);
}

public GetBetsResponse GetBets(BetListType type, DateTime startDate, DateTime endDate)
public Task<GetBetsResponse> GetBets(BetListType type, DateTime startDate, DateTime endDate)
{
// get request uri
var sb = new StringBuilder();
Expand All @@ -220,10 +220,10 @@ public GetBetsResponse GetBets(BetListType type, DateTime startDate, DateTime en

var uri = sb.ToString();

return GetJsonAsync<GetBetsResponse>(uri).Result;
return GetJsonAsync<GetBetsResponse>(uri);
}

public GetBetsResponse GetBets(List<int> betIds)
public Task<GetBetsResponse> GetBets(List<int> betIds)
{
// get request uri
var sb = new StringBuilder();
Expand All @@ -232,12 +232,12 @@ public GetBetsResponse GetBets(List<int> betIds)

var uri = sb.ToString();

return GetJsonAsync<GetBetsResponse>(uri).Result;
return GetJsonAsync<GetBetsResponse>(uri);
}

public PlaceBetResponse PlaceBet(PlaceBetRequest placeBetRequest)
public Task<PlaceBetResponse> PlaceBet(PlaceBetRequest placeBetRequest)
{
return PostJsonAsync<PlaceBetResponse>("bets/place", placeBetRequest).Result;
return PostJsonAsync<PlaceBetResponse>("bets/place", placeBetRequest);
}

/// <summary>
Expand All @@ -253,7 +253,7 @@ public PlaceBetResponse PlaceBet(PlaceBetRequest placeBetRequest)
/// <param name="side"></param>
/// <param name="handicap"></param>
/// <returns></returns>
public GetLineResponse GetLine(int sportId, int leagueId, long eventId, int periodNumber, BetType betType, OddsFormat oddsFormat,
public Task<GetLineResponse> GetLine(int sportId, int leagueId, long eventId, int periodNumber, BetType betType, OddsFormat oddsFormat,
TeamType? team = null, SideType? side = null, decimal? handicap = null)
{
if (team == null)
Expand Down Expand Up @@ -294,13 +294,13 @@ public GetLineResponse GetLine(int sportId, int leagueId, long eventId, int peri

var uri = sb.ToString();

return GetJsonAsync<GetLineResponse>(uri).Result;
return GetJsonAsync<GetLineResponse>(uri);
}

public GetInRunningResponse GetInRunning()
public Task<GetInRunningResponse> GetInRunning()
{
const string uri = "inrunning";
return GetJsonAsync<GetInRunningResponse>(uri).Result;
return GetJsonAsync<GetInRunningResponse>(uri);
}
}
}
Expand Down

0 comments on commit 7dd69ac

Please sign in to comment.