forked from apiaryio/language-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruby.html
21 lines (19 loc) · 991 Bytes
/
ruby.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<section name="ruby" class="ruby">
<p class="ioDesc">Request</p>
<pre class="incoming"><code class="language-ruby">require 'rubygems' if RUBY_VERSION < '1.9'
require 'rest_client'
<% if @body and @contentType is "application/x-www-form-urlencoded": %>
values = CGI::escape(<%= @helpers.escape @body %>)
<% else if @body and @contentType is "application/json": %>
values = <%= @helpers.escape @body %>
<% else if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain"): %>
values = <%= @helpers.escape(@body or '') %>
<% else if @body: %>
values = <%= @helpers.escape @body %>
<% end %>
<% if @helpers.isNotEmpty @headers: %>
headers = {<%= [':'[email protected](header)+' => '[email protected] value for header,value of @headers] %>}
<% end %>
response = RestClient.<%= @method.toLowerCase() %> "<%= @apiUrl %><%= @url %>"<% if @body: %>, values<% end %><% if @helpers.isNotEmpty @headers: %>, headers<% end %>
puts response</code></pre>
</section>