46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/documentary/view/helpers.rb', line 46
def endpoint_blocks
io = StringIO.new
io.puts "## #{link_to('Endpoints')}"
io.puts new_line
docblocks.endpoints.each do |endpoint|
io.puts "### #{link_to(endpoint.title)}"
io.puts new_line
io.puts endpoint.notes if endpoint.notes
io.puts new_line
io.puts '#### Enpoint URL'
io.puts new_line
io.puts start_code_block
io.puts "#{endpoint.verb} #{endpoint.endpoint}"
io.puts end_code_block
if endpoint.information
io.puts '#### Endpoint Information'
io.puts new_line
endpoint.information.each do |key, value|
io.puts "* **#{key.titleize}**: #{value}"
end
end
if endpoint.params
io.puts new_line
io.puts '#### Parameters'
io.puts new_line
io.puts 'Name | Required | Description'
io.puts '-------- | -------- | -----------'
endpoint.params.each do |param|
io.puts "#{param.keys.first} | #{param['required']} | #{param['notes'].strip}"
end
end
if endpoint.example_request
io.puts new_line
io.puts '#### Example Request'
io.puts new_line
example_request = YAML.load(endpoint.example_request)
if example_request['query']
io.puts start_code_block
io.puts "#{endpoint.verb} #{endpoint.endpoint}" << '?' << query_params(example_request['query'])
io.puts end_code_block
end
if example_request['body']
io.puts start_code_block
example_request['body'].each do |b|
io.puts request_payload(b)
io.puts new_line
end
io.puts start_code_block
end
end
if endpoint.example_response
io.puts new_line
io.puts '#### Example Response'
io.puts new_line
io.puts start_code_block
io.puts JSON.pretty_generate(endpoint.example_response)
io.puts end_code_block
end
end
io.string
end
|