Module: DiscourseApi::API::Topics
- Included in:
- Client
- Defined in:
- lib/discourse_api/api/topics.rb
Instance Method Summary collapse
- #bookmark_topic(topic_id) ⇒ Object
- #change_owner(topic_id, params = {}) ⇒ Object
-
#change_topic_status(topic_slug, topic_id, params = {}) ⇒ Object
TODO: Deprecated.
-
#create_topic(args = {}) ⇒ Object
:category OPTIONAL name of category, not ID :skip_validations OPTIONAL boolean :auto_track OPTIONAL boolean :created_at OPTIONAL seconds since epoch.
- #create_topic_action(args) ⇒ Object
- #delete_topic(id) ⇒ Object
-
#edit_topic_timestamp(topic_id, timestamp) ⇒ Object
timestamp is seconds past the epoch.
- #get_topic_url_by_external_id(external_id) ⇒ Object
- #latest_topics(params = {}) ⇒ Object
- #new_topics(params = {}) ⇒ Object
- #recategorize_topic(topic_id, category_id) ⇒ Object
- #remove_topic_bookmark(topic_id) ⇒ Object
- #rename_topic(topic_id, title) ⇒ Object
- #top_topics(params = {}) ⇒ Object
- #topic(id, params = {}) ⇒ Object
- #topic_posts(topic_id, post_ids = [], params = {}) ⇒ Object
- #topic_set_user_notification_level(topic_id, params) ⇒ Object
- #topics_by(username, params = {}) ⇒ Object
- #update_topic_status(topic_id, params = {}) ⇒ Object
Instance Method Details
#bookmark_topic(topic_id) ⇒ Object
115 116 117 |
# File 'lib/discourse_api/api/topics.rb', line 115 def bookmark_topic(topic_id) put("/t/#{topic_id}/bookmark.json") end |
#change_owner(topic_id, params = {}) ⇒ Object
104 105 106 107 108 |
# File 'lib/discourse_api/api/topics.rb', line 104 def change_owner(topic_id, params = {}) params = API.params(params).required(:username, :post_ids) post("/t/#{topic_id}/change-owner.json", params) end |
#change_topic_status(topic_slug, topic_id, params = {}) ⇒ Object
TODO: Deprecated. Remove after 20201231
60 61 62 63 |
# File 'lib/discourse_api/api/topics.rb', line 60 def change_topic_status(topic_slug, topic_id, params = {}) deprecated(__method__, "update_topic_status") update_topic_status(topic_id, params) end |
#create_topic(args = {}) ⇒ Object
:category OPTIONAL name of category, not ID :skip_validations OPTIONAL boolean :auto_track OPTIONAL boolean :created_at OPTIONAL seconds since epoch.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/discourse_api/api/topics.rb', line 9 def create_topic(args = {}) args = API .params(args) .required(:title, :raw) .optional( :skip_validations, :category, :auto_track, :created_at, :api_username, :tags, :external_id, ) post("/posts", args.to_h) end |
#create_topic_action(args) ⇒ Object
26 27 28 29 |
# File 'lib/discourse_api/api/topics.rb', line 26 def create_topic_action(args) args = API.params(args).required(:id, :post_action_type_id) post("/post_actions", args.to_h.merge(flag_topic: true)) end |
#delete_topic(id) ⇒ Object
80 81 82 |
# File 'lib/discourse_api/api/topics.rb', line 80 def delete_topic(id) delete("/t/#{id}.json") end |
#edit_topic_timestamp(topic_id, timestamp) ⇒ Object
timestamp is seconds past the epoch.
32 33 34 |
# File 'lib/discourse_api/api/topics.rb', line 32 def (topic_id, ) put("/t/#{topic_id}/change-timestamp", timestamp: ) end |
#get_topic_url_by_external_id(external_id) ⇒ Object
123 124 125 |
# File 'lib/discourse_api/api/topics.rb', line 123 def get_topic_url_by_external_id(external_id) get("/t/external_id/#{external_id}") end |
#latest_topics(params = {}) ⇒ Object
36 37 38 39 |
# File 'lib/discourse_api/api/topics.rb', line 36 def latest_topics(params = {}) response = get("/latest.json", params) response[:body]["topic_list"]["topics"] end |
#new_topics(params = {}) ⇒ Object
46 47 48 49 |
# File 'lib/discourse_api/api/topics.rb', line 46 def new_topics(params = {}) response = get("/new.json", params) response[:body]["topic_list"]["topics"] end |
#recategorize_topic(topic_id, category_id) ⇒ Object
55 56 57 |
# File 'lib/discourse_api/api/topics.rb', line 55 def recategorize_topic(topic_id, category_id) put("/t/#{topic_id}.json", topic_id: topic_id, category_id: category_id) end |
#remove_topic_bookmark(topic_id) ⇒ Object
119 120 121 |
# File 'lib/discourse_api/api/topics.rb', line 119 def remove_topic_bookmark(topic_id) put("/t/#{topic_id}/remove_bookmarks.json") end |
#rename_topic(topic_id, title) ⇒ Object
51 52 53 |
# File 'lib/discourse_api/api/topics.rb', line 51 def rename_topic(topic_id, title) put("/t/#{topic_id}.json", topic_id: topic_id, title: title) end |
#top_topics(params = {}) ⇒ Object
41 42 43 44 |
# File 'lib/discourse_api/api/topics.rb', line 41 def top_topics(params = {}) response = get("/top.json", params) response[:body]["topic_list"]["topics"] end |
#topic(id, params = {}) ⇒ Object
70 71 72 73 |
# File 'lib/discourse_api/api/topics.rb', line 70 def topic(id, params = {}) response = get("/t/#{id}.json", params) response[:body] end |
#topic_posts(topic_id, post_ids = [], params = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/discourse_api/api/topics.rb', line 84 def topic_posts(topic_id, post_ids = [], params = {}) params = API.params(params).optional( :asc, :filter, :include_raw, :include_suggested, :post_number, :username_filters, ) url = ["/t/#{topic_id}/posts.json"] if post_ids.count > 0 url.push("?") url.push(post_ids.map { |id| "post_ids[]=#{id}" }.join("&")) end response = get(url.join, params) response[:body] end |
#topic_set_user_notification_level(topic_id, params) ⇒ Object
110 111 112 113 |
# File 'lib/discourse_api/api/topics.rb', line 110 def topic_set_user_notification_level(topic_id, params) params = API.params(params).required(:notification_level) post("/t/#{topic_id}/notifications", params) end |
#topics_by(username, params = {}) ⇒ Object
75 76 77 78 |
# File 'lib/discourse_api/api/topics.rb', line 75 def topics_by(username, params = {}) response = get("/topics/created-by/#{username}.json", params) response[:body]["topic_list"]["topics"] end |