Task <StacManResponse <Tag> > ITagMethods.GetByName(string site, IEnumerable <string> tags, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate, Tags.Sort?sort, int?min, int?max, DateTime?mindate, DateTime?maxdate, string minname, string maxname, Order?order)
        {
            ValidateString(site, "site");
            ValidateEnumerable(tags, "tags");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, min: min, max: max, mindate: mindate, maxdate: maxdate, minname: minname, maxname: maxname);

            var ub = new ApiUrlBuilder(Version, String.Format("/tags/{0}/info", String.Join(";", tags.Select(HttpUtility.UrlEncode))), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", min);
            ub.AddParameter("max", max);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("min", minname);
            ub.AddParameter("max", maxname);
            ub.AddParameter("order", order);

            return(CreateApiTask <Tag>(ub, HttpMethod.GET, "/tags/{tags}/info"));
        }
Exemple #2
0
        Task <StacManResponse <Badge> > IBadgeMethods.GetByIds(string site, IEnumerable <int> ids, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate, Badges.AllSort?sort, Badges.Rank?minrank, Badges.Rank?maxrank, string minname, string maxname, Badges.BadgeType?mintype, Badges.BadgeType?maxtype, Order?order)
        {
            ValidateString(site, "site");
            ValidateEnumerable(ids, "ids");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, minrank: minrank, maxrank: maxrank, minname: minname, maxname: maxname, mintype: mintype, maxtype: maxtype);

            var ub = new ApiUrlBuilder(String.Format("/badges/{0}", String.Join(";", ids)), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", minrank);
            ub.AddParameter("max", maxrank);
            ub.AddParameter("min", minname);
            ub.AddParameter("max", maxname);
            ub.AddParameter("min", mintype);
            ub.AddParameter("max", maxtype);
            ub.AddParameter("order", order);

            return(CreateApiTask <Badge>(ub, "/badges/{ids}"));
        }
        Task<StacManResponse<Badge>> IBadgeMethods.GetAll(string site, string filter, int? page, int? pagesize, DateTime? fromdate, DateTime? todate, Badges.AllSort? sort, Badges.Rank? minrank, Badges.Rank? maxrank, string minname, string maxname, Badges.BadgeType? mintype, Badges.BadgeType? maxtype, Order? order, string inname)
        {
            ValidateString(site, "site");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, minrank: minrank, maxrank: maxrank, minname: minname, maxname: maxname, mintype: mintype, maxtype: maxtype);

            var ub = new ApiUrlBuilder(Version, "/badges", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", minrank);
            ub.AddParameter("max", maxrank);
            ub.AddParameter("min", minname);
            ub.AddParameter("max", maxname);
            ub.AddParameter("min", mintype);
            ub.AddParameter("max", maxtype);
            ub.AddParameter("order", order);
            ub.AddParameter("inname", inname);

            return CreateApiTask<Badge>(ub, HttpMethod.GET, "/badges");
        }
