Class: Herdic::Printer

Inherits:
Object
  • Object
show all
Defined in:
lib/herdic/printer.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Printer

Returns a new instance of Printer.



8
9
10
# File 'lib/herdic/printer.rb', line 8

def initialize(options)
  @options = options
end

Instance Method Details

#request(header, body) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/herdic/printer.rb', line 40

def request(header, body)
  subtitle 'Request'

  if header.empty?
    puts Util.color('no header', :white)
  else
    print_header header
  end

  hr

  print_json body
end

#response(response, body) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/herdic/printer.rb', line 54

def response(response, body)
  subtitle "Response: #{response.code} #{response.message}"

  print_header response.to_hash

  hr

  if !body || body.empty?
    puts Util.color('no body', :white)
  elsif 'application/json' == response.content_type
    print_json body
  else
    puts body
  end
end

#start_message(config_file = nil) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/herdic/printer.rb', line 12

def start_message(config_file = nil)
  if config_file
    puts "Starting Herdic (#{config_file})"
  else
    puts 'Starting Herdic'
  end
end

#subtitle(text) ⇒ Object



34
35
36
37
38
# File 'lib/herdic/printer.rb', line 34

def subtitle(text)
  puts
  puts Util.color(text, :green)
  hr color: :green
end

#title(meta) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/herdic/printer.rb', line 20

def title(meta)
  puts "\n\n"
  hr rule: '=', color: :green

  puts [Util.color(meta['method'], :green), meta['endpoint']].join('  ')

  if meta['title']
    indent = ' ' * meta['method'].size
    puts [indent, Util.color(meta['title'], :white)].join('  ')
  end

  hr rule: '=', color: :green
end