Example #1
0
        public List <APIInfo> Get(string apiName, string version)
        {
            ValidateApiKey(apiName, version);

            APIKey key = new APIKey(apiName, version);

            apiStore.TryGetValue(key, out List <APIInfo> resp);

            return(resp);
        }
Example #2
0
        public bool Save(string apiName, string version, string url, string method)
        {
            ValidateApiKey(apiName, version);

            if (string.IsNullOrEmpty(url))
            {
                throw new Exception("A url não foi informada");
            }

            if (string.IsNullOrEmpty(method))
            {
                throw new Exception("Metodo http não foi informado");
            }

            Uri uri = new Uri(url);

            string path = uri.LocalPath;

            if (path.IndexOf('/') == 0)
            {
                path = path.Remove(0, 1);
            }

            if (path.EndsWith("/", StringComparison.Ordinal))
            {
                path = path.Remove(path.Length - 1, 1);
            }

            string[] pathList = path.Split(new char[] { '/' });

            APIKey  key  = new APIKey(apiName, version);
            APIInfo info = new APIInfo(url, uri, pathList, method);

            List <APIInfo> apiInfo;

            if (!apiStore.TryGetValue(key, out apiInfo))
            {
                apiInfo = new List <APIInfo>();

                while (apiStore.TryAdd(key, apiInfo))
                {
                }
            }

            apiInfo.Add(info);

            return(true);
        }