Example #1
0
 void Awake()
 {
     if (singleton != null)
     {
         Destroy(gameObject);
     }
     else
     {
         singleton = this;
     }
 }
Example #2
0
        /// <summary>
        /// Searches characters.
        /// </summary>
        /// <param name="limit">The number of result</param>
        /// <param name="offset">The number of character to jump before search</param>
        /// <param name="Endpoint">The endpoint</param>
        /// <param name="SearchString">The search string</param>
        /// <returns></returns>
        /// <exception cref="System.InvalidOperationException">Limit 0 to 100 only</exception>
        public List <Characters> SearchCharacters(int limit           = 1,
                                                  int offset          = 200, string Endpoint = "v1/public/characters",
                                                  string SearchString = "")
        {
            //Marvel accept a maximum of 100 character by requests
            if (limit > 100)
            {
                throw new InvalidOperationException("Limit 0 to 100 only");
            }
            //1- Get the time
            t = DateTime.Now.TimeOfDay;
            //2- Calculate hash in accordance with marvel documentation
            hash = Tools.CalculateMD5LikeMarvel(t, pKey).ToLower();
            //3- Prepare the parameters
            urlParameters = "?nameStartsWith=" + HttpUtility.UrlEncode(SearchString) + "&ts=" + t.ToString().Replace(":", "").Replace(".", "") + "&limit=" + limit + "&offset=" + offset + "&apikey=" + Key + "&hash=" + hash;

            //4- Get the json response from marvel API
            string json = base.Execute(Endpoint, urlParameters);

            if (json != "")
            {
                List <Characters>    lc = null;
                CharacterDataWrapper cd = JsonConvert.DeserializeObject <CharacterDataWrapper>(json);

                if (cd.data != null)
                {
                    CharacterDataContainer CDC = cd.data;
                    if (CDC.results.Count > 0)
                    {
                        lc = CDC.results;
                    }
                }


                return(lc);
            }
            else
            {
                return(null);
            }
        }
Example #3
0
        public Characters GetCharacter(long id, string Endpoint = "v1/public/characters")
        {
            int limit  = 1;
            int offset = 0;

            //1- Get the time
            t = DateTime.Now.TimeOfDay;
            //2- Calculate hash in accordance with marvel documentation
            hash = Tools.CalculateMD5LikeMarvel(t, pKey).ToLower();
            //3- Prepare the parameters
            urlParameters = "/" + id + "?ts=" + t.ToString().Replace(":", "").Replace(".", "") + "&limit=" + limit + "&offset=" + offset + "&apikey=" + Key + "&hash=" + hash;

            //4- Get the json response from marvel API
            string json = base.Execute(Endpoint, urlParameters);

            if (json != "")
            {
                Characters           lc = null;
                CharacterDataWrapper cd = JsonConvert.DeserializeObject <CharacterDataWrapper>(json);

                if (cd.data != null)
                {
                    CharacterDataContainer CDC = cd.data;
                    if (CDC.results.Count > 0)
                    {
                        lc = CDC.results.First();
                    }
                }


                return(lc);
            }
            else
            {
                return(null);
            }
        }