Skip to main content

steam_user/
action.rs

1//! API action definitions and error context extensions.
2
3use crate::error::SteamUserError;
4
5/// All available actions exposed by `SteamUserApi`.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub enum ApiAction {
8    GetAccountDetails,
9    GetSteamWalletBalance,
10    GetAmountSpentOnSteam,
11    GetPurchaseHistory,
12    RedeemWalletCode,
13    ParentalUnlock,
14    GetFriendActivity,
15    GetFriendActivityFull,
16    CommentUserReceivedNewGame,
17    RateUpUserReceivedNewGame,
18    DeleteCommentUserReceivedNewGame,
19    GetOwnedApps,
20    GetOwnedAppsId,
21    GetOwnedAppsDetail,
22    GetAppDetail,
23    FetchCsgoAccountStats,
24    GetAppList,
25    SuggestAppList,
26    QueryAppList,
27    GetSteamAppVersionInfo,
28    GetDynamicStoreUserData,
29    FetchBatchedLoyaltyRewardItems,
30    GetMyComments,
31    GetUserComments,
32    PostComment,
33    DeleteComment,
34    GetConfirmations,
35    AcceptConfirmationForObject,
36    DenyConfirmationForObject,
37    GetAccountEmail,
38    GetCurrentSteamLogin,
39    AddFriend,
40    RemoveFriend,
41    AcceptFriendRequest,
42    IgnoreFriendRequest,
43    BlockUser,
44    UnblockUser,
45    GetFriendsList,
46    GetFriendsDetails,
47    GetFriendsDetailsOfUser,
48    SearchUsers,
49    CreateInstantInvite,
50    FollowUser,
51    UnfollowUser,
52    GetFollowingList,
53    GetFollowingListOfUser,
54    GetMyFriendsIdList,
55    GetPendingFriendList,
56    RemoveFriends,
57    UnfollowUsers,
58    CancelFriendRequest,
59    GetFriendsInCommon,
60    JoinGroup,
61    LeaveGroup,
62    GetGroupMembers,
63    PostGroupAnnouncement,
64    KickGroupMember,
65    InviteUserToGroup,
66    InviteUsersToGroup,
67    AcceptGroupInvite,
68    IgnoreGroupInvite,
69    GetGroupOverview,
70    GetGroupSteamIdFromVanityUrl,
71    GetGroupInfoXml,
72    GetGroupInfoXmlFull,
73    GetInvitableGroups,
74    InviteAllFriendsToGroup,
75    GetInventory,
76    GetUserInventoryContents,
77    GetInventoryHistory,
78    GetPriceOverview,
79    GetActiveInventories,
80    GetInventoryTrading,
81    GetInventoryTradingPartner,
82    GetFullInventoryHistory,
83    GetMyListings,
84    GetMarketHistory,
85    SellItem,
86    RemoveListing,
87    GetGemValue,
88    TurnItemIntoGems,
89    GetBoosterPackCatalog,
90    CreateBoosterPack,
91    OpenBoosterPack,
92    GetMarketRestrictions,
93    GetMarketApps,
94    GetItemNameid,
95    GetItemOrdersHistogram,
96    GetPhoneNumberStatus,
97    AddPhoneNumber,
98    ConfirmPhoneCodeForAdd,
99    ResendPhoneVerificationCode,
100    GetRemovePhoneNumberType,
101    SendAccountRecoveryCode,
102    ConfirmRemovePhoneNumberCode,
103    SendConfirmation2SteamMobileApp,
104    SendConfirmation2SteamMobileAppFinal,
105    GetPrivacySettings,
106    SetPrivacySettings,
107    SetAllPrivacy,
108    GetProfile,
109    EditProfile,
110    SetPersonaName,
111    GetAliasHistory,
112    ClearPreviousAliases,
113    SetNickname,
114    RemoveNickname,
115    PostProfileStatus,
116    SelectPreviousAvatar,
117    SetupProfile,
118    GetUserSummaryFromXml,
119    GetUserSummaryFromProfile,
120    FetchFullProfile,
121    ResolveUser,
122    GetAvatarHistory,
123    UploadAvatarFromUrl,
124    EnumerateTokens,
125    CheckTokenExists,
126    RevokeTokens,
127    GetTradeUrl,
128    GetTradeOffer,
129    AcceptTradeOffer,
130    DeclineTradeOffer,
131    SendTradeOffer,
132    GetSteamGuardStatus,
133    EnableTwoFactor,
134    FinalizeTwoFactor,
135    DisableTwoFactor,
136    DeauthorizeDevices,
137    AddAuthenticator,
138    FinalizeAuthenticator,
139    RemoveAuthenticator,
140    EnableSteamGuardEmail,
141    DisableSteamGuardEmail,
142    GetPlayerReports,
143    AddFreeLicense,
144    AddSubFreeLicense,
145    RedeemPoints,
146    GetHelpRequests,
147    GetHelpRequestDetail,
148    GetMatchHistory,
149    LoggedIn,
150    GetNotifications,
151    GetWebApiKey,
152    ResolveVanityUrl,
153    RevokeWebApiKey,
154}
155
156impl ApiAction {
157    /// Returns true if the action fetches data without side effects,
158    /// making it safe to blindly retry on transient failures.
159    pub fn is_read_only(&self) -> bool {
160        match self {
161            // Write/Mutating actions
162            Self::RedeemWalletCode
163            | Self::ParentalUnlock
164            | Self::CommentUserReceivedNewGame
165            | Self::RateUpUserReceivedNewGame
166            | Self::DeleteCommentUserReceivedNewGame
167            | Self::PostComment
168            | Self::DeleteComment
169            | Self::AcceptConfirmationForObject
170            | Self::DenyConfirmationForObject
171            | Self::AddFriend
172            | Self::RemoveFriend
173            | Self::AcceptFriendRequest
174            | Self::IgnoreFriendRequest
175            | Self::BlockUser
176            | Self::UnblockUser
177            | Self::CreateInstantInvite
178            | Self::FollowUser
179            | Self::UnfollowUser
180            | Self::RemoveFriends
181            | Self::UnfollowUsers
182            | Self::CancelFriendRequest
183            | Self::JoinGroup
184            | Self::LeaveGroup
185            | Self::PostGroupAnnouncement
186            | Self::KickGroupMember
187            | Self::InviteUserToGroup
188            | Self::InviteUsersToGroup
189            | Self::AcceptGroupInvite
190            | Self::IgnoreGroupInvite
191            | Self::InviteAllFriendsToGroup
192            | Self::SellItem
193            | Self::RemoveListing
194            | Self::TurnItemIntoGems
195            | Self::CreateBoosterPack
196            | Self::OpenBoosterPack
197            | Self::AddPhoneNumber
198            | Self::ConfirmPhoneCodeForAdd
199            | Self::ResendPhoneVerificationCode
200            | Self::SendAccountRecoveryCode
201            | Self::ConfirmRemovePhoneNumberCode
202            | Self::SendConfirmation2SteamMobileApp
203            | Self::SendConfirmation2SteamMobileAppFinal
204            | Self::SetPrivacySettings
205            | Self::SetAllPrivacy
206            | Self::EditProfile
207            | Self::SetPersonaName
208            | Self::ClearPreviousAliases
209            | Self::SetNickname
210            | Self::RemoveNickname
211            | Self::PostProfileStatus
212            | Self::SelectPreviousAvatar
213            | Self::SetupProfile
214            | Self::UploadAvatarFromUrl
215            | Self::RevokeTokens
216            | Self::AcceptTradeOffer
217            | Self::DeclineTradeOffer
218            | Self::SendTradeOffer
219            | Self::EnableTwoFactor
220            | Self::FinalizeTwoFactor
221            | Self::DisableTwoFactor
222            | Self::DeauthorizeDevices
223            | Self::AddAuthenticator
224            | Self::FinalizeAuthenticator
225            | Self::RemoveAuthenticator
226            | Self::EnableSteamGuardEmail
227            | Self::DisableSteamGuardEmail
228            | Self::AddFreeLicense
229            | Self::AddSubFreeLicense
230            | Self::RedeemPoints
231            | Self::RevokeWebApiKey => false,
232
233            // Read-only actions
234            Self::GetAccountDetails
235            | Self::GetSteamWalletBalance
236            | Self::GetAmountSpentOnSteam
237            | Self::GetPurchaseHistory
238            | Self::GetFriendActivity
239            | Self::GetFriendActivityFull
240            | Self::GetOwnedApps
241            | Self::GetOwnedAppsId
242            | Self::GetOwnedAppsDetail
243            | Self::GetAppDetail
244            | Self::FetchCsgoAccountStats
245            | Self::GetAppList
246            | Self::SuggestAppList
247            | Self::QueryAppList
248            | Self::GetSteamAppVersionInfo
249            | Self::GetDynamicStoreUserData
250            | Self::FetchBatchedLoyaltyRewardItems
251            | Self::GetMyComments
252            | Self::GetUserComments
253            | Self::GetConfirmations
254            | Self::GetAccountEmail
255            | Self::GetCurrentSteamLogin
256            | Self::GetFriendsList
257            | Self::GetFriendsDetails
258            | Self::GetFriendsDetailsOfUser
259            | Self::SearchUsers
260            | Self::GetFollowingList
261            | Self::GetFollowingListOfUser
262            | Self::GetMyFriendsIdList
263            | Self::GetPendingFriendList
264            | Self::GetFriendsInCommon
265            | Self::GetGroupMembers
266            | Self::GetGroupOverview
267            | Self::GetGroupSteamIdFromVanityUrl
268            | Self::GetGroupInfoXml
269            | Self::GetGroupInfoXmlFull
270            | Self::GetInvitableGroups
271            | Self::GetInventory
272            | Self::GetUserInventoryContents
273            | Self::GetInventoryHistory
274            | Self::GetPriceOverview
275            | Self::GetActiveInventories
276            | Self::GetInventoryTrading
277            | Self::GetInventoryTradingPartner
278            | Self::GetFullInventoryHistory
279            | Self::GetMyListings
280            | Self::GetMarketHistory
281            | Self::GetGemValue
282            | Self::GetBoosterPackCatalog
283            | Self::GetMarketRestrictions
284            | Self::GetMarketApps
285            | Self::GetItemNameid
286            | Self::GetItemOrdersHistogram
287            | Self::GetPhoneNumberStatus
288            | Self::GetRemovePhoneNumberType
289            | Self::GetPrivacySettings
290            | Self::GetProfile
291            | Self::GetAliasHistory
292            | Self::GetUserSummaryFromXml
293            | Self::GetUserSummaryFromProfile
294            | Self::FetchFullProfile
295            | Self::ResolveUser
296            | Self::GetAvatarHistory
297            | Self::EnumerateTokens
298            | Self::CheckTokenExists
299            | Self::GetTradeUrl
300            | Self::GetTradeOffer
301            | Self::GetSteamGuardStatus
302            | Self::GetPlayerReports
303            | Self::GetHelpRequests
304            | Self::GetHelpRequestDetail
305            | Self::GetMatchHistory
306            | Self::LoggedIn
307            | Self::GetNotifications
308            | Self::GetWebApiKey
309            | Self::ResolveVanityUrl => true,
310        }
311    }
312}
313
314/// Extension trait to attach `ApiAction` context to errors.
315pub trait ActionContext<T> {
316    fn with_action(self, action: ApiAction) -> Result<T, SteamUserError>;
317}
318
319impl<T, E> ActionContext<T> for Result<T, E>
320where
321    SteamUserError: From<E>,
322{
323    fn with_action(self, action: ApiAction) -> Result<T, SteamUserError> {
324        self.map_err(|e| SteamUserError::ActionFailed { action, source: Box::new(SteamUserError::from(e)) })
325    }
326}