Exemple #4
0
        private void GetApiResponse <T>(ApiUrlBuilder ub, HttpMethod httpMethod, string backoffKey, Action <StacManResponse <T> > callback) where T : StacManType
        {
            var response = new StacManResponse <T>();

            ub.AddParameter("key", Key);

            Action <string> successCallback = rawData =>
            {
                try
                {
                    response.RawData = rawData;
                    response.Data    = ParseApiResponse <Wrapper <T> >(Serializer.Deserialize <Dictionary <string, object> >(response.RawData), backoffKey);

                    if (response.Data.ErrorId.HasValue)
                    {
                        throw new Exceptions.StackExchangeApiException(response.Data.ErrorId.Value, response.Data.ErrorName, response.Data.ErrorMessage);
                    }

                    response.Success = true;
                }
                catch (Exception ex)
                {
                    response.Success = false;
                    response.Error   = ex;
                }

                callback(response);
            };

            Action <Exception> errorCallback = ex =>
            {
                response.Success = false;
                response.Error   = ex;
                callback(response);
            };


            var urlManager = this.urlManager; // snapshot

            if (httpMethod == HttpMethod.POST)
            {
                var url = ub.BaseUrl;
                if (urlManager != null)
                {
                    url = urlManager(url);
                }
                response.ApiUrl = url;
                FetchApiResponseWithPOST(url, ub.QueryString(), successCallback, errorCallback);
            }
            else
            {
                var url = ub.ToString();
                if (urlManager != null)
                {
                    url = urlManager(url);
                }
                response.ApiUrl = url;
                FetchApiResponseWithGET(url, successCallback, errorCallback);
            }
        }
        Task<StacManResponse<Post>> IPostMethods.GetByIds(string site, IEnumerable<int> ids, string filter = null, int? page = null, int? pagesize = null, DateTime? fromdate = null, DateTime? todate = null, Posts.Sort? sort = null, DateTime? mindate = null, DateTime? maxdate = null, int? min = null, int? max = null, Order? order = null)
        {
            var filterObj = ValidateAndGetFilter(filter);

            ValidateString(site, "site");
            ValidateEnumerable(ids, "ids");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate, min: min, max: max);

            var ub = new ApiUrlBuilder(String.Format("/posts/{0}", String.Join(";", ids)), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("min", min);
            ub.AddParameter("max", max);
            ub.AddParameter("order", order);

            return CreateApiTask<Post>(ub, filterObj, "/posts/{ids}");
        }
        Task<StacManResponse<Answer>> IAnswerMethods.GetAll(string site, string filter = null, int? page = null, int? pagesize = null, DateTime? fromdate = null, DateTime? todate = null, Answers.Sort? sort = null, DateTime? mindate = null, DateTime? maxdate = null, int? min = null, int? max = null, Order? order = null)
        {
            var filterObj = ValidateAndGetFilter(filter);

            ValidateString(site, "site");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate, min: min, max: max);

            var ub = new ApiUrlBuilder("/answers", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("min", min);
            ub.AddParameter("max", max);
            ub.AddParameter("order", order);

            return CreateApiTask<Answer>(ub, filterObj, "/answers");
        }
Exemple #7
0
 public ApiRequest(StacManClient client, ApiUrlBuilder ub, HttpMethod httpMethod, string backoffKey)
 {
     Client     = client;
     UrlBuilder = ub;
     HttpMethod = httpMethod;
     BackoffKey = backoffKey;
 }
        Task<StacManResponse<Question>> ISearchMethods.GetSimilar(string site, string filter = null, int? page = null, int? pagesize = null, DateTime? fromdate = null, DateTime? todate = null, Questions.SearchSort? sort = null, DateTime? mindate = null, DateTime? maxdate = null, int? min = null, int? max = null, Order? order = null, string tagged = null, string nottagged = null, string inttitle = null)
        {
            var filterObj = ValidateAndGetFilter(filter);

            ValidateString(site, "site");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate, min: min, max: max);

            var ub = new ApiUrlBuilder("/similar", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("min", min);
            ub.AddParameter("max", max);
            ub.AddParameter("order", order);
            ub.AddParameter("tagged", tagged);
            ub.AddParameter("nottagged", nottagged);
            ub.AddParameter("inttitle", inttitle);

            return CreateApiTask<Question>(ub, filterObj, "/similar");
        }
        Task <StacManResponse <Question> > ISearchMethods.GetSimilar(string site, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate, Questions.SearchSort?sort, DateTime?mindate, DateTime?maxdate, int?min, int?max, Order?order, string tagged, string nottagged, string intitle)
        {
            ValidateString(site, "site");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate, min: min, max: max);

            var ub = new ApiUrlBuilder(Version, "/similar", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("min", min);
            ub.AddParameter("max", max);
            ub.AddParameter("order", order);
            ub.AddParameter("tagged", tagged);
            ub.AddParameter("nottagged", nottagged);
            ub.AddParameter("intitle", intitle);

            return(CreateApiTask <Question>(ub, HttpMethod.GET, "/similar"));
        }
