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");
        }
        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 <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<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 <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");
        }
Beispiel #9
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}"));
        }
Beispiel #10
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<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");
        }
        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<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<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 <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}"));
        }
        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");
        }
        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");
        }
Beispiel #21
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"));
        }
        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");
        }
Beispiel #23
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"));
        }
Beispiel #24
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<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}");
        }
Beispiel #26
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<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 <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<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 <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.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<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 <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<SuggestedEdit>> ISuggestedEditMethods.GetByIds(string site, IEnumerable<int> ids, string filter = null, int? page = null, int? pagesize = null, DateTime? fromdate = null, DateTime? todate = null, SuggestedEdits.Sort? sort = null, DateTime? mindate = null, DateTime? maxdate = null, Order? order = null)
        {
            var filterObj = ValidateAndGetFilter(filter);

            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, filterObj, "/suggested-edits/{ids}");
        }
Beispiel #38
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 <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"));
        }
Beispiel #40
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"));
        }
Beispiel #41
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<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}");
        }
        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");
        }
Beispiel #44
0
        private void GetApiResponse <T>(ApiUrlBuilder ub, string backoffKey, Action <StacManResponse <T> > callback) where T : StacManType
        {
            var response = new StacManResponse <T>();

            ub.AddParameter("key", Key);

            response.ApiUrl = ub.ToString();

            FetchApiResponse(response.ApiUrl,
                             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);
            },
                             ex =>
            {
                response.Success = false;
                response.Error   = ex;
                callback(response);
            });
        }
        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<Answer>> IAnswerMethods.GetByIds(string site, IEnumerable<int> ids, string filter, int? page, int? pagesize, DateTime? fromdate, DateTime? todate, Answers.Sort? sort, DateTime? mindate, DateTime? maxdate, int? min, int? max, Order? order)
        {
            ValidateString(site, "site");
            ValidateEnumerable(ids, "ids");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate, min: min, max: max);

            var ub = new ApiUrlBuilder(Version, String.Format("/answers/{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<Answer>(ub, HttpMethod.GET, "/answers/{ids}");
        }
        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"));
        }
        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<NetworkUser>> IUserMethods.GetMyAssociated(string access_token, string filter, int? page, int? pagesize)
        {
            ValidateString(access_token, "access_token");
            ValidatePaging(page, pagesize);

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

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

            return CreateApiTask<NetworkUser>(ub, HttpMethod.GET, "/_users/associated");
        }
Beispiel #50
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 <Comment> > IQuestionMethods.GetComments(string site, IEnumerable <int> ids, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate, Comments.Sort?sort, DateTime?mindate, DateTime?maxdate, int?min, int?max, Order?order)
        {
            ValidateString(site, "site");
            ValidateEnumerable(ids, "ids");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, mindate: mindate, maxdate: maxdate, min: min, max: max);

            var ub = new ApiUrlBuilder(Version, String.Format("/questions/{0}/comments", 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 <Comment>(ub, HttpMethod.GET, "/questions/{ids}/comments"));
        }
        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"));
        }
        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<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");
        }
        Task<StacManResponse<Badge>> IUserMethods.GetMyBadges(string site, string access_token, string filter, int? page, int? pagesize, DateTime? fromdate, DateTime? todate, Badges.UserSort? sort, Badges.Rank? minrank, Badges.Rank? maxrank, string minname, string maxname, Badges.BadgeType? mintype, Badges.BadgeType? maxtype, DateTime? mindate, DateTime? maxdate, Order? order)
        {
            ValidateString(site, "site");
            ValidateString(access_token, "access_token");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, minrank: minrank, maxrank: maxrank, minname: minname, maxname: maxname, mintype: mintype, maxtype: maxtype, mindate: mindate, maxdate: maxdate);

            var ub = new ApiUrlBuilder(Version, "/me/badges", 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", minrank);
            ub.AddParameter("max", maxrank);
            ub.AddParameter("min", minname);
            ub.AddParameter("max", maxname);
            ub.AddParameter("min", mintype);
            ub.AddParameter("max", maxtype);
            ub.AddParameter("min", mindate);
            ub.AddParameter("max", maxdate);
            ub.AddParameter("order", order);

            return CreateApiTask<Badge>(ub, HttpMethod.GET, "/_users/badges");
        }
        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<Comment>> IUserMethods.GetMyCommentsToUser(string site, string access_token, int toid, string filter, int? page, int? pagesize, DateTime? fromdate, DateTime? todate, Comments.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, String.Format("/me/comments/{0}", toid), 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<Comment>(ub, HttpMethod.GET, "/_users/comments/{toid}");
        }
Beispiel #59
0
        Task <StacManResponse <Badge> > IBadgeMethods.GetNamed(string site, string filter, int?page, int?pagesize, DateTime?fromdate, DateTime?todate, Badges.Sort?sort, Badges.Rank?minrank, Badges.Rank?maxrank, string minname, string maxname, Order?order, string inname)
        {
            ValidateString(site, "site");
            ValidatePaging(page, pagesize);
            ValidateSortMinMax(sort, minrank: minrank, maxrank: maxrank, minname: minname, maxname: maxname);

            var ub = new ApiUrlBuilder("/badges/name", 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("order", order);
            ub.AddParameter("inname", inname);

            return(CreateApiTask <Badge>(ub, "/badges/name"));
        }
        Task<StacManResponse<User>> IUserMethods.GetModerators(string site, string filter, int? page, int? pagesize, DateTime? fromdate, DateTime? todate, Users.Sort? sort, int? min, int? max, DateTime? mindate, DateTime? maxdate, string minname, string maxname, Order? order)
        {
            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, "/users/moderators", 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<User>(ub, HttpMethod.GET, "/users/moderators");
        }