Class: Bl::Wiki

Inherits:
Thor
  • Object
show all
Includes:
Requestable
Defined in:
lib/bl/wiki.rb

Instance Method Summary collapse

Methods included from Requestable

client

Constructor Details

#initialize ⇒ Wiki

Returns a new instance of Wiki.



5
6
7
8
9
# File 'lib/bl/wiki.rb', line 5

def initialize(*)
  @config = Bl::Config.instance
  @url = 'wikis'
  super
end

Instance Method Details

#edit(id) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bl/wiki.rb', line 31

def edit(id)
  wiki_content = client.get("#{@url}/#{id}").body.content
  file = Tempfile.new
  file.puts(wiki_content)
  file.close
  begin
    file.open
    system("$EDITOR #{file.path}")
    new_content = file.read
    client.patch("#{@url}/#{id}", content: new_content)
    puts "wiki #{id} updated."
  ensure
    file.close
    file.unlink
  end
end

#list ⇒ Object



12
13
14
15
16
# File 'lib/bl/wiki.rb', line 12

def list
  client.get(@url, projectIdOrKey: @config[:project_key]).body.each do |w|
    puts [w.id, w.projectId, w.name, w.updated].join("\t")
  end
end

#show(id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/bl/wiki.rb', line 19

def show(id)
  body = client.get("#{@url}/#{id}").body
  puts "id: #{body.id}"
  puts "projectId: #{body.projectId}"
  puts "name: #{body.name}"
  puts "updated: #{body.updated}"
  puts '--'
  puts 'content:'
  puts body.content
end