Exemple #10
0
        Task <StacManResponse <Badge> > IBadgeMethods.GetAll(string site, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate, Badges.AllSort?sort, Badges.Rank?minrank, Badges.Rank?maxrank, string minname, string maxname, Badges.BadgeType?mintype, Badges.BadgeType?maxtype, Order?order, string inname)
        {
            ValidateString(site, "site");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, minrank: minrank, maxrank: maxrank, minname: minname, maxname: maxname, mintype: mintype, maxtype: maxtype);

            var ub = new ApiUrlBuilder("/badges", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", minrank);
            ub.AddParameter("max", maxrank);
            ub.AddParameter("min", minname);
            ub.AddParameter("max", maxname);
            ub.AddParameter("min", mintype);
            ub.AddParameter("max", maxtype);
            ub.AddParameter("order", order);
            ub.AddParameter("inname", inname);

            return(CreateApiTask <Badge>(ub, "/badges"));
        }
        Task<StacManResponse<Badge>> IBadgeMethods.GetByIds(string site, IEnumerable<int> ids, string filter = null, int? page = null, int? pagesize = null, DateTime? fromdate = null, DateTime? todate = null, Badges.AllSort? sort = null, Badges.Rank? minrank = null, Badges.Rank? maxrank = null, string minname = null, string maxname = null, Badges.BadgeType? mintype = null, Badges.BadgeType? maxtype = null, Order? order = null)
        {
            var filterObj = ValidateAndGetFilter(filter);

            ValidateString(site, "site");
            ValidateEnumerable(ids, "ids");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, minrank: minrank, maxrank: maxrank, minname: minname, maxname: maxname, mintype: mintype, maxtype: maxtype);

            var ub = new ApiUrlBuilder(String.Format("/badges/{0}", String.Join(";", ids)), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", minrank);
            ub.AddParameter("max", maxrank);
            ub.AddParameter("min", minname);
            ub.AddParameter("max", maxname);
            ub.AddParameter("min", mintype);
            ub.AddParameter("max", maxtype);
            ub.AddParameter("order", order);

            return CreateApiTask<Badge>(ub, filterObj, "/badges/{ids}");
        }
        Task<StacManResponse<Question>> ISearchMethods.GetMatches(string site, string filter, int? page, int? pagesize, DateTime? fromdate, DateTime? todate, Questions.SearchSort? sort, DateTime? mindate, DateTime? maxdate, int? min, int? max, Order? order, string tagged, string nottagged, string intitle)
        {
            ValidateString(site, "site");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate, min: min, max: max);

            var ub = new ApiUrlBuilder(Version, "/search", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("min", min);
            ub.AddParameter("max", max);
            ub.AddParameter("order", order);
            ub.AddParameter("tagged", tagged);
            ub.AddParameter("nottagged", nottagged);
            ub.AddParameter("intitle", intitle);

            return CreateApiTask<Question>(ub, HttpMethod.GET, "/search");
        }
        Task <StacManResponse <Tag> > ITagMethods.GetModeratorOnly(string site, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate, Tags.Sort?sort, int?min, int?max, DateTime?mindate, DateTime?maxdate, string minname, string maxname, Order?order, string inname)
        {
            ValidateString(site, "site");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, min: min, max: max, mindate: mindate, maxdate: maxdate, minname: minname, maxname: maxname);

            var ub = new ApiUrlBuilder(Version, "/tags/moderator-only", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", min);
            ub.AddParameter("max", max);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("min", minname);
            ub.AddParameter("max", maxname);
            ub.AddParameter("order", order);
            ub.AddParameter("inname", inname);

            return(CreateApiTask <Tag>(ub, HttpMethod.GET, "/tags/moderator-only"));
        }
        Task<StacManResponse<Error>> IErrorMethods.Simulate(int id, string filter)
        {
            var ub = new ApiUrlBuilder(Version, String.Format("/errors/{0}", id), useHttps: false);

            ub.AddParameter("filter", filter);

            return CreateApiTask<Error>(ub, HttpMethod.GET, "/errors/{id}");
        }
        Task <StacManResponse <Error> > IErrorMethods.Simulate(int id, string filter)
        {
            var ub = new ApiUrlBuilder(Version, String.Format("/errors/{0}", id), useHttps: false);

            ub.AddParameter("filter", filter);

            return(CreateApiTask <Error>(ub, HttpMethod.GET, "/errors/{id}"));
        }
        Task <StacManResponse <Filter> > IFilterMethods.Read(IEnumerable <string> filters, string filter)
        {
            ValidateEnumerable(filters, "filters");

            var ub = new ApiUrlBuilder(Version, String.Format("/filters/{0}", String.Join(";", filters.Select(HttpUtility.UrlEncode))), useHttps: false);

            ub.AddParameter("filter", filter);

            return(CreateApiTask <Filter>(ub, HttpMethod.GET, "/filters/{filters}"));
        }
        Task<StacManResponse<Filter>> IFilterMethods.Read(IEnumerable<string> filters, string filter)
        {
            ValidateEnumerable(filters, "filters");

            var ub = new ApiUrlBuilder(Version, String.Format("/filters/{0}", String.Join(";", filters.Select(HttpUtility.UrlEncode))), useHttps: false);

            ub.AddParameter("filter", filter);

            return CreateApiTask<Filter>(ub, HttpMethod.GET, "/filters/{filters}");
        }
        Task <StacManResponse <Info> > IInfoMethods.Get(string site, string filter)
        {
            ValidateString(site, "site");

            var ub = new ApiUrlBuilder(Version, "/info", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);

            return(CreateApiTask <Info>(ub, HttpMethod.GET, "/info"));
        }
        Task<StacManResponse<Info>> IInfoMethods.Get(string site, string filter)
        {
            ValidateString(site, "site");

            var ub = new ApiUrlBuilder(Version, "/info", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);

            return CreateApiTask<Info>(ub, HttpMethod.GET, "/info");
        }
        Task<StacManResponse<Error>> IErrorMethods.Simulate(int id, string filter = null)
        {
            var filterObj = ValidateAndGetFilter(filter);


            var ub = new ApiUrlBuilder(String.Format("/errors/{0}", id), useHttps: false);

            ub.AddParameter("filter", filter);

            return CreateApiTask<Error>(ub, filterObj, "/errors/{id}");
        }
        Task <StacManResponse <Filter> > IFilterMethods.Create(string filter, IEnumerable <string> include, IEnumerable <string> exclude, string @base, bool? @unsafe)
        {
            var ub = new ApiUrlBuilder(Version, "/filters/create", useHttps: false);

            ub.AddParameter("filter", filter);
            ub.AddParameter("include", include);
            ub.AddParameter("exclude", exclude);
            ub.AddParameter("base", @base);
            ub.AddParameter("unsafe", @unsafe);

            return(CreateApiTask <Filter>(ub, HttpMethod.GET, "/filters/create"));
        }
        Task <StacManResponse <Site> > ISiteMethods.GetAll(string filter, int?page, int?pagesize)
        {
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder("/sites", useHttps: false);

            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return(CreateApiTask <Site>(ub, "/sites"));
        }
        Task <StacManResponse <Error> > IErrorMethods.GetAll(string filter, int?page, int?pagesize)
        {
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/errors", useHttps: false);

            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return(CreateApiTask <Error>(ub, HttpMethod.GET, "/errors"));
        }
        Task<StacManResponse<Error>> IErrorMethods.GetAll(string filter, int? page, int? pagesize)
        {
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/errors", useHttps: false);

            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return CreateApiTask<Error>(ub, HttpMethod.GET, "/errors");
        }
        Task<StacManResponse<Filter>> IFilterMethods.Read(IEnumerable<string> filters, string filter = null)
        {
            var filterObj = ValidateAndGetFilter(filter);

            ValidateEnumerable(filters, "filters");

            var ub = new ApiUrlBuilder(String.Format("/filters/{0}", String.Join(";", filters)), useHttps: false);

            ub.AddParameter("filter", filter);

            return CreateApiTask<Filter>(ub, filterObj, "/filters/{filters}");
        }
        Task<StacManResponse<Filter>> IFilterMethods.Create(string filter, IEnumerable<string> include, IEnumerable<string> exclude, string @base, bool? @unsafe)
        {
            var ub = new ApiUrlBuilder(Version, "/filters/create", useHttps: false);

            ub.AddParameter("filter", filter);
            ub.AddParameter("include", include);
            ub.AddParameter("exclude", exclude);
            ub.AddParameter("base", @base);
            ub.AddParameter("unsafe", @unsafe);

            return CreateApiTask<Filter>(ub, HttpMethod.GET, "/filters/create");
        }
