Permalink
Browse files

Adapt examples to new headers object

  • Loading branch information...
1 parent ec8401f commit dd40e498982e4a3689de7617b964a8f9b7b8fd09 @Almad Almad committed Apr 10, 2012
Showing with 7 additions and 7 deletions.
  1. +1 −1 curl.html
  2. +3 −3 nodejs.html
  3. +1 −1 python.html
  4. +1 −1 raw.html
  5. +1 −1 ruby.html
View
@@ -1,7 +1,7 @@
<section name="curl">
<p class="ioDesc">In</p>
<pre class="incoming brush:shell">
-curl --include<% if @headers?.length: %><% for header in @headers: %> --header "<%= header[0]%>: <%= header[1] %>"<% end %> \
+curl --include<% if @headers: %><% for header,value of @headers: %> --header "<%= header %>: <%= value %>"<% end %> \
<% end %><% if @method isnt 'GET': %> --request <%= @method %> \
<% end %><% if @body: %> --data <%= @helpers.escape @body %> \
<% end %> "<%= @apiUrl %><%= @url %>"
View
@@ -2,13 +2,13 @@
<p class="ioDesc">In</p>
<pre class="incoming brush:js">
var request = require("request");
-<% if @method is "GET" : %>
+<% if @method is "GET" and not @headers: %>
request("<%= @apiUrl %><%= @url %>", function (error, response, body) {
<% else : %>
request({
url: "<%= @apiUrl %><%= @url %>",<% if @body: %>
- body: <%= @helpers.escape @body %>,<% end %><% if @headers.length: %>
- headers: {<%= ['"'+header[0]+'": "'+header[1]+'"' for header in @headers].join(", ") %>}, <% end %>
+ body: <%= @helpers.escape @body %>,<% end %><% if @headers: %>
+ headers: {<%= ('"'+header+'": "'+value+'"' for header,value of @headers).join(", ") %>}, <% end %>
method: "<%= @method.toUpperCase() %>"
}, function (error, response, body) {
<% end %> console.log("Reponse received", response);
View
@@ -8,7 +8,7 @@
<% if @contentType is "application/x-www-form-urlencoded": %>values = urlencode(<%= @body %>)
<% else if @contentType is "application/json": %>values = dumps(<%= @body %>)
<% else if @method isnt 'GET': %>values = <%= @helpers.escape @body %>
-<% end %><% if @headers?.length: %>headers = {<%= ['"'+header[0]+'": "'+header[1]+'"' for header in @headers].join(", ") %>}
+<% end %><% if @headers: %>headers = {<%= ('"'+header+'": "'+value+'"' for header,value of @headers).join(", ") %>}
<% end %>request = Request("<%= @apiUrl %><%= @url %>"<% if @method in ['POST', 'PUT'] : %>, data=values<% end %><% if @headers?.length: %>, headers=headers<% end %>)
<% if @method not in ['GET', 'POST'] : %>request.get_method = lambda: '<%= @method %>'
<% end %>response_body = urlopen(request).read()
View
@@ -1,5 +1,5 @@
<section name="raw">
<p class="ioDesc">In</p>
- <pre class="incoming"><%= header.join(': ')+'\n' for header in @headers %></pre>
+ <pre class="incoming"><%= "#{header}: #{value}\n" for header, value of @headers %></pre>
<pre class="incoming<%= @helpers.getContentTypeBrush @headers %>"><%= @body %></pre>
</section>
View
@@ -6,7 +6,7 @@
<% if @contentType is "application/x-www-form-urlencoded": %>values = CGI::escape(<%= @helpers.escape @body %>)
<% else if @contentType is "application/json": %>values = <%= @helpers.escape @body %>
<% else if @body: %>values = <%= @helpers.escape @body %>
-<% end %><% if @headers?.length: %>headers = {<%= @headers.map((h)=> ":#{@helpers.rubyKey h[0]} => \"#{h[1]}\"" ).join(', ') %>}
+<% end %><% if @headers: %>headers = {<%= ['"'+@helpers.rubyKey header+'" => "'+value+'"' for header,value of @headers].join(", ") %>}
<% end %>response = RestClient.<%= @method.toLowerCase() %> "<%= @apiUrl %><%= @url %>"<% if @body: %>, values<% end %><% if @headers?.length: %>, headers<% end %>
</pre>
</section>

0 comments on commit dd40e49

Please sign in to comment.