예제 #1
0
        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);
            }
        }
예제 #2
0
 public static void CallAPI(string endPoint, LootLockerHTTPMethod httpMethod, Dictionary <string, object> body = null, Action <LootLockerResponse> onComplete = null)
 {
     new LootLockerServerRequest(endPoint, httpMethod, body).Send((response) =>
     {
         onComplete?.Invoke(response);
     });
 }
예제 #3
0
        public static void CallDomainAuthAPI(string endPoint, LootLockerHTTPMethod httpMethod, string body = null, Action <LootLockerResponse> onComplete = null)
        {
            if (LootLockerConfig.current.domainKey.ToString().Length == 0)
            {
                #if UNITY_EDITOR
                LootLockerSDKManager.DebugMessage("LootLocker domain key must be set in settings", true);
                #endif
                onComplete?.Invoke(LootLockerResponseFactory.Error <LootLockerResponse>("LootLocker domain key must be set in settings"));

                return;
            }

            Dictionary <string, string> headers = new Dictionary <string, string>();
            headers.Add("domain-key", LootLockerConfig.current.domainKey);

            if (LootLockerConfig.current.developmentMode)
            {
                headers.Add("is-development", "true");
            }

            LootLockerBaseServerAPI.I.SwitchURL(LootLockerCallerRole.Base);

            new LootLockerServerRequest(endPoint, httpMethod, body, headers, callerRole: LootLockerCallerRole.Base).Send((response) =>
            {
                onComplete?.Invoke(response);
            });
        }
예제 #4
0
        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", callerRole == LootLocker.LootLockerEnums.LootLockerCallerRole.Admin ? LootLockerConfig.current.adminToken : LootLockerConfig.current.token);
            }

            if (LootLockerConfig.current != null)
            {
                headers.Add(LootLockerConfig.current.dateVersion.key, LootLockerConfig.current.dateVersion.value);
            }

            LootLockerBaseServerAPI.I.SwitchURL(callerRole);

            new LootLockerServerRequest(endPoint, httpMethod, body, headers, callerRole: callerRole).Send((response) =>
            {
                onComplete?.Invoke(response);
            });
        }
예제 #5
0
        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);
            });
        }
예제 #6
0
        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);
            }
        }
예제 #7
0
 public EndPointClass(string endPoint, LootLockerHTTPMethod httpMethod)
 {
     this.endPoint   = endPoint;
     this.httpMethod = httpMethod;
 }