Exemple #27
0
        Task <StacManResponse <AccessToken> > IAccessTokenMethods.Get(IEnumerable <string> accessTokens, string filter, int?page, int?pagesize)
        {
            ValidateEnumerable(accessTokens, "accessTokens");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, String.Format("/access-tokens/{0}", String.Join(";", accessTokens.Select(HttpUtility.UrlEncode))), useHttps: false);

            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return(CreateApiTask <AccessToken>(ub, HttpMethod.GET, "/access-tokens/{accessTokens}"));
        }
        Task<StacManResponse<AccessToken>> IAccessTokenMethods.Invalidate(IEnumerable<string> accessTokens, string filter, int? page, int? pagesize)
        {
            ValidateEnumerable(accessTokens, "accessTokens");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, String.Format("/access-tokens/{0}/invalidate", String.Join(";", accessTokens.Select(HttpUtility.UrlEncode))), useHttps: false);

            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return CreateApiTask<AccessToken>(ub, HttpMethod.GET, "/access-tokens/{accessTokens}/invalidate");
        }
Exemple #29
0
        Task <StacManResponse <AccessToken> > IAccessTokenMethods.Invalidate(IEnumerable <string> accessTokens, string filter, int?page, int?pagesize)
        {
            ValidateEnumerable(accessTokens, "accessTokens");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(String.Format("/access-tokens/{0}/invalidate", String.Join(";", accessTokens)), useHttps: false);

            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return(CreateApiTask <AccessToken>(ub, "/access-tokens/{accessTokens}/invalidate"));
        }
        Task<StacManResponse<InboxItem>> IInboxMethods.Get(string access_token, string filter, int? page, int? pagesize)
        {
            ValidateString(access_token, "access_token");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/inbox", useHttps: true);

            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return CreateApiTask<InboxItem>(ub, HttpMethod.GET, "/inbox");
        }
        Task <StacManResponse <InboxItem> > IInboxMethods.Get(string access_token, string filter, int?page, int?pagesize)
        {
            ValidateString(access_token, "access_token");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/inbox", useHttps: true);

            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return(CreateApiTask <InboxItem>(ub, HttpMethod.GET, "/inbox"));
        }
        Task<StacManResponse<Site>> ISiteMethods.GetAll(string filter = null, int? page = null, int? pagesize = null)
        {
            var filterObj = ValidateAndGetFilter(filter);

            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder("/sites", useHttps: false);

            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return CreateApiTask<Site>(ub, filterObj, "/sites");
        }
        Task<StacManResponse<Privilege>> IPrivilegeMethods.GetAll(string site, string filter, int? page, int? pagesize)
        {
            ValidateString(site, "site");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/privileges", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return CreateApiTask<Privilege>(ub, HttpMethod.GET, "/privileges");
        }
        Task <StacManResponse <Privilege> > IPrivilegeMethods.GetAll(string site, string filter, int?page, int?pagesize)
        {
            ValidateString(site, "site");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/privileges", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return(CreateApiTask <Privilege>(ub, HttpMethod.GET, "/privileges"));
        }
        Task<StacManResponse<Filter>> IFilterMethods.Create(string filter = null, IEnumerable<string> include = null, IEnumerable<string> exclude = null, string @base = null, bool? @unsafe = null)
        {
            var filterObj = ValidateAndGetFilter(filter);


            var ub = new ApiUrlBuilder("/filters/create", useHttps: false);

            ub.AddParameter("filter", filter);
            ub.AddParameter("include", include);
            ub.AddParameter("exclude", exclude);
            ub.AddParameter("base", @base);
            ub.AddParameter("unsafe", @unsafe);

            return CreateApiTask<Filter>(ub, filterObj, "/filters/create");
        }
        Task<StacManResponse<AccessToken>> IAccessTokenMethods.Get(IEnumerable<string> accessTokens, string filter = null, int? page = null, int? pagesize = null)
        {
            var filterObj = ValidateAndGetFilter(filter);

            ValidateEnumerable(accessTokens, "accessTokens");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(String.Format("/access-tokens/{0}", String.Join(";", accessTokens)), useHttps: false);

            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return CreateApiTask<AccessToken>(ub, filterObj, "/access-tokens/{accessTokens}");
        }
        Task<StacManResponse<Notification>> INotificationMethods.GetUnread(string access_token, string filter, int? page, int? pagesize)
        {
            ValidateString(access_token, "access_token");
            ValidateMinApiVersion("2.1");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/notifications/unread", useHttps: true);

            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return CreateApiTask<Notification>(ub, HttpMethod.GET, "/notifications/unread");
        }
