Browse files

Fixing rendering of cURL multiline body, new-lines in PHP and Python,…

… NodeJS on new-lines for readability
  • Loading branch information...
1 parent 9f707a4 commit ee2752cddfd1eca52ac49465430e987695782efa @kuba-kubula kuba-kubula committed Jan 30, 2013
Showing with 30 additions and 17 deletions.
  1. +1 −2 curl.html
  2. +8 −4 nodejs.html
  3. +1 −1 php.html
  4. +20 −10 python.html
View
3 curl.html
@@ -2,7 +2,6 @@
<p class="ioDesc">Request</p>
<pre class="incoming"><code class="language-bash">curl --include<% if @headers: %><% for header,value of @headers: %> --header <%= @helpers.escape "#{header}: #{value}" %><% end %> \
<% end %><% if @method isnt 'GET' or @body: %> --request <%= @method %> \
- <% end %><%if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain"): %> --data "<%= ((@helpers.escape line)[1..-2] + "\n" for line in @body)[0..-2] %>" \
- <% else if @body: %> --data <%= @helpers.escape @body %> \
+ <% end %><% if @body: %> --data <%= @helpers.escape @body %> \
<% end %>"<%= @apiUrl %><%= @url %>"</code></pre>
</section>
View
12 nodejs.html
@@ -5,12 +5,16 @@
request("<%= @apiUrl %><%= @url %>", function (error, response, body) {
<% else : %>
request({
- url: "<%= @apiUrl %><%= @url %>",<% if @body: %>
- body: <%= @helpers.escape @body %>,<% end %><% if @helpers.isNotEmpty @headers: %>
- headers: {<%= ("#{@helpers.escape header}: #{@helpers.escape value}" for header,value of @headers).join(", ") %>}, <% end %>
+ url: "<%= @apiUrl %><%= @url %>",
+<% if @body: %>
+ body: <%= @helpers.escape @body %>,
+<% end %>
+<% if @helpers.isNotEmpty @headers: %>
+ headers: {<%= ("#{@helpers.escape header}: #{@helpers.escape value}" for header,value of @headers).join(", ") %>},
+<% end %>
method: "<%= @method.toUpperCase() %>"
}, function (error, response, body) {
-<% end %>
+<% end %>
console.log("Status", response.statusCode);
console.log("Headers", JSON.stringify(response.headers));
console.log("Reponse received", body);
View
2 php.html
@@ -13,7 +13,7 @@
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "<%= @method %>");
<% end %>
<% if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain"): %>
-$fields = <%= eos %><%= "#{line}\n" for line in @body %>EOT;
+$fields = <%= eos %><%= "#{line}\n" for line in @body.split('\n') %>EOT;
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
<% else if @body and @body.length > 0: %>
curl_setopt($ch, CURLOPT_POSTFIELDS, <%= @helpers.escape @body %>);
View
30 python.html
@@ -1,16 +1,26 @@
<section name="python" class="python">
<p class="ioDesc">Request</p>
<pre class="incoming"><code class="language-python">from urllib2 import Request, urlopen
-<% if @contentType is "application/json": %>from json import dumps
-<% else if @contentType is "application/x-www-form-urlencoded": %>from urllib import urlencode
+<% if @contentType is "application/json": %>
+from json import dumps
+<% else if @contentType is "application/x-www-form-urlencoded": %>
+from urllib import urlencode
<% end %>
-<% if @contentType is "application/x-www-form-urlencoded" and @body: %>values = urlencode(<%= @body %>)
-<% else if @contentType is "application/json" and @body: %>values = dumps(<%= @body %>)
-<% else if @method isnt 'GET' and (@contentType is "text/html" or @contentType is "text/plain") and @body: %>values = <%= @helpers.escape @body %>
-<% else if @method isnt 'GET' and @body: %>values = <%= @helpers.escape @body %>
-<% end %><% if @helpers.isNotEmpty @headers: %>headers = {<%= ("#{@helpers.escape header}: #{@helpers.escape value}" for header,value of @headers).join(", ") %>}
-<% end %>request = Request("<%= @apiUrl %><%= @url %>"<% if @method isnt 'GET' and @body : %>, data=values<% end %><% if @helpers.isNotEmpty @headers: %>, headers=headers<% end %>)
-<% if @method not in ['GET', 'POST'] : %>request.get_method = lambda: '<%= @method %>'
-<% end %>response_body = urlopen(request).read()
+<% if @contentType is "application/x-www-form-urlencoded" and @body: %>
+values = urlencode(<%= @body %>)
+<% else if @contentType is "application/json" and @body: %>
+values = dumps(<%= @body %>)
+<% else if @method isnt 'GET' and @body: %>
+values = <%= @helpers.escape @body %>
+
+<% end %>
+<% if @helpers.isNotEmpty @headers: %>
+headers = {<%= ("#{@helpers.escape header}: #{@helpers.escape value}" for header,value of @headers).join(", ") %>}
+<% end %>
+request = Request("<%= @apiUrl %><%= @url %>"<% if @method isnt 'GET' and @body : %>, data=values<% end %><% if @helpers.isNotEmpty @headers: %>, headers=headers<% end %>)
+<% if @method not in ['GET', 'POST'] : %>
+request.get_method = lambda: '<%= @method %>'
+<% end %>
+response_body = urlopen(request).read()
print response_body</code></pre>
</section>

0 comments on commit ee2752c

Please sign in to comment.