Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial transfer of language templates

  • Loading branch information...
commit ec8401f01006784028f57f7379f0b6b984d04917 0 parents
Almad Almad authored
Showing with 59 additions and 0 deletions.
  1. +9 −0 curl.html
  2. +17 −0 nodejs.html
  3. +16 −0 python.html
  4. +5 −0 raw.html
  5. +12 −0 ruby.html
9 curl.html
@@ -0,0 +1,9 @@
+<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 %> \
+ <% end %><% if @method isnt 'GET': %> --request <%= @method %> \
+ <% end %><% if @body: %> --data <%= @helpers.escape @body %> \
+ <% end %> "<%= @apiUrl %><%= @url %>"
+</pre>
+</section>
17 nodejs.html
@@ -0,0 +1,17 @@
+<section name="nodejs">
+ <p class="ioDesc">In</p>
+ <pre class="incoming brush:js">
+var request = require("request");
+<% if @method is "GET" : %>
+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 %>
+ method: "<%= @method.toUpperCase() %>"
+}, function (error, response, body) {
+<% end %> console.log("Reponse received", response);
+});
+
+</section>
16 python.html
@@ -0,0 +1,16 @@
+<section name="python">
+ <p class="ioDesc">In</p>
+ <pre class="incoming brush: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
+<% end %>
+<% 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 %>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()
+</pre>
+</section>
5 raw.html
@@ -0,0 +1,5 @@
+<section name="raw">
+ <p class="ioDesc">In</p>
+ <pre class="incoming"><%= header.join(': ')+'\n' for header in @headers %></pre>
+ <pre class="incoming<%= @helpers.getContentTypeBrush @headers %>"><%= @body %></pre>
+</section>
12 ruby.html
@@ -0,0 +1,12 @@
+<section name="ruby">
+ <p class="ioDesc">In</p>
+ <pre class="incoming brush:ruby">
+require 'rest_client'
+
+<% 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 %>response = RestClient.<%= @method.toLowerCase() %> "<%= @apiUrl %><%= @url %>"<% if @body: %>, values<% end %><% if @headers?.length: %>, headers<% end %>
+</pre>
+</section>
Please sign in to comment.
Something went wrong with that request. Please try again.