Exemple #38
0
        Task <StacManResponse <Notification> > INotificationMethods.GetUnread(string access_token, string filter, int?page, int?pagesize)
        {
            ValidateString(access_token, "access_token");
            ValidateMinApiVersion("2.1");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/notifications/unread", useHttps: true);

            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return(CreateApiTask <Notification>(ub, HttpMethod.GET, "/notifications/unread"));
        }
        Task <StacManResponse <TagWiki> > ITagMethods.GetTagWikis(string site, IEnumerable <string> tags, string filter, int?page, int?pagesize)
        {
            ValidateString(site, "site");
            ValidateEnumerable(tags, "tags");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, String.Format("/tags/{0}/wikis", String.Join(";", tags.Select(HttpUtility.UrlEncode))), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return(CreateApiTask <TagWiki>(ub, HttpMethod.GET, "/tags/{tags}/wikis"));
        }
        Task <StacManResponse <TagScore> > ITagMethods.GetTopAskers(string site, string tag, Tags.Period period, string filter, int?page, int?pagesize)
        {
            ValidateString(site, "site");
            ValidateString(tag, "tag");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, String.Format("/tags/{0}/top-askers/{1}", tag, period), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return(CreateApiTask <TagScore>(ub, HttpMethod.GET, "/tags/{tag}/top-askers/{period}"));
        }
