Пример #1
0
        public async Task<File> GetFileContents(string projectKey, string repositorySlug, string path, RequestOptions requestOptions = null)
        {
            string requestUrl = UrlBuilder.FormatRestApiUrl(ONE_FILE, requestOptions, projectKey, repositorySlug, path);
            File response = await _httpWorker.GetAsync<File>(requestUrl);

            return response;
        }
Пример #2
0
        // todo: refactor, since I don't like this logic. At least use string builder
        // todo: UrlEncode when necessary
        public static string FormatRestApiUrl(string restUrl, RequestOptions requestOptions = null, params string[] inputs)
        {
            StringParamsValidator(inputs.Length, inputs);

            string resultingUrl = String.Format(restUrl, UrlEscapeParams(inputs));

            if (requestOptions != null)
            {
                string partialUrl = "";
                bool urlHasQueryParams = restUrl.IndexOf('?') > -1;

                if (requestOptions.Limit != null && requestOptions.Limit.HasValue && requestOptions.Limit.Value > 0)
                {
                    partialUrl += string.IsNullOrWhiteSpace(partialUrl) && !urlHasQueryParams ? "?" : "&";
                    partialUrl += string.Format("limit={0}", requestOptions.Limit.Value);
                }

                if (requestOptions.Start != null && requestOptions.Start.HasValue && requestOptions.Start.Value >= 0)
                {
                    partialUrl += string.IsNullOrWhiteSpace(partialUrl) && !urlHasQueryParams ? "?" : "&";
                    partialUrl += string.Format("start={0}", requestOptions.Start.Value);
                }

                if (!String.IsNullOrWhiteSpace(requestOptions.At))
                {
                    partialUrl += string.IsNullOrWhiteSpace(partialUrl) && !urlHasQueryParams ? "?" : "&";
                    partialUrl += string.Format("at={0}", requestOptions.At);
                }

                resultingUrl += partialUrl;
            }

            return resultingUrl;
        }
Пример #3
0
        public async Task<ResponseWrapper<Hook>> GetHooks(string projectKey, string repositorySlug,RequestOptions requestOptions = null)
        {
            string requestUrl = UrlBuilder.FormatRestApiUrl(MANY_HOOKS, requestOptions, projectKey, repositorySlug);

            ResponseWrapper<Hook> response = await _httpWorker.GetAsync<ResponseWrapper<Hook>>(requestUrl);

            return response;
        }
Пример #4
0
        public async Task<ResponseWrapper<Repository>> Get(string projectKey, RequestOptions requestOptions = null)
        {
            string requestUrl = UrlBuilder.FormatRestApiUrl(MANY_REPOSITORIES, requestOptions, projectKey);

            ResponseWrapper<Repository> response = await _httpWorker.GetAsync<ResponseWrapper<Repository>>(requestUrl);

            return response;
        }
Пример #5
0
        public async Task<ResponseWrapper<Project>> Get(RequestOptions requestOptions = null)
        {
            string requestUrl = UrlBuilder.FormatRestApiUrl(MANY_PROJECTS, requestOptions);

            ResponseWrapper<Project> response = await _httpWorker.GetAsync<ResponseWrapper<Project>>(requestUrl).ConfigureAwait(false);

            return response;
        }
Пример #6
0
        public async Task<ResponseWrapper<Permission>> GetUsers(string projectKey, RequestOptions requestOptions = null)
        {
            string requestUrl = UrlBuilder.FormatRestApiUrl(PERMISSION_USERS, requestOptions, projectKey);

            ResponseWrapper<Permission> response = await _httpWorker.GetAsync<ResponseWrapper<Permission>>(requestUrl).ConfigureAwait(false);

            return response;
        }
Пример #7
0
        public async Task<ResponseWrapper<Branch>> Get(string projectKey, string repositorySlug, RequestOptions requestOptions = null)
        {
            string requestUrl = UrlBuilder.FormatRestApiUrl(MANY_BRANCHES, requestOptions, projectKey, repositorySlug);

            ResponseWrapper<Branch> response = await _httpWorker.GetAsync<ResponseWrapper<Branch>>(requestUrl).ConfigureAwait(false);

            return response;
        }
Пример #8
0
        /// <summary>
        /// Get one or many commits
        /// </summary>
        public async Task<ResponseWrapper<Commit>> Get(string projectKey, string repositorySlug, RequestOptions requestOptions = null, RequestOptionsForCommits commitRequestOptions = null)
        {
            string requestUrl = UrlBuilder.FormatRestApiUrlWithCommitOptions(MANY_COMMITS, requestOptions, commitRequestOptions, projectKey, repositorySlug);

            ResponseWrapper<Commit> response = await _httpWorker.GetAsync<ResponseWrapper<Commit>>(requestUrl).ConfigureAwait(false);

            return response;
        }
Пример #9
0
        public async Task<ResponseWrapper<Project>> Get(string filter, RequestOptions requestOptions = null)
        {
            string requestUrl = UrlBuilder.FormatRestApiUrl(MANY_GROUPS + "?filter={0}", requestOptions, filter);

            ResponseWrapper<Project> response = await _httpWorker.GetAsync<ResponseWrapper<Project>>(requestUrl).ConfigureAwait(false);

            return response;
        }
