Beispiel #1
0
 public void StartMultipartUpload(Version.FileDescriptor.Type fileDescriptorType, int partNumber, Action <ApiContainer> onSuccess, Action <ApiContainer> onError)
 {
     if (!IsInitialized)
     {
         onError?.Invoke(new ApiContainer
         {
             Error = "Unable to upload file: file not initialized."
         });
     }
     else
     {
         int latestVersionNumber = GetLatestVersionNumber();
         Version.FileDescriptor fileDescriptor = GetFileDescriptor(latestVersionNumber, fileDescriptorType);
         if (fileDescriptor == null)
         {
             onError?.Invoke(new ApiContainer
             {
                 Error = "Version record doesn't exist"
             });
         }
         else
         {
             UploadStatus     uploadStatus     = new UploadStatus(base.id, latestVersionNumber, fileDescriptorType, "start");
             ApiDictContainer apiDictContainer = new ApiDictContainer("url");
             apiDictContainer.OnSuccess = onSuccess;
             apiDictContainer.OnError   = onError;
             ApiDictContainer responseContainer = apiDictContainer;
             API.SendPutRequest(uploadStatus.Endpoint + "?partNumber=" + partNumber, responseContainer);
         }
     }
 }
Beispiel #2
0
        public ApiWorldInstance FetchInstance(int index, Action <ApiWorldInstance> success, Action <string> error = null)
        {
            if (index < 0 || index >= mWorldInstances.Count)
            {
                if (error != null)
                {
                    error("Instance index out of range.");
                }
                return(null);
            }
            string           idWithTags       = mWorldInstances[index].idWithTags;
            ApiDictContainer apiDictContainer = new ApiDictContainer();

            apiDictContainer.OnSuccess = delegate(ApiContainer c)
            {
                Dictionary <string, object> responseDictionary = (c as ApiDictContainer).ResponseDictionary;
                mWorldInstances[index] = new ApiWorldInstance(this, responseDictionary, c.DataTimestamp);
                if (success != null)
                {
                    success(mWorldInstances[index]);
                }
            };
            apiDictContainer.OnError = delegate(ApiContainer c)
            {
                if (error != null)
                {
                    error(c.Error);
                }
            };
            ApiDictContainer responseContainer = apiDictContainer;

            API.SendGetRequest("worlds/" + base.id + "/" + idWithTags, responseContainer, null, disableCache: true);
            return(mWorldInstances[index]);
        }
Beispiel #3
0
 public void FetchData(WorldData data, Action <Dictionary <string, object> > successCallback, Action <string> errorCallback)
 {
     if (base.id == null)
     {
         errorCallback("APIWorld.FetchData called with null id.");
     }
     else
     {
         string text = null;
         if (data != 0)
         {
         }
         text = "/metadata";
         ApiDictContainer apiDictContainer = new ApiDictContainer();
         apiDictContainer.OnSuccess = delegate(ApiContainer c)
         {
             if (successCallback != null)
             {
                 successCallback((c as ApiDictContainer).ResponseDictionary);
             }
         };
         apiDictContainer.OnError = delegate(ApiContainer c)
         {
             if (errorCallback != null)
             {
                 errorCallback(c.Error);
             }
         };
         ApiDictContainer responseContainer = apiDictContainer;
         API.SendGetRequest("worlds/" + base.id + text, responseContainer, null, disableCache: true);
     }
 }
Beispiel #4
0
        public static void DeleteFeedback(string feedbackId, Action successCallback, Action <string> errorCallback)
        {
            ApiDictContainer apiDictContainer = new ApiDictContainer();

            apiDictContainer.OnSuccess = delegate
            {
                if (successCallback != null)
                {
                    successCallback();
                }
            };
            apiDictContainer.OnError = delegate(ApiContainer c)
            {
                if (errorCallback != null)
                {
                    errorCallback(c.Error);
                }
            };
            ApiContainer responseContainer = apiDictContainer;

            API.SendDeleteRequest("/feedback/" + feedbackId, responseContainer);
        }
Beispiel #5
0
        public static void GenerateMergeCode(Action <Dictionary <string, object> > successCallback = null, Action <string> errorCallback = null)
        {
            ApiDictContainer apiDictContainer = new ApiDictContainer();

            apiDictContainer.OnSuccess = delegate(ApiContainer c)
            {
                if (successCallback != null)
                {
                    successCallback((c as ApiDictContainer).ResponseDictionary);
                }
            };
            apiDictContainer.OnError = delegate(ApiContainer c)
            {
                if (errorCallback != null)
                {
                    errorCallback(c.Error);
                }
            };
            ApiDictContainer responseContainer = apiDictContainer;

            SendPutRequest("auth/user/mergeToken", responseContainer);
        }
Beispiel #6
0
        public static void RemoveFromGroup(string objectId, Action successCallback, Action <string> errorCallback)
        {
            ApiDictContainer apiDictContainer = new ApiDictContainer();

            apiDictContainer.OnSuccess = delegate
            {
                if (successCallback != null)
                {
                    successCallback();
                }
            };
            apiDictContainer.OnError = delegate(ApiContainer c)
            {
                if (errorCallback != null)
                {
                    errorCallback(c.Error);
                }
            };
            ApiContainer responseContainer = apiDictContainer;

            API.SendDeleteRequest("favorites/" + objectId, responseContainer);
        }
