Class: Bl::Wiki

Inherits:
Command show all
Defined in:
lib/bl/wiki.rb

Instance Method Summary collapse

Methods included from Printer

print_response, printable_issues

Methods included from Formatting

colorize_priority, colorize_status, colorize_type

Methods included from Requestable

client, formatter, request

Constructor Details

#initializeWiki

Returns a new instance of Wiki.



3
4
5
6
7
# File 'lib/bl/wiki.rb', line 3

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

Instance Method Details

#add(name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bl/wiki.rb', line 12

def add(name)
  res = request(
    :post,
    @url,
    projectId: options[:projectId],
    name: name,
    content: options[:content]
    )
  puts 'wiki added:'
  print_response(res, :wiki)
end

#countObject



26
27
28
29
30
# File 'lib/bl/wiki.rb', line 26

def count
  res = request(:get, "#{@url}/count", projectIdOrKey: options[:projectIdOrKey])
  puts 'wiki count'
  puts res.body.count
end

#delete(id) ⇒ Object



33
34
35
36
37
# File 'lib/bl/wiki.rb', line 33

def delete(id)
  res = request(:delete, "#{@url}/#{id}")
  puts 'wiki deleted'
  print_response(res, :wiki)
end

#edit(id) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bl/wiki.rb', line 66

def edit(id)
  wiki_content = request(: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
    request(:patch, "#{@url}/#{id}", content: new_content)
    puts "wiki #{id} updated."
  ensure
    file.close
    file.unlink
  end
end

#listObject



40
41
42
43
# File 'lib/bl/wiki.rb', line 40

def list
  res = request(:get, @url, projectIdOrKey: @config[:project_key])
  print_response(res, :wiki)
end

#show(id) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/bl/wiki.rb', line 46

def show(id)
  body = request(: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

#tagsObject



59
60
61
62
63
# File 'lib/bl/wiki.rb', line 59

def tags
  res = request(:get, "#{@url}/tags", projectIdOrKey: options[:projectIdOrKey])
  puts 'wiki tags:'
  print_response(res, :named)
end