Class: DiscourseCli::Commands::Posts

Inherits:
Base
  • Object
show all
Defined in:
lib/discourse_cli/commands/posts.rb

Instance Method Summary collapse

Methods inherited from Base

exit_on_failure?

Instance Method Details

#createObject



25
26
27
28
29
30
31
# File 'lib/discourse_cli/commands/posts.rb', line 25

def create
  raw = resolve_raw(options[:raw])
  result = client.create_post(topic_id: options[:"topic-id"], raw: raw)
  formatter.print_item(result)
rescue DiscourseApi::DiscourseError => e
  handle_error(e)
end

#delete(id) ⇒ Object



44
45
46
47
48
49
# File 'lib/discourse_cli/commands/posts.rb', line 44

def delete(id)
  client.delete_post(id.to_i)
  formatter.print_success("Deleted post #{id}")
rescue DiscourseApi::DiscourseError => e
  handle_error(e)
end

#listObject



7
8
9
10
11
12
13
# File 'lib/discourse_cli/commands/posts.rb', line 7

def list
  response = client.posts
  items = response["latest_posts"] || []
  formatter.print_list(items)
rescue DiscourseApi::DiscourseError => e
  handle_error(e)
end

#show(id) ⇒ Object



16
17
18
19
20
# File 'lib/discourse_cli/commands/posts.rb', line 16

def show(id)
  formatter.print_item(client.get_post(id.to_i))
rescue DiscourseApi::DiscourseError => e
  handle_error(e)
end

#update(id) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/discourse_cli/commands/posts.rb', line 35

def update(id)
  raw = resolve_raw(options[:raw])
  client.edit_post(id.to_i, raw)
  formatter.print_success("Updated post #{id}")
rescue DiscourseApi::DiscourseError => e
  handle_error(e)
end