Module: DiscourseApi::API::Topics
- Included in:
- Client
- Defined in:
- lib/discourse_api/api/topics.rb
Instance Method Summary collapse
-
#create_topic(args = {}) ⇒ Object
:category OPTIONAL name of category, not ID :skip_validations OPTIONAL boolean :auto_track OPTIONAL boolean.
- #delete_topic(id) ⇒ Object
- #latest_topics(params = {}) ⇒ Object
- #new_topics(params = {}) ⇒ Object
- #recategorize_topic(topic_id, category_id) ⇒ Object
- #rename_topic(topic_id, title) ⇒ Object
- #topic(id, params = {}) ⇒ Object
- #topic_posts(topic_id, post_ids = []) ⇒ Object
- #topics_by(username, params = {}) ⇒ Object
Instance Method Details
#create_topic(args = {}) ⇒ Object
:category OPTIONAL name of category, not ID :skip_validations OPTIONAL boolean :auto_track OPTIONAL boolean
7 8 9 10 11 12 |
# File 'lib/discourse_api/api/topics.rb', line 7 def create_topic(args={}) args = API.params(args) .required(:title, :raw) .optional(:skip_validations, :category, :auto_track) post("/posts", args.to_h) end |
#delete_topic(id) ⇒ Object
42 43 44 |
# File 'lib/discourse_api/api/topics.rb', line 42 def delete_topic(id) delete("/t/#{id}.json") end |
#latest_topics(params = {}) ⇒ Object
14 15 16 17 |
# File 'lib/discourse_api/api/topics.rb', line 14 def latest_topics(params={}) response = get('/latest.json', params) response[:body]['topic_list']['topics'] end |
#new_topics(params = {}) ⇒ Object
19 20 21 22 |
# File 'lib/discourse_api/api/topics.rb', line 19 def new_topics(params={}) response = get("/new.json", params) response[:body]['topic_list']['topics'] end |
#recategorize_topic(topic_id, category_id) ⇒ Object
28 29 30 |
# File 'lib/discourse_api/api/topics.rb', line 28 def recategorize_topic(topic_id, category_id) put("/t/#{topic_id}.json", { topic_id: topic_id, category_id: category_id }) end |
#rename_topic(topic_id, title) ⇒ Object
24 25 26 |
# File 'lib/discourse_api/api/topics.rb', line 24 def rename_topic(topic_id, title) put("/t/#{topic_id}.json", { topic_id: topic_id, title: title }) end |
#topic(id, params = {}) ⇒ Object
32 33 34 35 |
# File 'lib/discourse_api/api/topics.rb', line 32 def topic(id, params={}) response = get("/t/#{id}.json", params) response[:body] end |
#topic_posts(topic_id, post_ids = []) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/discourse_api/api/topics.rb', line 46 def topic_posts(topic_id, post_ids=[]) url = "/t/#{topic_id}/posts.json" if post_ids.count > 0 url << '?' post_ids.each do |id| url << "post_ids[]=#{id}&" end end response = get(url) response[:body] end |
#topics_by(username, params = {}) ⇒ Object
37 38 39 40 |
# File 'lib/discourse_api/api/topics.rb', line 37 def topics_by(username, params={}) response = get("/topics/created-by/#{username}.json", params) response[:body]['topic_list']['topics'] end |