Module: DiscourseApi::API::Posts

Included in:
Client
Defined in:
lib/discourse_api/api/posts.rb

Instance Method Summary collapse

Instance Method Details

#create_post(args) ⇒ Object



5
6
7
8
# File 'lib/discourse_api/api/posts.rb', line 5

def create_post(args)
  args = API.params(args).required(:topic_id, :raw).optional(:created_at, :api_username)
  post("/posts", args)
end

#create_post_action(args) ⇒ Object



10
11
12
13
# File 'lib/discourse_api/api/posts.rb', line 10

def create_post_action(args)
  args = API.params(args).required(:id, :post_action_type_id)
  post("/post_actions", args.to_h.merge(flag_topic: false))
end

#delete_post(id) ⇒ Object



35
36
37
# File 'lib/discourse_api/api/posts.rb', line 35

def delete_post(id)
  delete("/posts/#{id}.json")
end

#destroy_post_action(post_id, post_action_type_id) ⇒ Object



39
40
41
# File 'lib/discourse_api/api/posts.rb', line 39

def destroy_post_action(post_id, post_action_type_id)
  delete("/post_actions/#{post_id}.json", post_action_type_id: post_action_type_id)
end

#edit_post(id, raw) ⇒ Object



31
32
33
# File 'lib/discourse_api/api/posts.rb', line 31

def edit_post(id, raw)
  put("/posts/#{id}", post: { raw: raw })
end

#get_post(id, args = {}) ⇒ Object



15
16
17
18
19
# File 'lib/discourse_api/api/posts.rb', line 15

def get_post(id, args = {})
  args = API.params(args).optional(:version)
  response = get("/posts/#{id}.json", args)
  response[:body]
end

#post_action_users(post_id, post_action_type_id) ⇒ Object



43
44
45
46
47
# File 'lib/discourse_api/api/posts.rb', line 43

def post_action_users(post_id, post_action_type_id)
  response =
    get("/post_action_users.json", id: post_id, post_action_type_id: post_action_type_id)
  response[:body]
end

#posts(args = {}) ⇒ Object



21
22
23
24
25
# File 'lib/discourse_api/api/posts.rb', line 21

def posts(args = {})
  args = API.params(args).default(before: 0)
  response = get("/posts.json", args)
  response[:body]
end

#wikify_post(id) ⇒ Object



27
28
29
# File 'lib/discourse_api/api/posts.rb', line 27

def wikify_post(id)
  put("/posts/#{id}/wiki", wiki: true)
end