def GetURL(methodUrl, getParams): if not TitleId: raise PlayFabErrors.PlayFabException( "You must set PlayFabSettings.TitleId before making an API call") url = [] if not ProductionEnvironmentURL.startswith("http"): if VerticalName: url.append("https://") url.append(VerticalName) else: url.append("https://") url.append(TitleId) url.append(ProductionEnvironmentURL) url.append(methodUrl) if getParams: for idx, (k, v) in enumerate(getParams.items()): if idx == 0: url.append("?") else: url.append("&") url.append(k) url.append("=") url.append(v) return "".join(url)
def GetURL(methodUrl): if not TitleId: raise PlayFabErrors.PlayFabException( "You must set PlayFabSettings.TitleId before making an API call") url = ProductionEnvironmentURL.format(titleId=TitleId, methodUrl=methodUrl) return url
def BlockEntity(request, callback, customData=None, extraHeaders=None): if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Group/BlockEntity", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def DoPost(urlPath, request, authKey, authVal, callback, customData = None, extraHeaders = None): url = PlayFabSettings.GetURL(urlPath) try: j = json.dumps(request) except Exception as e: raise PlayFabErrors.PlayFabException("The given request is not json serializable. {}".format(e)) requestHeaders = {} if extraHeaders: requestHeaders.update(extraHeaders) requestHeaders["Content-Type"] = "application/json" requestHeaders["X-PlayFabSDK"] = PlayFabSettings._internalSettings.SdkVersionString requestHeaders["X-ReportErrorAsSuccess"] = "true" # Makes processing PlayFab errors a little easier if authKey and authVal: requestHeaders[authKey] = authVal httpResponse = requests.post(url, data=j, headers=requestHeaders) error = response = None if httpResponse.status_code != 200: # Failed to contact PlayFab Case error = PlayFabErrors.PlayFabError() error.HttpCode = httpResponse.status_code error.HttpStatus = httpResponse.reason else: # Contacted playfab responseWrapper = json.loads(httpResponse.content.decode("utf-8")) if responseWrapper["code"] != 200: # contacted PlayFab, but response indicated failure error = responseWrapper else: # successful call to PlayFab response = responseWrapper["data"] if error and callback: callGlobalErrorHandler(error) try: callback(None, error) # Notify the caller about an API Call failure except Exception as e: PlayFabSettings.GlobalExceptionLogger(e) # Global notification about exception in caller's callback elif response and callback: try: callback(response, None) # Notify the caller about an API Call success except Exception as e: PlayFabSettings.GlobalExceptionLogger(e) # Global notification about exception in caller's callback
def AuthUser(request, callback, customData = None, extraHeaders = None): """ Validates a user with the PlayFab service https://docs.microsoft.com/rest/api/playfab/matchmaker/matchmaking/authuser """ if not PlayFabSettings.DeveloperSecretKey: raise PlayFabErrors.PlayFabException("Must have DeveloperSecretKey set to call this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Matchmaker/AuthUser", request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey, wrappedCallback, customData, extraHeaders)
def PlayerLeft(request, callback, customData = None, extraHeaders = None): """ Informs the PlayFab game server hosting service that the indicated user has left the Game Server Instance specified https://docs.microsoft.com/rest/api/playfab/matchmaker/matchmaking/playerleft """ if not PlayFabSettings.DeveloperSecretKey: raise PlayFabErrors.PlayFabException("Must have DeveloperSecretKey set to call this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Matchmaker/PlayerLeft", request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey, wrappedCallback, customData, extraHeaders)
def UserInfo(request, callback, customData = None, extraHeaders = None): """ Retrieves the relevant details for a specified user, which the external match-making service can then use to compute effective matches https://docs.microsoft.com/rest/api/playfab/matchmaker/matchmaking/userinfo """ if not PlayFabSettings.DeveloperSecretKey: raise PlayFabErrors.PlayFabException("Must have DeveloperSecretKey set to call this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Matchmaker/UserInfo", request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey, wrappedCallback, customData, extraHeaders)
def WriteEvents(request, callback, customData=None, extraHeaders=None): """ Write batches of entity based events to PlayStream. The namespace of the Event must be 'custom' or start with 'custom.'. https://docs.microsoft.com/rest/api/playfab/events/playstream-events/writeevents """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Event/WriteEvents", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def GetDraftItems(request, callback, customData=None, extraHeaders=None): """ Retrieves a paginated list of the items from the draft catalog. https://docs.microsoft.com/rest/api/playfab/economy/catalog/getdraftitems """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Catalog/GetDraftItems", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def SetPerformance(request, callback, customData=None, extraHeaders=None): """ Sets the Insights performance level value for the title. https://docs.microsoft.com/rest/api/playfab/insights/analytics/setperformance """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Insights/SetPerformance", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def GetLanguageList(request, callback, customData=None, extraHeaders=None): """ Retrieves the list of allowed languages, only accessible by title entities https://docs.microsoft.com/rest/api/playfab/localization/localization/getlanguagelist """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Locale/GetLanguageList", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def DeleteItem(request, callback, customData=None, extraHeaders=None): """ Removes an item from working catalog and all published versions from the public catalog. https://docs.microsoft.com/rest/api/playfab/economy/catalog/deleteitem """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Catalog/DeleteItem", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def IsMember(request, callback, customData=None, extraHeaders=None): """ Checks to see if an entity is a member of a group or role within the group https://docs.microsoft.com/rest/api/playfab/groups/groups/ismember """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Group/IsMember", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def PublishDraftItem(request, callback, customData=None, extraHeaders=None): """ Initiates a publish of an item from the working catalog to the public catalog. https://docs.microsoft.com/rest/api/playfab/economy/catalog/publishdraftitem """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Catalog/PublishDraftItem", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def ReviewItem(request, callback, customData=None, extraHeaders=None): """ Creates or updates a review for the specified item. https://docs.microsoft.com/rest/api/playfab/economy/catalog/reviewitem """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Catalog/ReviewItem", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def StartGame(request, callback, customData=None, extraHeaders=None): """ Instructs the PlayFab game server hosting service to instantiate a new Game Server Instance https://docs.microsoft.com/rest/api/playfab/matchmaker/matchmaking/startgame """ if not PlayFabSettings.DeveloperSecretKey: raise PlayFabErrors.PlayFabException( "Must have DeveloperSecretKey set to call this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Matchmaker/StartGame", request, "X-SecretKey", PlayFabSettings.DeveloperSecretKey, wrappedCallback, customData, extraHeaders)
def GetItemReviews(request, callback, customData=None, extraHeaders=None): """ Get a paginated set of reviews associated with the specified item. https://docs.microsoft.com/rest/api/playfab/economy/catalog/getitemreviews """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Catalog/GetItemReviews", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def BlockEntity(request, callback, customData=None, extraHeaders=None): """ Blocks a list of entities from joining a group. https://docs.microsoft.com/rest/api/playfab/groups/groups/blockentity """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Group/BlockEntity", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def ApplyToGroup(request, callback, customData=None, extraHeaders=None): """ Applies to join a group https://docs.microsoft.com/rest/api/playfab/groups/groups/applytogroup """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Group/ApplyToGroup", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def UpdateRole(request, callback, customData=None, extraHeaders=None): """ Updates metadata about a role. https://docs.microsoft.com/rest/api/playfab/groups/groups/updaterole """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Group/UpdateRole", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def RemoveMembers(request, callback, customData=None, extraHeaders=None): """ Removes members from a group. https://docs.microsoft.com/rest/api/playfab/groups/groups/removemembers """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Group/RemoveMembers", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def ListMembership(request, callback, customData=None, extraHeaders=None): """ Lists all groups and roles for an entity https://docs.microsoft.com/rest/api/playfab/groups/groups/listmembership """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Group/ListMembership", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def CreateUploadUrls(request, callback, customData=None, extraHeaders=None): """ Creates one or more upload URLs which can be used by the client to upload raw file data. https://docs.microsoft.com/rest/api/playfab/economy/catalog/createuploadurls """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Catalog/CreateUploadUrls", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def GetObjects(request, callback, customData=None, extraHeaders=None): """ Retrieves objects from an entity's profile. https://docs.microsoft.com/rest/api/playfab/data/object/getobjects """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Object/GetObjects", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def ReportItem(request, callback, customData=None, extraHeaders=None): """ Submit a report for an item, indicating in what way the item is inappropriate. https://docs.microsoft.com/rest/api/playfab/economy/catalog/reportitem """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Catalog/ReportItem", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def ChangeMemberRole(request, callback, customData=None, extraHeaders=None): """ Changes the role membership of a list of entities from one role to another. https://docs.microsoft.com/rest/api/playfab/groups/groups/changememberrole """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Group/ChangeMemberRole", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def CreateDraftItem(request, callback, customData=None, extraHeaders=None): """ Creates a new item in the working catalog using provided metadata. https://docs.microsoft.com/rest/api/playfab/economy/catalog/createdraftitem """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Catalog/CreateDraftItem", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def ListFunctions(request, callback, customData=None, extraHeaders=None): """ Lists all currently registered Azure Functions for a given title. https://docs.microsoft.com/rest/api/playfab/cloudscript/server-side-cloud-script/listfunctions """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/CloudScript/ListFunctions", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def GetCatalogConfig(request, callback, customData=None, extraHeaders=None): """ Gets the configuration for the catalog. https://docs.microsoft.com/rest/api/playfab/economy/catalog/getcatalogconfig """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Catalog/GetCatalogConfig", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)
def DeleteGroup(request, callback, customData=None, extraHeaders=None): """ Deletes a group and all roles, invitations, join requests, and blocks associated with it. https://docs.microsoft.com/rest/api/playfab/groups/groups/deletegroup """ if not PlayFabSettings._internalSettings.EntityToken: raise PlayFabErrors.PlayFabException( "Must call GetEntityToken before calling this method") def wrappedCallback(playFabResult, error): if callback: callback(playFabResult, error) PlayFabHTTP.DoPost("/Group/DeleteGroup", request, "X-EntityToken", PlayFabSettings._internalSettings.EntityToken, wrappedCallback, customData, extraHeaders)