Пример #10
0
        public async Task<ResponseWrapper<Branch>> GetByCommitId(string projectKey, string repositorySlug, string commitId, RequestOptions requestOptions = null)
        {
            string requestUrl = UrlBuilder.FormatRestApiUrl(BRANCHES_FOR_COMMIT, requestOptions, projectKey, repositorySlug,
                commitId);

            ResponseWrapper<Branch> response = await _httpWorker.GetAsync<ResponseWrapper<Branch>>(requestUrl);

            return response;
        }
Пример #11
0
        public async Task<ResponseWrapper<RepoPermission>> Get(string projectKey, string repositorySlug,
            RequestOptions requestOptions = null)
        {
            var requestUrl = UrlBuilder.FormatRestApiUrl(PermissionsUrl, requestOptions, projectKey, repositorySlug);

            var response = await _httpWorker.GetAsync<ResponseWrapper<RepoPermission>>(requestUrl).ConfigureAwait(false);

            return response;
        }
Пример #12
0
        public async Task<Changes> GetChanges(string projectKey, string repositorySlug, string untilCommit, string sinceCommit = null, RequestOptions requestOptions = null)
        {
            string requestUrl = "";

            if (string.IsNullOrWhiteSpace(sinceCommit))
                requestUrl = UrlBuilder.FormatRestApiUrl(CHANGES_UNTIL, requestOptions, projectKey, repositorySlug, untilCommit);
            else
                requestUrl = UrlBuilder.FormatRestApiUrl(CHANGES_UNTIL_AND_SINCE, requestOptions, projectKey, repositorySlug, untilCommit, sinceCommit);

            Changes response = await _httpWorker.GetAsync<Changes>(requestUrl).ConfigureAwait(false);

            return response;
        }
Пример #13
0
        public async Task<ResponseWrapper<PullRequest>> Get(string projectKey, string repositorySlug, RequestOptions options = null, Direction direction = Direction.INCOMING,
            PullRequestState state = PullRequestState.OPEN, bool withAttributes = true, bool withProperties = true)
        {
            string requestUrl = UrlBuilder.ToRestApiUrl(string.Format(PULL_REQUEST, projectKey, repositorySlug))
                                          .WithOptions(options)
                                          .WithQueryParam("direction", direction.ToString())
                                          .WithQueryParam("state", state.ToString())
                                          .WithQueryParam("withAttributes", withAttributes.ToString())
                                          .WithQueryParam("withProperties", withProperties.ToString());

            var pr = await _httpWorker.GetAsync<ResponseWrapper<PullRequest>>(requestUrl).ConfigureAwait(false);

            return pr;

        }
Пример #14
0
        public static string FormatRestApiUrlWithCommitOptions(string restUrl, RequestOptions requestOptions = null, RequestOptionsForCommits commitRequestOptions = null, params string[] inputs)
        {
            string resultingUrl = FormatRestApiUrl(restUrl, requestOptions, inputs);

            if (commitRequestOptions != null)
            {
                string partialUrl = "";
                bool urlHasQueryParams = restUrl.IndexOf('?') > -1;

                if (!string.IsNullOrWhiteSpace(commitRequestOptions.Path))
                {
                    partialUrl += string.IsNullOrWhiteSpace(partialUrl) && !urlHasQueryParams ? "?" : "&";
                    partialUrl += string.Format("path={0}", commitRequestOptions.Path);
                }

                if (!string.IsNullOrWhiteSpace(commitRequestOptions.Since))
                {
                    partialUrl += string.IsNullOrWhiteSpace(partialUrl) && !urlHasQueryParams ? "?" : "&";
                    partialUrl += string.Format("since={0}", commitRequestOptions.Since);
                }

                if (!string.IsNullOrWhiteSpace(commitRequestOptions.Until))
                {
                    partialUrl += string.IsNullOrWhiteSpace(partialUrl) && !urlHasQueryParams ? "?" : "&";
                    partialUrl += string.Format("until={0}", commitRequestOptions.Until);
                }

                if (commitRequestOptions.WithCounts)
                {
                    partialUrl += string.IsNullOrWhiteSpace(partialUrl) && !urlHasQueryParams ? "?" : "&";
                    partialUrl += "withCounts=true";
                }

                resultingUrl += partialUrl;
            }

            return resultingUrl;
        }
Пример #15
0
            public FluentUrl WithOptions(RequestOptions options)
            {
                if (options == null)
                {
                    return this;
                }

                if (options.Limit.HasValue && options.Limit > 0)
                {
                    m_queryParams["limit"] = options.Limit.ToString();
                }

                if (options.Start.HasValue && options.Start >= 0)
                {
                    m_queryParams["start"] = options.Start.ToString();
                }

                if (!String.IsNullOrWhiteSpace(options.At))
                {
                    m_queryParams["at"] = options.At;
                }

                return this;
            }