Пример #1
0
        public static GetTopicsModel GetNewCategoryTopics(this DiscourseApi api, int categoryId,
                                                          string username = DefaultUsername)
        {
            var route = String.Format("/c/{0}/l/new.json", categoryId);

            return(api.ExecuteRequest <GetTopicsModel>(route, Method.GET, true, username));
        }
Пример #2
0
        public static List <SimilarTopicModel> GetSimilarTopics(this DiscourseApi api, string title, string content)
        {
            var timestamp =
                (DateTime.Now - new DateTime(1970, 1, 1).ToLocalTime()).TotalMilliseconds.ToString(
                    CultureInfo.InvariantCulture);
            var parameters = new Dictionary <string, string>
            {
                { "title", title },
                { "raw", content },
                { "_", timestamp }
            };

            return(api.ExecuteRequest <List <SimilarTopicModel> >("/topics/similar_to", Method.GET, false, DefaultUsername,
                                                                  parameters));
        }
Пример #3
0
        public static ResultState DeleteUser(this DiscourseApi api, string username, string apiUserName = DefaultUsername)
        {
            var path = String.Format("/users/{0}.json", username);
            var data = new UpdateUsername(username);

            var result = api.ExecuteRequest <RestResponse>(path, Method.DELETE, true, apiUserName, null, data);

            switch (result.StatusCode)
            {
            case (HttpStatusCode)422:
                return(ResultState.Unchanged);

            case HttpStatusCode.OK:
                return(ResultState.Deleted);

            default:
                return(ResultState.Error);
            }
        }
Пример #4
0
        public static ResultState UpdateUserEmail(this DiscourseApi api, string username, string newEmail, string apiUserName = DefaultUsername)
        {
            var path = String.Format("/users/{0}/preferences/email", username);
            var data = new UpdateEmail(newEmail);

            var result = api.ExecuteRequest <RestResponse>(path, Method.PUT, true, apiUserName, null, data);

            switch (result.StatusCode)
            {
            case (HttpStatusCode)422:
                return(ResultState.Unchanged);

            case HttpStatusCode.Accepted:
                return(ResultState.Modified);

            default:
                return(ResultState.Error);
            }
        }
Пример #5
0
        public static ResultState DeleteCategory(this DiscourseApi api, int categoryId, string username = DefaultUsername)
        {
            var route = String.Format("/c/{0}", categoryId);
            var data  = new DeleteCategory(categoryId);

            var result = api.ExecuteRequest <RestResponse>(route, Method.DELETE, true, username, null, data);

            switch (result.StatusCode)
            {
            case (HttpStatusCode)422:
                return(ResultState.Unchanged);

            case HttpStatusCode.Accepted:
                return(ResultState.Modified);

            default:
                return(ResultState.Error);
            }
        }
Пример #6
0
        public static ResultState UpdateUserTrustLevel(this DiscourseApi api, int userId, int level,
                                                       string apiUserName = DefaultUsername)
        {
            var path = String.Format("/admin/users/{0}/trust_level", userId);
            var data = new UpdateUserTrustLevel(userId, level);

            var result = api.ExecuteRequest <RestResponse>(path, Method.PUT, true, apiUserName, null, data);

            switch (result.StatusCode)
            {
            case (HttpStatusCode)422:
                return(ResultState.Unchanged);

            case HttpStatusCode.OK:
                return(ResultState.Modified);

            default:
                return(ResultState.Error);
            }
        }
Пример #7
0
        public static ResultState UpdateTopic(this DiscourseApi api, int topicId, string newTitle, int?categoryId,
                                              string apiUserName = DefaultUsername)
        {
            var path = String.Format("/t/{0}", topicId);
            var data = new UpdateTopic(topicId, newTitle, categoryId);

            var result = api.ExecuteRequest <RestResponse>(path, Method.PUT, true, apiUserName, null, data);

            switch (result.StatusCode)
            {
            case (HttpStatusCode)422:
                return(ResultState.Unchanged);

            case HttpStatusCode.Accepted:
                return(ResultState.Modified);

            default:
                return(ResultState.Error);
            }
        }
Пример #8
0
        public static ResultState CreateUser(this DiscourseApi api, string name, string username, string email,
                                             string password, bool active = true, string apiUserName = DefaultUsername)
        {
            var path = "/users";
            var data = new NewUser {
                Active = active, Email = email, Name = name, Password = password, UserName = username
            };

            var result = api.ExecuteRequest <RestResponse>(path, Method.POST, true, apiUserName, null, data);

            switch (result.StatusCode)
            {
            case (HttpStatusCode)422:
                return(ResultState.Unchanged);

            case HttpStatusCode.OK:
                return(ResultState.Created);

            default:
                return(ResultState.Error);
            }
        }
Пример #9
0
        public static GetUserModel GetUser(this DiscourseApi api, string username)
        {
            var path = String.Format("/users/{0}.json", username);

            return(api.ExecuteRequest <GetUserModel>(path, Method.GET));
        }
Пример #10
0
        public static GetTopicsModel GetSubCategoryTopics(this DiscourseApi api, int parentCategory, int childCategory)
        {
            var route = String.Format("/c/{0}/{1}.json", parentCategory, childCategory);

            return(api.ExecuteRequest <GetTopicsModel>(route, Method.GET));
        }
Пример #11
0
        public static GetTopicsModel GetLatestCategoryTopics(this DiscourseApi api, int categoryId)
        {
            var route = String.Format("/c/{0}/l/latest.json", categoryId);

            return(api.ExecuteRequest <GetTopicsModel>(route, Method.GET));
        }
Пример #12
0
        public static Category CreateCategory(this DiscourseApi api, NewCategory newCategory, string username = DefaultUsername)
        {
            var response = api.ExecuteRequest <CreatedCategory>("/categories", Method.POST, true, username, null, newCategory);

            return(response == null ? null : response.Category);
        }
Пример #13
0
 public static GetCategoriesModel GetCategories(this DiscourseApi api)
 {
     return(api.ExecuteRequest <GetCategoriesModel>("/categories.json", Method.GET));
 }
Пример #14
0
 public static CreatedTopic CreateTopic(this DiscourseApi api, NewTopic data, string username = DefaultUsername)
 {
     return(api.ExecuteRequest <CreatedTopic>("/posts", Method.POST, true, username, null, data));
 }
Пример #15
0
 public static GetTopicsModel GetNewTopics(this DiscourseApi api, string username = DefaultUsername)
 {
     return(api.ExecuteRequest <GetTopicsModel>("/new.json", Method.GET, true, username));
 }
Пример #16
0
 public static GetTopicsModel GetTopTopics(this DiscourseApi api)
 {
     return(api.ExecuteRequest <GetTopicsModel>("/top.json", Method.GET));
 }