Beispiel #7
0
        public void PutInstance(ApiWorldInstance inst, Action success, Action <string> error = null)
        {
            string idWithTags = inst.idWithTags;
            int    num        = -1;

            for (int i = 0; i < mWorldInstances.Count; i++)
            {
                if (mWorldInstances[i].idWithTags == idWithTags)
                {
                    mWorldInstances[i] = inst;
                }
            }
            bool newInstance = num == -1;
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            if (newInstance)
            {
                dictionary["id"] = inst.idWithTags;
                ApiWorldInstance.AccessType accessType = inst.GetAccessType();
                if (accessType == ApiWorldInstance.AccessType.InviteOnly)
                {
                    dictionary["private"] = inst.instanceCreator;
                }
                else
                {
                    dictionary["private"] = "false";
                }
                if (accessType == ApiWorldInstance.AccessType.FriendsOnly)
                {
                    dictionary["friends"] = inst.instanceCreator;
                }
                else
                {
                    dictionary["friends"] = "false";
                }
            }
            dictionary["name"] = inst.instanceName;
            string tagString = inst.GetTagString();

            if (tagString != null)
            {
                dictionary["tags"] = tagString;
            }
            ApiDictContainer apiDictContainer = new ApiDictContainer();

            apiDictContainer.OnSuccess = delegate(ApiContainer c)
            {
                Dictionary <string, object> responseDictionary = (c as ApiDictContainer).ResponseDictionary;
                if (newInstance && responseDictionary != null)
                {
                    mWorldInstances.Add(new ApiWorldInstance(this, responseDictionary, c.DataTimestamp));
                }
                if (success != null)
                {
                    success();
                }
            };
            apiDictContainer.OnError = delegate(ApiContainer c)
            {
                if (error != null)
                {
                    error(c.Error);
                }
            };
            ApiDictContainer responseContainer = apiDictContainer;

            API.SendPutRequest("worlds/" + base.id + "/" + idWithTags, responseContainer, dictionary);
        }
Beispiel #8
0
 public void Fetch(string instanceID = null, string platforms = null, Action <ApiContainer> onSuccess = null, Action <ApiContainer> onFailure = null, Dictionary <string, object> parameters = null, bool compatibleVersionsOnly = true)
 {
     if (string.IsNullOrEmpty(base.id))
     {
         onFailure(new ApiContainer
         {
             Error = "APIWorld.Fetch called with null id."
         });
     }
     else if (localWorlds.ContainsKey(base.id))
     {
         ApiModelContainer <ApiWorld> obj = new ApiModelContainer <ApiWorld>(localWorlds[base.id]);
         onSuccess(obj);
     }
     else
     {
         if (parameters == null)
         {
             parameters = new Dictionary <string, object>();
         }
         if (compatibleVersionsOnly)
         {
             parameters["maxUnityVersion"] = VERSION.UnityVersion;
             parameters["minUnityVersion"] = MIN_LOADABLE_VERSION.UnityVersion;
             parameters["maxAssetVersion"] = VERSION.ApiVersion;
             parameters["minAssetVersion"] = MIN_LOADABLE_VERSION.ApiVersion;
         }
         if (platforms != null)
         {
             parameters["platform"] = platforms;
         }
         if (!string.IsNullOrEmpty(instanceID))
         {
             ApiDictContainer apiDictContainer = new ApiDictContainer("users");
             apiDictContainer.OnSuccess = delegate(ApiContainer c)
             {
                 List <object>         json       = (c as ApiDictContainer).ResponseDictionary["users"] as List <object>;
                 IEnumerable <APIUser> enumerable = API.ConvertJsonListToModelList <APIUser>(json, c.DataTimestamp);
                 if (enumerable == null)
                 {
                     c.Error = "Failed to decode user model";
                     onFailure(c);
                 }
                 else
                 {
                     int num = enumerable.Count();
                     if (instances == null)
                     {
                         instances = new Dictionary <string, int>();
                     }
                     if (!mWorldInstances.Any((ApiWorldInstance w) => w.idWithTags == instanceID))
                     {
                         mWorldInstances.Add(new ApiWorldInstance(this, instanceID, num));
                         instances.Add(instanceID, num);
                     }
                     ApiWorldInstance apiWorldInstance = worldInstances.First((ApiWorldInstance w) => w.idWithTags == instanceID);
                     apiWorldInstance.count = num;
                     apiWorldInstance.users = enumerable.ToList();
                     onSuccess(c);
                 }
             };
             apiDictContainer.OnError = onFailure;
             ApiDictContainer responseContainer = apiDictContainer;
             API.SendRequest("worlds/" + base.id + "/" + instanceID, HTTPMethods.Get, responseContainer, parameters, authenticationRequired: true, disableCache: true);
         }
         else
         {
             ApiModelContainer <ApiWorld> apiModelContainer = new ApiModelContainer <ApiWorld>(this);
             apiModelContainer.OnSuccess = onSuccess;
             apiModelContainer.OnError   = onFailure;
             ApiModelContainer <ApiWorld> responseContainer2 = apiModelContainer;
             API.SendRequest("worlds/" + base.id, HTTPMethods.Get, responseContainer2, parameters, authenticationRequired: true, disableCache: true);
         }
     }
 }