Exemple #41
0
        Task <StacManResponse <Tag> > ITagMethods.GetRelated(string site, IEnumerable <string> tags, string filter, int?page, int?pagesize)
        {
            ValidateString(site, "site");
            ValidateEnumerable(tags, "tags");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(String.Format("/tags/{0}/related", String.Join(";", tags)), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return(CreateApiTask <Tag>(ub, "/tags/{tags}/related"));
        }
        Task<StacManResponse<Comment>> ICommentMethods.Delete(string site, string access_token, int id, string filter, bool? preview)
        {
            ValidateString(site, "site");
            ValidateString(access_token, "access_token");
            ValidateMinApiVersion("2.1");

            var ub = new ApiUrlBuilder(Version, String.Format("/comments/{0}/delete", id), useHttps: true);

            ub.AddParameter("site", site);
            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("preview", preview);

            return CreateApiTask<Comment>(ub, HttpMethod.POST, "/comments/{id}/delete");
        }
Exemple #43
0
        Task <StacManResponse <Comment> > ICommentMethods.Delete(string site, string access_token, int id, string filter, bool?preview)
        {
            ValidateString(site, "site");
            ValidateString(access_token, "access_token");
            ValidateMinApiVersion("2.1");

            var ub = new ApiUrlBuilder(Version, String.Format("/comments/{0}/delete", id), useHttps: true);

            ub.AddParameter("site", site);
            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("preview", preview);

            return(CreateApiTask <Comment>(ub, HttpMethod.POST, "/comments/{id}/delete"));
        }
Exemple #44
0
        Task <StacManResponse <Badge> > IBadgeMethods.GetRecent(string site, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate)
        {
            ValidateString(site, "site");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder("/badges/recipients", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);

            return(CreateApiTask <Badge>(ub, "/badges/recipients"));
        }
        Task<StacManResponse<InboxItem>> IInboxMethods.Get(string access_token, string filter = null, int? page = null, int? pagesize = null)
        {
            var filterObj = ValidateAndGetFilter(filter);

            ValidateString(access_token, "access_token");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder("/inbox", useHttps: true);

            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return CreateApiTask<InboxItem>(ub, filterObj, "/inbox");
        }
        Task<StacManResponse<Revision>> IRevisionMethods.GetByIds(string site, IEnumerable<Guid> ids, string filter, int? page, int? pagesize, DateTime? fromdate, DateTime? todate)
        {
            ValidateString(site, "site");
            ValidateEnumerable(ids, "ids");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, String.Format("/revisions/{0}", String.Join(";", ids)), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);

            return CreateApiTask<Revision>(ub, HttpMethod.GET, "/revisions/{ids}");
        }
