public LootLockerServerRequest(string endpoint, LootLockerHTTPMethod httpMethod = LootLockerHTTPMethod.GET, byte[] upload = null, string uploadName = null, string uploadType = null, Dictionary <string, string> body = null, Dictionary <string, string> extraHeaders = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User, bool isFileUpload = true) { this.retryCount = 0; this.endpoint = endpoint; this.httpMethod = httpMethod; this.payload = null; this.upload = upload; this.uploadName = uploadName; this.uploadType = uploadType; this.jsonPayload = null; this.extraHeaders = extraHeaders != null && extraHeaders.Count == 0 ? null : extraHeaders; // Force extra headers to null if empty dictionary was supplied this.queryParams = null; this.adminCall = callerRole; this.form = new WWWForm(); foreach (var kvp in body) { this.form.AddField(kvp.Key, kvp.Value); } this.form.AddBinaryData("file", upload, uploadName); bool isNonPayloadMethod = (this.httpMethod == LootLockerHTTPMethod.GET || this.httpMethod == LootLockerHTTPMethod.HEAD || this.httpMethod == LootLockerHTTPMethod.OPTIONS); if (this.payload != null && isNonPayloadMethod) { LootLockerSDKManager.DebugMessage("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint); } }
public LootLockerServerRequest(string endpoint, LootLockerHTTPMethod httpMethod = LootLockerHTTPMethod.GET, string payload = null, Dictionary <string, string> extraHeaders = null, Dictionary <string, string> queryParams = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User) { this.retryCount = 0; this.endpoint = endpoint; this.httpMethod = httpMethod; this.jsonPayload = payload; this.upload = null; this.uploadName = null; this.uploadType = null; this.payload = null; this.extraHeaders = extraHeaders != null && extraHeaders.Count == 0 ? null : extraHeaders; // Force extra headers to null if empty dictionary was supplied this.queryParams = queryParams != null && queryParams.Count == 0 ? null : queryParams; this.adminCall = callerRole; bool isNonPayloadMethod = (this.httpMethod == LootLockerHTTPMethod.GET || this.httpMethod == LootLockerHTTPMethod.HEAD || this.httpMethod == LootLockerHTTPMethod.OPTIONS); this.form = null; if (!string.IsNullOrEmpty(jsonPayload) && isNonPayloadMethod) { LootLockerSDKManager.DebugMessage("WARNING: Payloads should not be sent in GET, HEAD, OPTIONS, requests. Attempted to send a payload to: " + this.httpMethod.ToString() + " " + this.endpoint); } }
public static void UploadFile(string endPoint, LootLockerHTTPMethod httpMethod, byte[] file, string fileName = "file", string fileContentType = "text/plain", Dictionary <string, string> body = null, Action <LootLockerResponse> onComplete = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User) { Dictionary <string, string> headers = new Dictionary <string, string>(); if (useAuthToken) { headers = new Dictionary <string, string>(); headers.Add(callerRole == LootLockerCallerRole.Admin ? "x-auth-token" : "x-session-token", LootLockerBaseServerAPI.activeConfig.token); } LootLockerBaseServerAPI.I.SwitchURL(callerRole); new LootLockerServerRequest(endPoint, httpMethod, file, fileName, fileContentType, body, headers, callerRole: callerRole).Send((response) => { onComplete?.Invoke(response); }); }
public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, string body = null, Action <LootLockerResponse> onComplete = null, bool useAuthToken = true, LootLocker.LootLockerEnums.LootLockerCallerRole callerRole = LootLocker.LootLockerEnums.LootLockerCallerRole.User) { #if UNITY_EDITOR LootLockerSDKManager.DebugMessage("Caller Type: " + callerRole.ToString()); #endif Dictionary <string, string> headers = new Dictionary <string, string>(); if (useAuthToken) { headers = new Dictionary <string, string>(); headers.Add(callerRole == LootLocker.LootLockerEnums.LootLockerCallerRole.Admin ? "x-auth-token" : "x-session-token", LootLockerBaseServerAPI.activeConfig.token); } LootLockerBaseServerAPI.I.SwitchURL(callerRole); new LootLockerServerRequest(endPoint, httpMethod, body, headers, callerRole: callerRole).Send((response) => { onComplete?.Invoke(response); }); }