コード例 #1
0
        public async Task <PackageInfo> GetPackageInfo(string feedName, string packageName)
        {
            var filter  = WebUtility.UrlEncode($"Id eq '{packageName}'");
            var url     = $"https://www.myget.org/F/{feedName}/api/v2/Packages()?$filter={filter}&$orderby=Published desc&$top=10";
            var content = await _restfulApiClient.Get(url);

            var searchResult = _serializer.Deserialize(content);

            var packageInfo = searchResult.d[0];

            return(new PackageInfo(
                       packageInfo.Id.Value.ToString(),
                       packageInfo.Version.Value.ToString(),
                       (int)packageInfo.DownloadCount.Value));
        }
コード例 #2
0
        public async Task <PackageInfo> GetPackageInfo(string packageName, bool includePreReleases)
        {
            var url     = $"https://api-v3search-0.nuget.org/query?q={packageName}&skip=0&take=10&prerelease={includePreReleases}";
            var content = await _restfulApiClient.Get(url);

            var searchResult = _serializer.Deserialize(content);

            var packageInfo = (searchResult.data as IEnumerable <dynamic>).First(
                x => x.id.Value.ToString()
                .Equals(packageName, StringComparison.InvariantCultureIgnoreCase));

            return(new PackageInfo(
                       packageInfo.id.Value.ToString(),
                       packageInfo.version.Value.ToString(),
                       (int)packageInfo.totalDownloads.Value));
        }
コード例 #3
0
        public async Task <IList <Build> > GetBuilds(
            string account,
            string project,
            int buildCount,
            string branch = null,
            bool includeBuildsFromPullRequest = true)
        {
            var url = $"https://circleci.com/api/v1/project/{account}/{project}";

            if (!string.IsNullOrEmpty(branch))
            {
                url = $"{url}/tree/{WebUtility.UrlEncode(branch)}";
            }

            url = $"{url}?limit={buildCount}";

            var       builds      = new List <Build>();
            var       attempt     = 0;
            const int maxAttempts = 5;

            do
            {
                var result = await _restfulApiClient.Get(url);

                if (result == null)
                {
                    break;
                }

                var batch = _parser.Parse(result);

                if (batch == null || batch.Count == 0)
                {
                    break;
                }

                builds.AddRange(batch.Where(build => includeBuildsFromPullRequest || !build.FromPullRequest));
                url = $"{url}&offset={attempt}";
            } while (
                builds.Count < buildCount &&
                ++attempt < maxAttempts);

            return(builds.Count > buildCount?builds.Take(buildCount).ToList() : builds);
        }
コード例 #4
0
        public void RestfulApiClient_Get_Return_StatusCode_200()
        {
            //Arrange
            string         url = "https://portalapp-dev.wistron.com/api/Test/GetRuntimeError2";
            HttpCallResult expectedResponse = new HttpCallResult
            {
                FaultInfo     = null,
                ReturnContent = "{\"data\":null,\"rtnCode\":5000,\"rtnMsg\":\"伺服器/資料庫錯誤\"}",
                StatusCode    = "200"
            };

            //Act
            HttpCallResult actualResponse = _targetObj.Get(url, _header);

            //Assert
            Assert.AreEqual(expectedResponse.FaultInfo, actualResponse.FaultInfo);
            Assert.AreEqual(expectedResponse.ReturnContent, actualResponse.ReturnContent);
            Assert.AreEqual(expectedResponse.StatusCode, actualResponse.StatusCode);
        }
コード例 #5
0
        public async Task <IList <Build> > GetBuilds(
            string account,
            string project,
            int buildCount,
            string branch = null,
            bool includeBuildsFromPullRequest = true)
        {
            var url = $"https://ci.appveyor.com/api/projects/{account}/{project}/history?recordsNumber={buildCount}";

            if (!string.IsNullOrEmpty(branch))
            {
                url = $"{url}&branch={branch}";
            }

            var builds   = new List <Build>();
            var attempts = 5;

            do
            {
                var result = await _restfulApiClient.Get(url);

                if (result == null)
                {
                    break;
                }

                var batch = _parser.Parse(result);

                if (batch == null || batch.Count == 0)
                {
                    break;
                }

                builds.AddRange(batch.Where(build => includeBuildsFromPullRequest || !build.FromPullRequest));
                url = $"{url}&startBuildId={batch[batch.Count - 1].BuildId}";
            } while (
                builds.Count < buildCount &&
                --attempts > 0);

            return(builds.Count > buildCount?builds.Take(buildCount).ToList() : builds);
        }
コード例 #6
0
        public async Task <IList <Build> > GetBuilds(
            string account,
            string project,
            int buildCount,
            string branch = null,
            bool includeBuildsFromPullRequest = true)
        {
            const double fixedAmountOfBuildsPerRequestForTravisCi = 25;
            const double factor   = 5;
            var          attempts = Math.Ceiling((buildCount / fixedAmountOfBuildsPerRequestForTravisCi) * factor);

            var url = $"https://api.travis-ci.org/repos/{account}/{project}/builds";

            var builds = new List <Build>();

            do
            {
                var result = await _restfulApiClient.Get(url);

                if (result == null)
                {
                    break;
                }

                var batch = _parser.Parse(result);

                if (batch == null || batch.Count == 0)
                {
                    break;
                }

                builds.AddRange(batch
                                .Where(build => string.IsNullOrEmpty(branch) || build.Branch == branch)
                                .Where(build => includeBuildsFromPullRequest || !build.FromPullRequest));
                url = $"{url}?after_number={batch[batch.Count -1].BuildNumber}";
            } while (
                builds.Count < buildCount &&
                --attempts > 0);

            return(builds.Count > buildCount?builds.Take(buildCount).ToList() : builds);
        }