Exemple #47
0
        Task <StacManResponse <Badge> > IBadgeMethods.GetRecentByIds(string site, IEnumerable <int> ids, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate)
        {
            ValidateString(site, "site");
            ValidateEnumerable(ids, "ids");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(String.Format("/badges/{0}/recipients", String.Join(";", ids)), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);

            return(CreateApiTask <Badge>(ub, "/badges/{ids}/recipients"));
        }
Exemple #48
0
        Task <StacManResponse <Event> > IEventMethods.GetRecent(string site, string access_token, string filter, int?page, int?pagesize, DateTime?since)
        {
            ValidateString(site, "site");
            ValidateString(access_token, "access_token");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/events", useHttps: true);

            ub.AddParameter("site", site);
            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("since", since);

            return(CreateApiTask <Event>(ub, HttpMethod.GET, "/events"));
        }
        Task <StacManResponse <QuestionTimeline> > IQuestionMethods.GetTimelines(string site, IEnumerable <int> ids, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate)
        {
            ValidateString(site, "site");
            ValidateEnumerable(ids, "ids");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, String.Format("/questions/{0}/timeline", String.Join(";", ids)), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);

            return(CreateApiTask <QuestionTimeline>(ub, HttpMethod.GET, "/questions/{ids}/timeline"));
        }
        Task<StacManResponse<Event>> IEventMethods.GetRecent(string site, string access_token, string filter, int? page, int? pagesize, DateTime? since)
        {
            ValidateString(site, "site");
            ValidateString(access_token, "access_token");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/events", useHttps: true);

            ub.AddParameter("site", site);
            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("since", since);

            return CreateApiTask<Event>(ub, HttpMethod.GET, "/events");
        }
