Exemple #1
0
        public void TestGetUser()
        {
            _api = DiscourseApi.GetInstance("https://meta.discourse.org", _apiKey);
            var result = _api.GetUser("chaoticloki");

            Assert.IsNotNull(result);
        }
        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));
        }
Exemple #3
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));
        }
        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);
            }
        }
Exemple #5
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);
            }
        }
Exemple #6
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);
            }
        }
Exemple #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);
            }
        }
Exemple #8
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);
            }
        }
Exemple #9
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);
            }
        }
 public void Initialize()
 {
     _api = DiscourseApi.GetInstance(Environment.GetEnvironmentVariable("DiscourseApiUrl"), _apiKey);
 }
Exemple #11
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));
        }
Exemple #12
0
 public static GetTopicsModel GetTopTopics(this DiscourseApi api)
 {
     return(api.ExecuteRequest <GetTopicsModel>("/top.json", Method.GET));
 }
 public void TestGetUser()
 {
     _api = DiscourseApi.GetInstance("https://meta.discourse.org", _apiKey);
     var result = _api.GetUser("chaoticloki");
     Assert.IsNotNull(result);
 }
 public void Initialize()
 {
     _api = DiscourseApi.GetInstance("http://discourse.logicpending.com", _apiKey);
 }
Exemple #15
0
 public void Initialize()
 {
     _api = DiscourseApi.GetInstance(Environment.GetEnvironmentVariable("DiscourseApiUrl"), _apiKey);
 }
Exemple #16
0
 public static CreatedTopic CreateTopic(this DiscourseApi api, NewTopic data, string username = DefaultUsername)
 {
     return(api.ExecuteRequest <CreatedTopic>("/posts", Method.POST, true, username, null, data));
 }
Exemple #17
0
 public static GetTopicsModel GetNewTopics(this DiscourseApi api, string username = DefaultUsername)
 {
     return(api.ExecuteRequest <GetTopicsModel>("/new.json", Method.GET, true, username));
 }
        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));
        }
 public void Initialize()
 {
     _api = DiscourseApi.GetInstance("http://discourse.logicpending.com", _apiKey);
 }
        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));
        }
        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);
        }
 public static GetCategoriesModel GetCategories(this DiscourseApi api)
 {
     return(api.ExecuteRequest <GetCategoriesModel>("/categories.json", Method.GET));
 }