Update usage examples, add Ruby. Fixes #158

This commit is contained in:
Pēteris Caune 2018-03-13 12:18:32 +02:00
parent 61191d1cb9
commit 6bc3a445db
9 changed files with 54 additions and 8 deletions

View File

@ -31,12 +31,13 @@ class Command(BaseCommand):
_process("bash_wget", lexers.BashLexer())
_process("browser", lexers.JavascriptLexer())
_process("crontab", lexers.BashLexer())
_process("node", lexers.JavascriptLexer())
_process("python_urllib2", lexers.PythonLexer())
_process("python_requests", lexers.PythonLexer())
_process("php", lexers.PhpLexer())
_process("powershell", lexers.shell.PowerShellLexer())
_process("powershell_inline", lexers.shell.BashLexer())
_process("node", lexers.JavascriptLexer())
_process("ruby", lexers.RubyLexer())
# API examples
_process("list_checks_request", lexers.BashLexer())

View File

@ -12,6 +12,7 @@
<li><a href="{% url 'hc-docs' %}#crontab">Crontab</a></li>
<li><a href="{% url 'hc-docs' %}#bash">Bash</a></li>
<li><a href="{% url 'hc-docs' %}#python">Python</a></li>
<li><a href="{% url 'hc-docs' %}#ruby">Ruby</a></li>
<li><a href="{% url 'hc-docs' %}#node">Node</a></li>
<li><a href="{% url 'hc-docs' %}#php">PHP</a></li>
<li><a href="{% url 'hc-docs' %}#browser">Browser</a></li>

View File

@ -115,9 +115,24 @@ thing: they fire off a HTTP GET method.</p>
<a name="python"></a>
<h3>Python</h3>
{% include "front/snippets/python_urllib2.html" %}
<p>
If you are already using the
<a href="http://docs.python-requests.org/en/master/">requests</a> library,
it's convenient to also use it here:
</p>
{% include "front/snippets/python_requests.html" %}
<p>
Otherwise, you can use the <code>urllib</code> standard module.
</p>
{% include "front/snippets/python_urllib2.html" %}
<a name="ruby"></a>
<h3>Ruby</h3>
{% include "front/snippets/ruby.html" %}
<a name="node"></a>
<h3>Node</h3>
{% include "front/snippets/node.html" %}

View File

@ -286,6 +286,9 @@
<li>
<a href="#python" data-toggle="tab">Python</a>
</li>
<li>
<a href="#ruby" data-toggle="tab">Ruby</a>
</li>
<li class="hidden-xs">
<a href="#node" data-toggle="tab">Node.js</a>
</li>
@ -318,6 +321,9 @@
{% include "front/snippets/python_urllib2.html" %}
{% include "front/snippets/python_requests.html" %}
</div>
<div role="tabpanel" class="tab-pane" id="ruby">
{% include "front/snippets/ruby.html" %}
</div>
<div role="tabpanel" class="tab-pane" id="node">
{% include "front/snippets/node.html" %}
</div>

View File

@ -1,4 +1,8 @@
<div class="highlight"><pre><span></span><span class="c1"># using urllib2:</span>
<span class="kn">import</span> <span class="nn">urllib2</span>
<span class="n">urllib2</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s2">&quot;{{ ping_url }}&quot;</span><span class="p">)</span>
<div class="highlight"><pre><span></span><span class="c1"># urllib with python 3.x:</span>
<span class="kn">import</span> <span class="nn">urllib.request</span>
<span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s2">&quot;{{ ping_url }}&quot;</span><span class="p">)</span>
<span class="c1"># urllib with python 2.x:</span>
<span class="kn">import</span> <span class="nn">urllib</span>
<span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s2">&quot;{{ ping_url }}&quot;</span><span class="p">)</span>
</pre></div>

View File

@ -1,3 +1,7 @@
# using urllib2:
import urllib2
urllib2.urlopen("PING_URL")
# urllib with python 3.x:
import urllib.request
urllib.request.urlopen("PING_URL")
# urllib with python 2.x:
import urllib
urllib.urlopen("PING_URL")

View File

@ -0,0 +1,5 @@
<div class="highlight"><pre><span></span><span class="nb">require</span> <span class="s1">&#39;net/http&#39;</span>
<span class="nb">require</span> <span class="s1">&#39;uri&#39;</span>
<span class="no">Net</span><span class="o">::</span><span class="no">HTTP</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="no">URI</span><span class="o">.</span><span class="n">parse</span><span class="p">(</span><span class="s1">&#39;{{ ping_url }}&#39;</span><span class="p">))</span>
</pre></div>

View File

@ -0,0 +1,4 @@
require 'net/http'
require 'uri'
Net::HTTP.get(URI.parse('PING_URL'))

View File

@ -41,6 +41,9 @@
<li>
<a href="#python" data-toggle="tab">Python</a>
</li>
<li class="hidden-xs">
<a href="#ruby" data-toggle="tab">Ruby</a>
</li>
<li class="hidden-xs">
<a href="#node" data-toggle="tab">Node.js</a>
</li>
@ -69,6 +72,9 @@
{% include "front/snippets/python_urllib2.html" %}
{% include "front/snippets/python_requests.html" %}
</div>
<div role="tabpanel" class="tab-pane" id="ruby">
{% include "front/snippets/ruby.html" %}
</div>
<div role="tabpanel" class="tab-pane" id="node">
{% include "front/snippets/node.html" %}
</div>