Exemple #51
0
        private Task <StacManResponse <T> > CreateApiTask <T>(ApiUrlBuilder ub, HttpMethod httpMethod, string backoffKey) where T : StacManType
        {
            var request = new ApiRequest <T>(this, ub, httpMethod, backoffKey);

            if (ActiveRequests >= MaxSimultaneousRequests || QueuedRequests.Count > 0)
            {
                lock (QueuedRequests)
                {
                    QueuedRequests.Enqueue(request);
                }
                ProcessQueue();
            }
            else
            {
                SendRequest(request);
            }

            return(request.Task);
        }
        Task<StacManResponse<Event>> IEventMethods.GetRecent(string site, string access_token, string filter = null, int? page = null, int? pagesize = null, DateTime? since = null)
        {
            var filterObj = ValidateAndGetFilter(filter);

            ValidateString(site, "site");
            ValidateString(access_token, "access_token");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder("/events", useHttps: true);

            ub.AddParameter("site", site);
            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("since", since);

            return CreateApiTask<Event>(ub, filterObj, "/events");
        }
        Task<StacManResponse<SuggestedEdit>> ISuggestedEditMethods.GetAll(string site, string filter, int? page, int? pagesize, DateTime? fromdate, DateTime? todate, SuggestedEdits.Sort? sort, DateTime? mindate, DateTime? maxdate, Order? order)
        {
            ValidateString(site, "site");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate);

            var ub = new ApiUrlBuilder(Version, "/suggested-edits", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("order", order);

            return CreateApiTask<SuggestedEdit>(ub, HttpMethod.GET, "/suggested-edits");
        }
        Task <StacManResponse <SuggestedEdit> > ISuggestedEditMethods.GetAll(string site, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate, SuggestedEdits.Sort?sort, DateTime?mindate, DateTime?maxdate, Order?order)
        {
            ValidateString(site, "site");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate);

            var ub = new ApiUrlBuilder("/suggested-edits", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("order", order);

            return(CreateApiTask <SuggestedEdit>(ub, "/suggested-edits"));
        }
        Task<StacManResponse<SuggestedEdit>> ISuggestedEditMethods.GetByIds(string site, IEnumerable<int> ids, string filter, int? page, int? pagesize, DateTime? fromdate, DateTime? todate, SuggestedEdits.Sort? sort, DateTime? mindate, DateTime? maxdate, Order? order)
        {
            ValidateString(site, "site");
            ValidateEnumerable(ids, "ids");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate);

            var ub = new ApiUrlBuilder(Version, String.Format("/suggested-edits/{0}", String.Join(";", ids)), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("order", order);

            return CreateApiTask<SuggestedEdit>(ub, HttpMethod.GET, "/suggested-edits/{ids}");
        }
        Task <StacManResponse <SuggestedEdit> > ISuggestedEditMethods.GetByIds(string site, IEnumerable <int> ids, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate, SuggestedEdits.Sort?sort, DateTime?mindate, DateTime?maxdate, Order?order)
        {
            ValidateString(site, "site");
            ValidateEnumerable(ids, "ids");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate);

            var ub = new ApiUrlBuilder(String.Format("/suggested-edits/{0}", String.Join(";", ids)), useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("order", order);

            return(CreateApiTask <SuggestedEdit>(ub, "/suggested-edits/{ids}"));
        }
        Task <StacManResponse <Question> > ISearchMethods.GetMatchesAdvanced(string site, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate, Questions.SearchSort?sort, DateTime?mindate, DateTime?maxdate, int?min, int?max, Order?order, string q, bool?accepted, int?answers, string body, bool?closed, bool?migrated, bool?notice, string nottagged, string tagged, string title, int?user, string url, int?views, bool?wiki)
        {
            ValidateString(site, "site");
            ValidateMinApiVersion("2.1");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate, min: min, max: max);

            var ub = new ApiUrlBuilder(Version, "/search/advanced", useHttps: false);

            ub.AddParameter("site", site);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("min", min);
            ub.AddParameter("max", max);
            ub.AddParameter("order", order);
            ub.AddParameter("q", q);
            ub.AddParameter("accepted", accepted);
            ub.AddParameter("answers", answers);
            ub.AddParameter("body", body);
            ub.AddParameter("closed", closed);
            ub.AddParameter("migrated", migrated);
            ub.AddParameter("notice", notice);
            ub.AddParameter("nottagged", nottagged);
            ub.AddParameter("tagged", tagged);
            ub.AddParameter("title", title);
            ub.AddParameter("user", user);
            ub.AddParameter("url", url);
            ub.AddParameter("views", views);
            ub.AddParameter("wiki", wiki);

            return(CreateApiTask <Question>(ub, HttpMethod.GET, "/search/advanced"));
        }
        Task<StacManResponse<Question>> IUserMethods.GetMyFeaturedQuestions(string site, string access_token, string filter, int? page, int? pagesize, DateTime? fromdate, DateTime? todate, Questions.Sort? sort, DateTime? mindate, DateTime? maxdate, int? min, int? max, Order? order)
        {
            ValidateString(site, "site");
            ValidateString(access_token, "access_token");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate, min: min, max: max);

            var ub = new ApiUrlBuilder(Version, "/me/questions/featured", useHttps: true);

            ub.AddParameter("site", site);
            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("fromdate", fromdate);
            ub.AddParameter("todate", todate);
            ub.AddParameter("sort", sort);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("min", min);
            ub.AddParameter("max", max);
            ub.AddParameter("order", order);

            return CreateApiTask<Question>(ub, HttpMethod.GET, "/_users/questions/featured");
        }
        Task<StacManResponse<AccountMerge>> IUserMethods.GetMyMerges(string access_token, string filter, int? page, int? pagesize)
        {
            ValidateString(access_token, "access_token");
            ValidateMinApiVersion("2.1");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/me/merges", useHttps: true);

            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);

            return CreateApiTask<AccountMerge>(ub, HttpMethod.GET, "/_users/merges");
        }
        Task<StacManResponse<InboxItem>> IUserMethods.GetMyInboxUnread(string site, string access_token, string filter, int? page, int? pagesize, DateTime? since)
        {
            ValidateString(site, "site");
            ValidateString(access_token, "access_token");
            ValidatePaging(page, pagesize);

            var ub = new ApiUrlBuilder(Version, "/me/inbox/unread", useHttps: true);

            ub.AddParameter("site", site);
            ub.AddParameter("access_token", access_token);
            ub.AddParameter("filter", filter);
            ub.AddParameter("page", page);
            ub.AddParameter("pagesize", pagesize);
            ub.AddParameter("since", since);

            return CreateApiTask<InboxItem>(ub, HttpMethod.GET, "/_users/inbox/unread");
        }