Skip to content

Commit c5d3edb

Browse files
author
Justin Skiles
authored
Issue/32 (#96)
* Starting to fix and update the EconService methods around trades * Added finishing touches to EconService endpoints. * Fixed wrong parameter name
1 parent 9b02eb8 commit c5d3edb

File tree

7 files changed

+188
-14
lines changed

7 files changed

+188
-14
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace Steam.Models.SteamEconomy
4+
{
5+
public class TradeHoldDurationsModel
6+
{
7+
public TimeSpan EscrowEndDuration { get; set; }
8+
9+
public DateTime EscrowEndDate { get; set; }
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Steam.Models.SteamEconomy
2+
{
3+
public class TradeHoldDurationsResultModel
4+
{
5+
public TradeHoldDurationsModel MyEscrow { get; set; }
6+
7+
public TradeHoldDurationsModel TheirEscrow { get; set; }
8+
9+
public TradeHoldDurationsModel BothEscrow { get; set; }
10+
}
11+
}

src/SteamWebAPI2/AutoMapperConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public static void Initialize()
9797
CreateSteamWebResponseMap<ResetLoginTokenContainer, string>(x);
9898
CreateSteamWebResponseMap<AccountPublicInfoContainer, AccountPublicInfoModel>(x);
9999
CreateSteamWebResponseMap<QueryLoginTokenContainer, QueryLoginTokenModel>(x);
100+
CreateSteamWebResponseMap<TradeHoldDurationsResultContainer, TradeHoldDurationsResultModel>(x);
100101

101102
x.AddProfile<DOTA2EconProfile>();
102103
x.AddProfile<DOTA2FantasyProfile>();

src/SteamWebAPI2/Interfaces/EconService.cs

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using SteamWebAPI2.Models.SteamEconomy;
1+
using Steam.Models.SteamEconomy;
2+
using SteamWebAPI2.Models.SteamEconomy;
23
using SteamWebAPI2.Utilities;
4+
using System;
35
using System.Collections.Generic;
46
using System.Threading.Tasks;
57

@@ -32,18 +34,30 @@ public EconService(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWeb
3234
/// <param name="includeFailed">If set, trades in status k_ETradeStatus_Failed, k_ETradeStatus_RollbackFailed, k_ETradeStatus_RollbackAbandoned, and k_ETradeStatus_EscrowRollback will be included</param>
3335
/// <param name="includeTotal">Unknown</param>
3436
/// <returns></returns>
35-
public async Task<ISteamWebResponse<Steam.Models.SteamEconomy.TradeHistoryModel>> GetTradeHistoryAsync(uint maxTrades, uint startAfterTime = 0, ulong startAfterTradeId = 0, bool navigatingBack = false, bool getDescriptions = false, string language = "", bool includeFailed = false, bool includeTotal = false)
37+
public async Task<ISteamWebResponse<TradeHistoryModel>> GetTradeHistoryAsync(
38+
uint maxTrades,
39+
DateTime? startAfterTime = null,
40+
ulong startAfterTradeId = 0,
41+
bool navigatingBack = false,
42+
bool getDescriptions = false,
43+
string language = "",
44+
bool includeFailed = false,
45+
bool includeTotal = false)
3646
{
3747
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
3848

49+
ulong? startAfterTimeUnix = startAfterTime.HasValue
50+
? startAfterTime.Value.ToUnixTimeStamp()
51+
: (ulong?)null;
52+
3953
parameters.AddIfHasValue(maxTrades, "max_trades");
40-
parameters.AddIfHasValue(startAfterTime, "start_after_time");
54+
parameters.AddIfHasValue(startAfterTimeUnix, "start_after_time");
4155
parameters.AddIfHasValue(startAfterTradeId, "start_after_tradeid");
4256
parameters.AddIfHasValue(navigatingBack, "navigating_back");
4357
parameters.AddIfHasValue(getDescriptions, "get_descriptions");
4458
parameters.AddIfHasValue(language, "language");
4559
parameters.AddIfHasValue(includeFailed, "include_failed");
46-
parameters.AddIfHasValue(includeTotal, "inclue_total");
60+
parameters.AddIfHasValue(includeTotal, "include_total");
4761

4862
var steamWebResponse = await steamWebInterface.GetAsync<TradeHistoryResultContainer>("GetTradeHistory", 1, parameters);
4963

@@ -65,20 +79,31 @@ public EconService(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWeb
6579
/// <param name="historicalOnly">Return trade offers that are not in an active state.</param>
6680
/// <param name="timeHistoricalCutoff">A unix time value. when active_only is set, inactive offers will be returned if their state was updated since this time. Useful to get delta updates on what has changed. WARNING: If not passed, this will default to the time your account last viewed the trade offers page. To avoid this behavior use a very low or very high date.</param>
6781
/// <returns></returns>
68-
public async Task<ISteamWebResponse<Steam.Models.SteamEconomy.TradeOffersResultModel>> GetTradeOffersAsync(bool getSentOffers, bool getReceivedOffers, bool getDescriptions = false, string language = "", bool activeOnly = false, bool historicalOnly = false, uint timeHistoricalCutoff = 0)
82+
public async Task<ISteamWebResponse<TradeOffersResultModel>> GetTradeOffersAsync(
83+
bool getSentOffers,
84+
bool getReceivedOffers,
85+
bool getDescriptions = false,
86+
string language = "",
87+
bool activeOnly = false,
88+
bool historicalOnly = false,
89+
DateTime? timeHistoricalCutoff = null)
6990
{
7091
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
7192

7293
int getSentOffersBit = getSentOffers ? 1 : 0;
7394
int getReceivedOffersBit = getReceivedOffers ? 1 : 0;
7495

96+
ulong? timeHistoricalCutoffUnix = timeHistoricalCutoff.HasValue
97+
? timeHistoricalCutoff.Value.ToUnixTimeStamp()
98+
: (ulong?)null;
99+
75100
parameters.AddIfHasValue(getSentOffersBit, "get_sent_offers");
76101
parameters.AddIfHasValue(getReceivedOffersBit, "get_received_offers");
77102
parameters.AddIfHasValue(getDescriptions, "get_descriptions");
78103
parameters.AddIfHasValue(language, "language");
79104
parameters.AddIfHasValue(activeOnly, "active_only");
80105
parameters.AddIfHasValue(historicalOnly, "historicalOnly");
81-
parameters.AddIfHasValue(timeHistoricalCutoff, "time_historical_cutoff");
106+
parameters.AddIfHasValue(timeHistoricalCutoffUnix, "time_historical_cutoff");
82107

83108
var steamWebResponse = await steamWebInterface.GetAsync<TradeOffersResultContainer>("GetTradeOffers", 1, parameters);
84109

@@ -95,12 +120,16 @@ public EconService(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWeb
95120
/// <param name="tradeOfferId">The trade offer identifier</param>
96121
/// <param name="language">The language to use for item display information.</param>
97122
/// <returns></returns>
98-
public async Task<ISteamWebResponse<Steam.Models.SteamEconomy.TradeOfferResultModel>> GetTradeOfferAsync(ulong tradeOfferId, string language = "")
123+
public async Task<ISteamWebResponse<TradeOfferResultModel>> GetTradeOfferAsync(
124+
ulong tradeOfferId,
125+
string language = "",
126+
bool getDescriptions = false)
99127
{
100128
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
101129

102130
parameters.AddIfHasValue(tradeOfferId, "tradeOfferId");
103131
parameters.AddIfHasValue(language, "language");
132+
parameters.AddIfHasValue(getDescriptions, "get_descriptions");
104133

105134
var steamWebResponse = await steamWebInterface.GetAsync<TradeOfferResultContainer>("GetTradeOffer", 1, parameters);
106135

@@ -110,5 +139,57 @@ public EconService(ISteamWebRequest steamWebRequest, ISteamWebInterface steamWeb
110139

111140
return steamWebResponseModel;
112141
}
142+
143+
public async Task<ISteamWebResponse<dynamic>> GetTradeStatusAsync(ulong tradeId, bool getDescriptions, string language)
144+
{
145+
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
146+
parameters.AddIfHasValue(tradeId, "tradeid");
147+
parameters.AddIfHasValue(getDescriptions, "get_descriptions");
148+
parameters.AddIfHasValue(language, "language");
149+
var steamWebResponse = await steamWebInterface.GetAsync<dynamic>("GetTradeStatus", 1, parameters);
150+
return steamWebResponse;
151+
}
152+
153+
public async Task<ISteamWebResponse<dynamic>> GetTradeOffersSummaryAsync(DateTime? timeLastVisit = null)
154+
{
155+
ulong? timeLastVisitUnix = timeLastVisit.HasValue
156+
? timeLastVisit.Value.ToUnixTimeStamp()
157+
: (ulong?)null;
158+
159+
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
160+
parameters.AddIfHasValue(timeLastVisitUnix, "time_last_visit");
161+
var steamWebResponse = await steamWebInterface.GetAsync<dynamic>("GetTradeOffersSummary", 1, parameters);
162+
return steamWebResponse;
163+
}
164+
165+
public async Task<ISteamWebResponse<dynamic>> DeclineTradeOfferAsync(ulong tradeOfferId)
166+
{
167+
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
168+
parameters.AddIfHasValue(tradeOfferId, "tradeofferid");
169+
var steamWebResponse = await steamWebInterface.PostAsync<dynamic>("DeclineTradeOffer", 1, parameters);
170+
return steamWebResponse;
171+
}
172+
173+
public async Task<ISteamWebResponse<dynamic>> CancelTradeOfferAsync(ulong tradeOfferId)
174+
{
175+
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
176+
parameters.AddIfHasValue(tradeOfferId, "tradeofferid");
177+
var steamWebResponse = await steamWebInterface.PostAsync<dynamic>("CancelTradeOffer", 1, parameters);
178+
return steamWebResponse;
179+
}
180+
181+
public async Task<ISteamWebResponse<TradeHoldDurationsResultModel>> GetTradeHoldDurationsAsync(ulong steamIdTarget, string tradeOfferAccessToken = "")
182+
{
183+
List<SteamWebRequestParameter> parameters = new List<SteamWebRequestParameter>();
184+
parameters.AddIfHasValue(steamIdTarget, "steamid_target");
185+
parameters.AddIfHasValue(tradeOfferAccessToken, "trade_offer_access_token");
186+
var steamWebResponse = await steamWebInterface.GetAsync<TradeHoldDurationsResultContainer>("GetTradeHoldDurations", 1, parameters);
187+
188+
var steamWebResponseModel = AutoMapperConfiguration.Mapper.Map<
189+
ISteamWebResponse<TradeHoldDurationsResultContainer>,
190+
ISteamWebResponse<TradeHoldDurationsResultModel>>(steamWebResponse);
191+
192+
return steamWebResponseModel;
193+
}
113194
}
114195
}

src/SteamWebAPI2/Interfaces/IEconService.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Steam.Models.SteamEconomy;
22
using SteamWebAPI2.Utilities;
3+
using System;
34
using System.Threading.Tasks;
45

56
namespace SteamWebAPI2.Interfaces
@@ -18,7 +19,20 @@ public interface IEconService
1819
/// <param name="includeFailed">If set, trades in status k_ETradeStatus_Failed, k_ETradeStatus_RollbackFailed, k_ETradeStatus_RollbackAbandoned, and k_ETradeStatus_EscrowRollback will be included</param>
1920
/// <param name="includeTotal">Unknown</param>
2021
/// <returns></returns>
21-
Task<ISteamWebResponse<TradeHistoryModel>> GetTradeHistoryAsync(uint maxTrades, uint startAfterTime, ulong startAfterTradeId, bool navigatingBack, bool getDescriptions, string language, bool includeFailed, bool includeTotal);
22+
Task<ISteamWebResponse<TradeHistoryModel>> GetTradeHistoryAsync(
23+
uint maxTrades,
24+
DateTime? startAfterTime,
25+
ulong startAfterTradeId,
26+
bool navigatingBack,
27+
bool getDescriptions,
28+
string language,
29+
bool includeFailed,
30+
bool includeTotal);
31+
32+
Task<ISteamWebResponse<dynamic>> GetTradeStatusAsync(
33+
ulong tradeId,
34+
bool getDescriptions,
35+
string language);
2236

2337
/// <summary>
2438
/// This API gets a list of trade offers (up to a maximum of 500 sent or 1000 received regardless of time_historical_cutoff) for the account associated with the WebAPI key. You cannot call this API for accounts other than your own.
@@ -29,20 +43,31 @@ public interface IEconService
2943
/// <param name="language">Needed if get_descriptions is set, the language to use for item descriptions.</param>
3044
/// <param name="activeOnly">Return only trade offers in an active state (offers that haven't been accepted yet), or any offers that have had their state change since time_historical_cutoff.</param>
3145
/// <param name="historicalOnly">Return trade offers that are not in an active state.</param>
32-
/// <param name="timeHistoricalCutoff">A unix time value. when active_only is set, inactive offers will be returned if their state was updated since this time. Useful to get delta updates on what has changed. WARNING: If not passed, this will default to the time your account last viewed the trade offers page. To avoid this behavior use a very low or very high date.</param>
46+
/// <param name="timeHistoricalCutoff">A unix time value. When active_only is set, inactive offers will be returned if their state was updated since this time. Useful to get delta updates on what has changed. WARNING: If not passed, this will default to the time your account last viewed the trade offers page. To avoid this behavior use a very low or very high date.</param>
3347
/// <returns></returns>
34-
Task<ISteamWebResponse<TradeOffersResultModel>> GetTradeOffersAsync(bool getSentOffers, bool getReceivedOffers, bool getDescriptions, string language, bool activeOnly, bool historicalOnly, uint timeHistoricalCutoff);
48+
Task<ISteamWebResponse<TradeOffersResultModel>> GetTradeOffersAsync(
49+
bool getSentOffers,
50+
bool getReceivedOffers,
51+
bool getDescriptions,
52+
string language,
53+
bool activeOnly,
54+
bool historicalOnly,
55+
DateTime? timeHistoricalCutoff);
3556

3657
/// <summary>
3758
/// This API gets details about a single trade offer. The trade offer must have been sent to or from the account associated with the WebAPI key. You cannot call this API for accounts other than your own.
3859
/// </summary>
3960
/// <param name="tradeOfferId">The trade offer identifier</param>
4061
/// <param name="language">The language to use for item display information.</param>
4162
/// <returns></returns>
42-
Task<ISteamWebResponse<TradeOfferResultModel>> GetTradeOfferAsync(ulong tradeOfferId, string language);
63+
Task<ISteamWebResponse<TradeOfferResultModel>> GetTradeOfferAsync(ulong tradeOfferId, string language, bool getDescriptions);
64+
65+
Task<ISteamWebResponse<dynamic>> GetTradeOffersSummaryAsync(DateTime? timeLastVisit);
66+
67+
Task<ISteamWebResponse<dynamic>> DeclineTradeOfferAsync(ulong tradeOfferId);
68+
69+
Task<ISteamWebResponse<dynamic>> CancelTradeOfferAsync(ulong tradeOfferId);
4370

44-
//Task GetTradeOffersSummary(ulong timeLastVisit);
45-
//Task DeclineTradeOffer(ulong tradeOfferId);
46-
//Task CancelTradeOffer(ulong tradeOfferId);
71+
Task<ISteamWebResponse<TradeHoldDurationsResultModel>> GetTradeHoldDurationsAsync(ulong steamIdTarget, string tradeOfferAccessToken);
4772
}
4873
}

src/SteamWebAPI2/Mappings/EconServiceProfile.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using AutoMapper;
23
using Steam.Models.SteamEconomy;
34
using SteamWebAPI2.Models.SteamEconomy;
@@ -35,6 +36,15 @@ public EconServiceProfile()
3536
CreateMap<TradeOffersResultContainer, TradeOffersResultModel>().ConvertUsing((src, dest, context) =>
3637
context.Mapper.Map<TradeOffersResult, TradeOffersResultModel>(src.Result)
3738
);
39+
CreateMap<TradeHoldDurationsResultContainer, TradeHoldDurationsResultModel>().ConvertUsing((src, dest, context) =>
40+
context.Mapper.Map<TradeHoldDurationsResult, TradeHoldDurationsResultModel>(src.Result)
41+
);
42+
CreateMap<TradeHoldDurationsResult, TradeHoldDurationsResultModel>();
43+
CreateMap<TradeHoldDurations, TradeHoldDurationsModel>()
44+
.ForMember(dest => dest.EscrowEndDate,
45+
opts => opts.MapFrom(src => src.EscrowEndDateRfc3339))
46+
.ForMember(dest => dest.EscrowEndDuration,
47+
opts => opts.MapFrom(src => TimeSpan.FromSeconds(src.EscrowEndDurationSeconds)));
3848
}
3949
}
4050
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Newtonsoft.Json;
2+
using System;
3+
4+
namespace SteamWebAPI2.Models.SteamEconomy
5+
{
6+
internal class TradeHoldDurations
7+
{
8+
[JsonProperty("escrow_end_duration_seconds")]
9+
public uint EscrowEndDurationSeconds { get; set; }
10+
11+
[JsonProperty("escrow_end_date")]
12+
public uint EscrowEndDate { get; set; }
13+
14+
[JsonProperty("escrow_end_date_rfc3339")]
15+
public DateTime EscrowEndDateRfc3339 { get; set;}
16+
}
17+
18+
internal class TradeHoldDurationsResult
19+
{
20+
[JsonProperty("my_escrow")]
21+
public TradeHoldDurations MyEscrow { get; set; }
22+
23+
[JsonProperty("their_escrow")]
24+
public TradeHoldDurations TheirEscrow { get; set; }
25+
26+
[JsonProperty("both_escrow")]
27+
public TradeHoldDurations BothEscrow { get; set; }
28+
}
29+
30+
internal class TradeHoldDurationsResultContainer
31+
{
32+
[JsonProperty("response")]
33+
public TradeHoldDurationsResult Result { get; set; }
34+
}
35+
}

0 commit comments

Comments
 (0)