<?xml version="1.0" encoding="UTF-8"?>
<examples type="array">
  <example>
    <content>When using Adhearsion with Asterisk, you have [hundreds](http://www.voip-info.org/wiki/view/Asterisk+sound+files) of sound files to use right out of the box.

These range from the useful everyday sound files to pure novelties such as monkeys screaming and practical jokes.

To play a sound file, use the [``play``](http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#play-instance_method) method like below.

    # Ruby
    play &quot;hello-world&quot;

You can play multiple files in sequence too.

    # Ruby
    play &quot;please-enter-your&quot;, &quot;extension&quot;

If this is your first time seeing Ruby, ``play`` is actually a method. Ruby does not require you wrap a method's arguments with parenthesis.</content>
    <content-html>&lt;p&gt;When using Adhearsion with Asterisk, you have &lt;a href=&quot;http://www.voip-info.org/wiki/view/Asterisk+sound+files&quot;&gt;hundreds&lt;/a&gt; of sound files to use right out of the box.&lt;/p&gt;

&lt;p&gt;These range from the useful everyday sound files to pure novelties such as monkeys screaming and practical jokes.&lt;/p&gt;

&lt;p&gt;To play a sound file, use the &lt;a href=&quot;http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#play-instance_method&quot;&gt;&lt;code&gt;play&lt;/code&gt;&lt;/a&gt; method like below.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;hello-world&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;You can play multiple files in sequence too.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;please-enter-your&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;,&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;extension&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;If this is your first time seeing Ruby, &lt;code&gt;play&lt;/code&gt; is actually a method. Ruby does not require you wrap a method's arguments with parenthesis.&lt;/p&gt;</content-html>
    <created-at type="datetime">2009-02-16T03:50:14Z</created-at>
    <example-section-id type="integer">1</example-section-id>
    <id type="integer">1</id>
    <position type="integer">1</position>
    <title>Play a sound file</title>
    <updated-at type="datetime">2009-02-19T02:30:39Z</updated-at>
  </example>
  <example>
    <content>Adhearsion creates a number of variables for you when it runs your dialplan which are available in any context you may jump around to.

For example, the following dialplan will speak back whatever extension the user dials.

    # Ruby
    adhearsion {
      play extension
    }

The ``extension`` variable in this case is actually not an variable. It's a method that, because of Ruby's cleanliness, simply look like local variable. This may be a little confusing to you at first. Consider the following example:

    # Ruby
    adhearsion {
      extension = extension + 1
      play extension
      +player
    }
    player { 
      play extension
    }

When the ``adhearsion`` context jumps to the ``player`` context, you may think both contexts will speak the same number. It actually won't for a slightly technical reason:

When ``extension`` is defined with the ``=`` sign, Ruby will make that into a local variable and &quot;shadow&quot; anything else in a higher scope that may have that same name. Because the method ``extension`` is in a higher scope, the local variable will take precedence, but _only in the local scope_. The ``player`` context has its own, separate scope and, therefore, the ``extension`` instance method is used.

To share information between contexts, simply use Ruby instance variables. We can rewrite the previous example properly as follows:

    # Ruby
    adhearsion {
      @extension = extension + 1
      play @extension
      +player
    }
    player { 
      play @extension
    }

All contexts will run within the same Execution Environment object and therefore all instance variables will remain in scope no matter how many times you jump around.</content>
    <content-html>&lt;p&gt;Adhearsion creates a number of variables for you when it runs your dialplan which are available in any context you may jump around to.&lt;/p&gt;

&lt;p&gt;For example, the following dialplan will speak back whatever extension the user dials.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;adhearsion&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;extension&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;extension&lt;/code&gt; variable in this case is actually not an variable. It's a method that, because of Ruby's cleanliness, simply look like local variable. This may be a little confusing to you at first. Consider the following example:&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;adhearsion&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;extension&lt;/span&gt;
  &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;player&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;player&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt; 
  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;extension&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;When the &lt;code&gt;adhearsion&lt;/code&gt; context jumps to the &lt;code&gt;player&lt;/code&gt; context, you may think both contexts will speak the same number. It actually won't for a slightly technical reason:&lt;/p&gt;

&lt;p&gt;When &lt;code&gt;extension&lt;/code&gt; is defined with the &lt;code&gt;=&lt;/code&gt; sign, Ruby will make that into a local variable and &quot;shadow&quot; anything else in a higher scope that may have that same name. Because the method &lt;code&gt;extension&lt;/code&gt; is in a higher scope, the local variable will take precedence, but &lt;em&gt;only in the local scope&lt;/em&gt;. The &lt;code&gt;player&lt;/code&gt; context has its own, separate scope and, therefore, the &lt;code&gt;extension&lt;/code&gt; instance method is used.&lt;/p&gt;

&lt;p&gt;To share information between contexts, simply use Ruby instance variables. We can rewrite the previous example properly as follows:&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;adhearsion&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;attribute&quot;&gt;@extension&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;attribute&quot;&gt;@extension&lt;/span&gt;
  &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;player&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;player&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt; 
  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;attribute&quot;&gt;@extension&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;All contexts will run within the same Execution Environment object and therefore all instance variables will remain in scope no matter how many times you jump around.&lt;/p&gt;</content-html>
    <created-at type="datetime">2009-02-16T04:27:58Z</created-at>
    <example-section-id type="integer">1</example-section-id>
    <id type="integer">2</id>
    <position type="integer">1</position>
    <title>Sharing variables between contexts</title>
    <updated-at type="datetime">2009-02-20T15:42:24Z</updated-at>
  </example>
  <example>
    <content>Taking input via phone keypad input is extremely simple.

    # Ruby
    desired_extension = input

The example above shows a Ruby principle at work: *convention over configuration*. All of [``input``](http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#input-instance_method)'s parameters are optional. The code above simply receives any number of digits with no timeout until the user presses the &quot;#&quot; key. The result is then bound to the ``desired_extension`` variable with the delimiting &quot;#&quot; removed.

Or you can explicitly receive a number of digits with a timeout.

    # Ruby
    desired_extension = input 3, :timeout =&gt; 1.minute

This takes in three digits, waiting up to one minute for each successive key entry. Though a one minute timeout is a bit contrived, this example shows an interesting feature of Ruby: everything, even numbers, is an object. Objects have methods, therefore a ``minute`` method makes perfect sense.</content>
    <content-html>&lt;p&gt;Taking input via phone keypad input is extremely simple.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;desired_extension&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;input&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;The example above shows a Ruby principle at work: &lt;em&gt;convention over configuration&lt;/em&gt;. All of &lt;a href=&quot;http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#input-instance_method&quot;&gt;&lt;code&gt;input&lt;/code&gt;&lt;/a&gt;'s parameters are optional. The code above simply receives any number of digits with no timeout until the user presses the &quot;#&quot; key. The result is then bound to the &lt;code&gt;desired_extension&lt;/code&gt; variable with the delimiting &quot;#&quot; removed.&lt;/p&gt;

&lt;p&gt;Or you can explicitly receive a number of digits with a timeout.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;desired_extension&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:timeout&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;minute&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;This takes in three digits, waiting up to one minute for each successive key entry. Though a one minute timeout is a bit contrived, this example shows an interesting feature of Ruby: everything, even numbers, is an object. Objects have methods, therefore a &lt;code&gt;minute&lt;/code&gt; method makes perfect sense.&lt;/p&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:01:04Z</created-at>
    <example-section-id type="integer">1</example-section-id>
    <id type="integer">3</id>
    <position type="integer">2</position>
    <title>Receiving keypad input</title>
    <updated-at type="datetime">2009-02-19T02:30:39Z</updated-at>
  </example>
  <example>
    <content>Want the user to join a conference bridge? Just tell them to [join](http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#join-instance_method) something.

    # Ruby
    join &quot;sales&quot;

You can make the conference name virtually anything. For example, if you create a web-based tool to manage your company's conferences, you can make the conference name the unique ID of that conference's database record.

The join method uses the Asterisk [MeetMe](http://www.voip-info.org/wiki-Asterisk+cmd+MeetMe) application. Alternatively, you may use the add-on application [Conference](http://www.voip-info.org/wiki/view/Asterisk+cmd+Conference) using the [execute](http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#execute-instance_method) method as follows:

    # Ruby
    execute(&quot;Conference&quot;, &quot;room/S&quot;)</content>
    <content-html>&lt;p&gt;Want the user to join a conference bridge? Just tell them to &lt;a href=&quot;http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#join-instance_method&quot;&gt;join&lt;/a&gt; something.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;join&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;sales&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;You can make the conference name virtually anything. For example, if you create a web-based tool to manage your company's conferences, you can make the conference name the unique ID of that conference's database record.&lt;/p&gt;

&lt;p&gt;The join method uses the Asterisk &lt;a href=&quot;http://www.voip-info.org/wiki-Asterisk+cmd+MeetMe&quot;&gt;MeetMe&lt;/a&gt; application. Alternatively, you may use the add-on application &lt;a href=&quot;http://www.voip-info.org/wiki/view/Asterisk+cmd+Conference&quot;&gt;Conference&lt;/a&gt; using the &lt;a href=&quot;http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#execute-instance_method&quot;&gt;execute&lt;/a&gt; method as follows:&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;execute&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;Conference&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;,&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;room/S&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;)&lt;/span&gt;
&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:03:17Z</created-at>
    <example-section-id type="integer">1</example-section-id>
    <id type="integer">4</id>
    <position type="integer">3</position>
    <title>Joining a conference bridge</title>
    <updated-at type="datetime">2009-02-19T04:32:33Z</updated-at>
  </example>
  <example>
    <content>The Adhearsion dialplan.rb mirrors the Asterisk concept of a context. Within the [extensions.conf](http://www.voip-info.org/tiki-index.php?page=Asterisk%20config%20extensions.conf) file of Asterisk you may have these [contexts](http://www.voip-info.org/wiki-Asterisk+Dialplan+Introduction):

    [from_dallas]
    exten =&gt; _X.,1,AGI(agi://localhost)
    exten =&gt; _X.,n,Hangup

    [from_chicago]
    exten =&gt; _X.,1,AGI(agi://localhost)
    exten =&gt; _X.,n,Hangup

You would then have these corresponding contexts in the Adhearsion dialplan.rb:

    # Ruby
    from_texas {
      play 'hello', 'texas'
      # do more here
    }

    from_illinois {
      play 'hello', 'illinois'
      # do more here
    }

Further, you may have additional contexts in the Adhearsion dialplan.rb that may be mixed in as follows:

    # Ruby
    from_omaha {
      play 'hello', 'omaha', 'and'
      +from_nebraska
    }

    from_nebraska {
      play 'hello', 'nebraska'
      # do more here
    }

With this feature you may have reusable code in contexts within dialplan.rb.
</content>
    <content-html>&lt;p&gt;The Adhearsion dialplan.rb mirrors the Asterisk concept of a context. Within the &lt;a href=&quot;http://www.voip-info.org/tiki-index.php?page=Asterisk%20config%20extensions.conf&quot;&gt;extensions.conf&lt;/a&gt; file of Asterisk you may have these &lt;a href=&quot;http://www.voip-info.org/wiki-Asterisk+Dialplan+Introduction&quot;&gt;contexts&lt;/a&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[from_dallas]
exten =&amp;gt; _X.,1,AGI(agi://localhost)
exten =&amp;gt; _X.,n,Hangup

[from_chicago]
exten =&amp;gt; _X.,1,AGI(agi://localhost)
exten =&amp;gt; _X.,n,Hangup
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;You would then have these corresponding contexts in the Adhearsion dialplan.rb:&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;from_texas&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;hello&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;texas&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;
  &lt;span class=&quot;comment&quot;&gt;# do more here&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;ident&quot;&gt;from_illinois&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;hello&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;illinois&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;
  &lt;span class=&quot;comment&quot;&gt;# do more here&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;Further, you may have additional contexts in the Adhearsion dialplan.rb that may be mixed in as follows:&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;from_omaha&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;hello&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;omaha&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;and&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;
  &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;from_nebraska&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;ident&quot;&gt;from_nebraska&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;hello&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;nebraska&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;
  &lt;span class=&quot;comment&quot;&gt;# do more here&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;With this feature you may have reusable code in contexts within dialplan.rb.&lt;/p&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:03:45Z</created-at>
    <example-section-id type="integer">1</example-section-id>
    <id type="integer">5</id>
    <position type="integer">4</position>
    <title>Using dialplan contexts</title>
    <updated-at type="datetime">2009-02-19T04:52:06Z</updated-at>
  </example>
  <example>
    <content>The [menu](http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#menu-instance_method) command solves the problem of building enormous input-fetching state machines in Ruby without first-class message passing facilities or an external DSL. In otherwords, build complex menus to collect actionable user input via [DTMF](http://en.wikipedia.org/wiki/Dtmf).

Here is an example dialplan which uses the menu command effectively:

    # Ruby
    from_pstn {
      menu 'welcome', 'for-spanish-press-8', 'main-ivr',
           :timeout =&gt; 8.seconds, :tries =&gt; 3 do |link|
        link.shipment_status  1
        link.ordering         2
        link.representative   4
        link.spanish          8
        link.employee         900..999

        link.on_invalid { play 'invalid' }

        link.on_premature_timeout do |str|
          play 'sorry'
        end

        link.on_failure do
          play 'goodbye'
          hangup
        end
      end
    }

    shipment_status {
      # Fetch a tracking number and pass it to a web service.
    }

    ordering {
      # Enter another menu that lets them enter credit card
      # information and place their order over the phone.
    }

    representative {
      # Place the caller into a queue
    }

    spanish {
      # Special options for the spanish menu.
    }

    employee {
      dial &quot;SIP/#{extension}&quot; # Overly simplistic
    }</content>
    <content-html>&lt;p&gt;The &lt;a href=&quot;http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#menu-instance_method&quot;&gt;menu&lt;/a&gt; command solves the problem of building enormous input-fetching state machines in Ruby without first-class message passing facilities or an external DSL. In otherwords, build complex menus to collect actionable user input via &lt;a href=&quot;http://en.wikipedia.org/wiki/Dtmf&quot;&gt;DTMF&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here is an example dialplan which uses the menu command effectively:&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;from_pstn&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;menu&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;welcome&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;for-spanish-press-8&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;main-ivr&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt;
       &lt;span class=&quot;symbol&quot;&gt;:timeout&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;seconds&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:tries&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;shipment_status&lt;/span&gt;  &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;ordering&lt;/span&gt;         &lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;representative&lt;/span&gt;   &lt;span class=&quot;number&quot;&gt;4&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;spanish&lt;/span&gt;          &lt;span class=&quot;number&quot;&gt;8&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;employee&lt;/span&gt;         &lt;span class=&quot;number&quot;&gt;900&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;999&lt;/span&gt;

    &lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;on_invalid&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;invalid&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;on_premature_timeout&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;sorry&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

    &lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;on_failure&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt;
      &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;goodbye&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;
      &lt;span class=&quot;ident&quot;&gt;hangup&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;ident&quot;&gt;shipment_status&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;comment&quot;&gt;# Fetch a tracking number and pass it to a web service.&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;ident&quot;&gt;ordering&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;comment&quot;&gt;# Enter another menu that lets them enter credit card&lt;/span&gt;
  &lt;span class=&quot;comment&quot;&gt;# information and place their order over the phone.&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;ident&quot;&gt;representative&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;comment&quot;&gt;# Place the caller into a queue&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;ident&quot;&gt;spanish&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;comment&quot;&gt;# Special options for the spanish menu.&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;ident&quot;&gt;employee&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;dial&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;SIP/&lt;span class=&quot;expr&quot;&gt;#{extension}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;comment&quot;&gt;# Overly simplistic&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:04:21Z</created-at>
    <example-section-id type="integer">1</example-section-id>
    <id type="integer">6</id>
    <position type="integer">5</position>
    <title>Simple menu example</title>
    <updated-at type="datetime">2009-02-19T04:33:24Z</updated-at>
  </example>
  <example>
    <content>With Adhearsion it is easy to access an [RDBMS](http://en.wikipedia.org/wiki/RDBMS) either through Rails or directly with [ActiveRecord](http://api.rubyonrails.org/classes/ActiveRecord/Base.html). Once you have your models setup, you may fetch information in a database and then iterate over it in your dialplan.rb.

In this example we will show pulling information from a database to build a [text to speech (TTS)](http://en.wikipedia.org/wiki/Text_to_speech) audio file to playback to the caller.

    # Ruby
    # my_model.rb
    class ParkingLot &lt; ActiveRecord::Base
    end
   
    # dialplan.rb
    parking_spaces_available {
      message = &quot;Welcome to the parking info service.&quot;

      # Fetch the parking lot details from the database
      parking_lots = ParkingLot.find(:all)

      # Then iterate over the results to build a menu
      parking_lots.each do |parking_lot|
        message = message + &quot; &quot; +
                  parking_lot.name + &quot; has &quot; +
                  parking_lot.spaces.to_s +
                  &quot;spaces available.&quot;
      end

      # Then if you have Festival TTS installed you may
      # build your TTS file and play it back to the caller
      filename = &quot;parking_spaces_available.ulaw&quot;
      system(&quot;echo #{message} | text2wave -o #{filename} -otype ulaw&quot;)
      play filename
    }</content>
    <content-html>&lt;p&gt;With Adhearsion it is easy to access an &lt;a href=&quot;http://en.wikipedia.org/wiki/RDBMS&quot;&gt;RDBMS&lt;/a&gt; either through Rails or directly with &lt;a href=&quot;http://api.rubyonrails.org/classes/ActiveRecord/Base.html&quot;&gt;ActiveRecord&lt;/a&gt;. Once you have your models setup, you may fetch information in a database and then iterate over it in your dialplan.rb.&lt;/p&gt;

&lt;p&gt;In this example we will show pulling information from a database to build a &lt;a href=&quot;http://en.wikipedia.org/wiki/Text_to_speech&quot;&gt;text to speech (TTS)&lt;/a&gt; audio file to playback to the caller.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# my_model.rb&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;class &lt;/span&gt;&lt;span class=&quot;class&quot;&gt;ParkingLot&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Base&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# dialplan.rb&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;parking_spaces_available&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;Welcome to the parking info service.&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;

  &lt;span class=&quot;comment&quot;&gt;# Fetch the parking lot details from the database&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;parking_lots&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;ParkingLot&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;symbol&quot;&gt;:all&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;comment&quot;&gt;# Then iterate over the results to build a menu&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;parking_lots&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;parking_lot&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt; &lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt;
              &lt;span class=&quot;ident&quot;&gt;parking_lot&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt; has &lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt;
              &lt;span class=&quot;ident&quot;&gt;parking_lot&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;spaces&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;to_s&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt;
              &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;spaces available.&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;comment&quot;&gt;# Then if you have Festival TTS installed you may&lt;/span&gt;
  &lt;span class=&quot;comment&quot;&gt;# build your TTS file and play it back to the caller&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;filename&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;parking_spaces_available.ulaw&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;echo &lt;span class=&quot;expr&quot;&gt;#{message}&lt;/span&gt; | text2wave -o &lt;span class=&quot;expr&quot;&gt;#{filename}&lt;/span&gt; -otype ulaw&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;)&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;filename&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:06:33Z</created-at>
    <example-section-id type="integer">2</example-section-id>
    <id type="integer">9</id>
    <position type="integer">1</position>
    <title>Iterating over all records in a table</title>
    <updated-at type="datetime">2009-02-19T17:21:20Z</updated-at>
  </example>
  <example>
    <content>In this example we will show finding one record from the database and using information from that row.

    # Ruby
    # my_model.rb
    class ParkingLot &lt; ActiveRecord::Base
    end
   
    # dialplan.rb
    parking_lot_menu {
      menu 'welcome', 'for-bush-st-press1', 'for-hyde-press2',
           :timeout =&gt; 8.seconds, :tries =&gt; 3 do |link|

        link.bush_st 1
        link.hyde_st 2
     }
 
     bush_st {
       # Here you may see we find the parking lot name
       # based on the column 'name'
       parking_lot = ParkingLot.find(:first,
                                     :conditions =&gt; { :name =&gt; &quot;Bush St&quot; })

       play &quot;bush-st-has&quot;, parking_lot.spaces, &quot;spaces-available&quot;
     }

     hyde_st {
       # Do the same thing here
     }</content>
    <content-html>&lt;p&gt;In this example we will show finding one record from the database and using information from that row.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# my_model.rb&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;class &lt;/span&gt;&lt;span class=&quot;class&quot;&gt;ParkingLot&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Base&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# dialplan.rb&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;parking_lot_menu&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;menu&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;welcome&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;for-bush-st-press1&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;for-hyde-press2&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt;
       &lt;span class=&quot;symbol&quot;&gt;:timeout&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;seconds&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:tries&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;

    &lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;bush_st&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;link&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;hyde_st&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2&lt;/span&gt;
 &lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;

 &lt;span class=&quot;ident&quot;&gt;bush_st&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;comment&quot;&gt;# Here you may see we find the parking lot name&lt;/span&gt;
   &lt;span class=&quot;comment&quot;&gt;# based on the column 'name'&lt;/span&gt;
   &lt;span class=&quot;ident&quot;&gt;parking_lot&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;ParkingLot&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;symbol&quot;&gt;:first&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt;
                                 &lt;span class=&quot;symbol&quot;&gt;:conditions&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:name&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;Bush St&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;})&lt;/span&gt;

   &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;bush-st-has&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;,&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;parking_lot&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;spaces&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;spaces-available&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
 &lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;

 &lt;span class=&quot;ident&quot;&gt;hyde_st&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;comment&quot;&gt;# Do the same thing here&lt;/span&gt;
 &lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:07:00Z</created-at>
    <example-section-id type="integer">2</example-section-id>
    <id type="integer">10</id>
    <position type="integer">1</position>
    <title>Finding the first record by a column value</title>
    <updated-at type="datetime">2009-02-19T17:21:33Z</updated-at>
  </example>
  <example>
    <content>Creating a new [component](http://docs.adhearsion.com/display/adhearsion/Components) is easy with the built-in Adhearsion generators. From within your ~/ahn_project/ directory type:

    ahn create component my_shiny_new_component

With this you get a directory and files as follows:

    # Directory
    ~/ahn_project/components/my_shiny_new_component

    # The files created are
    ~/ahn_project/components/my_shiny_new_component.rb
    ~/ahn_project/components/my_shiny_new_component.yml

You may then disable the component as follows:

    ahn disable component my_shiny_new_component

And enable as follows:

    ahn enable component my_shiny_new_component
</content>
    <content-html>&lt;p&gt;Creating a new &lt;a href=&quot;http://docs.adhearsion.com/display/adhearsion/Components&quot;&gt;component&lt;/a&gt; is easy with the built-in Adhearsion generators. From within your ~/ahn_project/ directory type:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ahn create component my_shiny_new_component
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;With this you get a directory and files as follows:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# Directory
~/ahn_project/components/my_shiny_new_component

# The files created are
~/ahn_project/components/my_shiny_new_component.rb
~/ahn_project/components/my_shiny_new_component.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You may then disable the component as follows:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ahn disable component my_shiny_new_component
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And enable as follows:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ahn enable component my_shiny_new_component
&lt;/code&gt;&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:07:13Z</created-at>
    <example-section-id type="integer">3</example-section-id>
    <id type="integer">11</id>
    <position type="integer">8</position>
    <title>Creating a new component</title>
    <updated-at type="datetime">2009-02-19T17:40:09Z</updated-at>
  </example>
  <example>
    <content>Now that you have created your component, you may begin to create methods accessible to the different subsystems of Adhearsion. To add a method in your component that becomes available to your dialplan.rb, simply do the following:

    # Ruby
    # In your my_shiny_new_component.rb file
    methods_for :dialplan do
      def count_to_ten
        cnt = 0
        while cnt &lt; 11
          cnt += 1
        end
        return cnt
      end
    end

    # Then in your dialplan.rb the method is available
    inbound {
      ten = count_to_ten
    }</content>
    <content-html>&lt;p&gt;Now that you have created your component, you may begin to create methods accessible to the different subsystems of Adhearsion. To add a method in your component that becomes available to your dialplan.rb, simply do the following:&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# In your my_shiny_new_component.rb file&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;methods_for&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:dialplan&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;def &lt;/span&gt;&lt;span class=&quot;method&quot;&gt;count_to_ten&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;11&lt;/span&gt;
      &lt;span class=&quot;ident&quot;&gt;cnt&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;cnt&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Then in your dialplan.rb the method is available&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;inbound&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;ten&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;count_to_ten&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:07:29Z</created-at>
    <example-section-id type="integer">3</example-section-id>
    <id type="integer">12</id>
    <position type="integer">9</position>
    <title>Adding a new dialplan method</title>
    <updated-at type="datetime">2009-02-19T17:58:17Z</updated-at>
  </example>
  <example>
    <content>Any component methods defined within the :global scope will be available anywhere in the Ruby process.

    # Ruby
    methods_for :global do
      def open_door
        RestClient.get(&quot;http://front-door/control/open&quot;)
      end
    end

When methods are defined in the global scope, you should make the assumption that you will only have access to other globally-available methods. Don't use dialplan methods such a ``play`` in your global methods; this would work when your dialplan calls the global method but blow up when another part of the framework calls it.</content>
    <content-html>&lt;p&gt;Any component methods defined within the :global scope will be available anywhere in the Ruby process.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;methods_for&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:global&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;def &lt;/span&gt;&lt;span class=&quot;method&quot;&gt;open_door&lt;/span&gt;
    &lt;span class=&quot;constant&quot;&gt;RestClient&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;http://front-door/control/open&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;)&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;When methods are defined in the global scope, you should make the assumption that you will only have access to other globally-available methods. Don't use dialplan methods such a &lt;code&gt;play&lt;/code&gt; in your global methods; this would work when your dialplan calls the global method but blow up when another part of the framework calls it.&lt;/p&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:07:47Z</created-at>
    <example-section-id type="integer">3</example-section-id>
    <id type="integer">13</id>
    <position type="integer">10</position>
    <title>Defining a globally-recognized method</title>
    <updated-at type="datetime">2009-02-19T02:30:40Z</updated-at>
  </example>
  <example>
    <content>The events.rb subsystem provides all events that the Asterisk [manager.conf](http://www.voip-info.org/tiki-index.php?page=Asterisk%20config%20manager.conf) specifies for that user. Therefore you may want to deal with only certain events to trigger various actions.

In the events.rb you may do something like this:

    # Ruby
    events.asterisk.manager_interface.each do |event|
      
      # I always downcase so I do not have to remember too much
      case event.name.downcase
      when &quot;newstate&quot;
        # If the call was answered 
        if event.headers[&quot;State&quot;] == &quot;Up&quot;
          # do something
        end
      when &quot;hangup&quot;
        # do something
      end

    end</content>
    <content-html>&lt;p&gt;The events.rb subsystem provides all events that the Asterisk &lt;a href=&quot;http://www.voip-info.org/tiki-index.php?page=Asterisk%20config%20manager.conf&quot;&gt;manager.conf&lt;/a&gt; specifies for that user. Therefore you may want to deal with only certain events to trigger various actions.&lt;/p&gt;

&lt;p&gt;In the events.rb you may do something like this:&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;events&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;asterisk&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;manager_interface&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;

  &lt;span class=&quot;comment&quot;&gt;# I always downcase so I do not have to remember too much&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;downcase&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;newstate&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;# If the call was answered &lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;[&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;State&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;]&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;Up&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
      &lt;span class=&quot;comment&quot;&gt;# do something&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;when&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;hangup&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;# do something&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:09:55Z</created-at>
    <example-section-id type="integer">4</example-section-id>
    <id type="integer">18</id>
    <position type="integer">11</position>
    <title>Handling a telephony platform event with a particular name</title>
    <updated-at type="datetime">2009-02-19T17:33:54Z</updated-at>
  </example>
  <example>
    <content>In your component, just register a callback for the ``:after_initialized`` namespace.

     # Ruby
    initialization do
      Events.register_callback :after_initialized do
        ahn_log &quot;Do stuff here!&quot;
      end
    end</content>
    <content-html>&lt;p&gt;In your component, just register a callback for the &lt;code&gt;:after_initialized&lt;/code&gt; namespace.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt; &lt;span class=&quot;ident&quot;&gt;initialization&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;constant&quot;&gt;Events&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;register_callback&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:after_initialized&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt;
    &lt;span class=&quot;ident&quot;&gt;ahn_log&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;Do stuff here!&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:10:15Z</created-at>
    <example-section-id type="integer">4</example-section-id>
    <id type="integer">19</id>
    <position type="integer">12</position>
    <title>Run code after Adhearsion fully initializes</title>
    <updated-at type="datetime">2009-02-19T05:00:50Z</updated-at>
  </example>
  <example>
    <content>Example component for Adhearsion showing a browser-based click to call application. Also shows how to use the RESTful API of Adhearsion.

You may access the component [here](http://github.com/jsgoecke/restful_clicktocall).</content>
    <content-html>&lt;p&gt;Example component for Adhearsion showing a browser-based click to call application. Also shows how to use the RESTful API of Adhearsion.&lt;/p&gt;

&lt;p&gt;You may access the component &lt;a href=&quot;http://github.com/jsgoecke/restful_clicktocall&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:11:58Z</created-at>
    <example-section-id type="integer">9</example-section-id>
    <id type="integer">23</id>
    <position type="integer">0</position>
    <title>Click to call</title>
    <updated-at type="datetime">2009-02-20T02:53:26Z</updated-at>
  </example>
  <example>
    <content>Below is a sample PHP class you can use to talk with the Adhearsion ``restful_rpc`` component. The ``restful_rpc`` component comes disabled by default in all newly-generated applications.
 
    &lt;?php
 
    // Define an Adhearsion PHP class for a REST HTTP connection
    class Adhearsion {
  
      public $url;
      public $username;
      public $password;
  
      function __construct($url, $username, $password) {
        $this-&gt;url = $url;
        $this-&gt;username = $username;
        $this-&gt;password = $password;
      }
  
      function invoke($method_name) {
        $json = json_encode(array_slice(func_get_args(), 1));
    
        $url = &quot;$this-&gt;url/$method_name&quot;;
        return json_decode(http_post_data($url,
                                          $json,
                                          array(&quot;httpauth&quot; =&gt; &quot;$this-&gt;username:$this-&gt;password&quot;)));
      }
  
    }

    // Connect to the REST API of Adhearsion
    $ahn = new Adhearsion(&quot;localhost:5000&quot;, &quot;jicksta&quot;, &quot;roflcopterz&quot;);

    //Build an array of the options for calling
    $call_options = array(array ('channel' =&gt; 'SIP/303',
                           'context' =&gt; 'inbound',
                           'exten' =&gt; '1000',
                           'priority' =&gt; '1',
                           'async' =&gt; 'true',
                           'variable' =&gt; 'destination=304');

    // Invoke the Adhearsion originate method via an HTTP POST of a JSON object
    $ahn-&gt;invoke(&quot;call_into_context&quot;, $call_options);
    ?&gt;

In this example, it does an &quot;origination&quot; to asynchronously call out to a SIP extension (103 in this case). When the callee answers, it will start executing the ``inbound`` Adhearsion context. In dialplan example below, we're extracting a variable set in the origination and using it to dial out again.

    # Ruby
    inbound {
      dial &quot;SIP/#{get_variable('destination')}&quot;
    }

</content>
    <content-html>&lt;p&gt;Below is a sample PHP class you can use to talk with the Adhearsion &lt;code&gt;restful_rpc&lt;/code&gt; component. The &lt;code&gt;restful_rpc&lt;/code&gt; component comes disabled by default in all newly-generated applications.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?php

// Define an Adhearsion PHP class for a REST HTTP connection
class Adhearsion {

  public $url;
  public $username;
  public $password;

  function __construct($url, $username, $password) {
    $this-&amp;gt;url = $url;
    $this-&amp;gt;username = $username;
    $this-&amp;gt;password = $password;
  }

  function invoke($method_name) {
    $json = json_encode(array_slice(func_get_args(), 1));

    $url = &quot;$this-&amp;gt;url/$method_name&quot;;
    return json_decode(http_post_data($url,
                                      $json,
                                      array(&quot;httpauth&quot; =&amp;gt; &quot;$this-&amp;gt;username:$this-&amp;gt;password&quot;)));
  }

}

// Connect to the REST API of Adhearsion
$ahn = new Adhearsion(&quot;localhost:5000&quot;, &quot;jicksta&quot;, &quot;roflcopterz&quot;);

//Build an array of the options for calling
$call_options = array(array ('channel' =&amp;gt; 'SIP/303',
                       'context' =&amp;gt; 'inbound',
                       'exten' =&amp;gt; '1000',
                       'priority' =&amp;gt; '1',
                       'async' =&amp;gt; 'true',
                       'variable' =&amp;gt; 'destination=304');

// Invoke the Adhearsion originate method via an HTTP POST of a JSON object
$ahn-&amp;gt;invoke(&quot;call_into_context&quot;, $call_options);
?&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;

&lt;p&gt;In this example, it does an &quot;origination&quot; to asynchronously call out to a SIP extension (103 in this case). When the callee answers, it will start executing the &lt;code&gt;inbound&lt;/code&gt; Adhearsion context. In dialplan example below, we're extracting a variable set in the origination and using it to dial out again.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;inbound&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;dial&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;SIP/&lt;span class=&quot;expr&quot;&gt;#{get_variable('destination')}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:12:46Z</created-at>
    <example-section-id type="integer">6</example-section-id>
    <id type="integer">24</id>
    <position type="integer">14</position>
    <title>Talking to your Adhearsion app from PHP</title>
    <updated-at type="datetime">2009-02-22T01:58:41Z</updated-at>
  </example>
  <example>
    <content>Adhearsion has a great RPC interface out of the box that may be accessed via [REST](http://en.wikipedia.org/wiki/Representational_State_Transfer). You may then access Adhearsion objects and methods from virtually any modern lanugage. In this case we will show Ruby consuming the web services (keep in mind Adhearsion uses [JSON](http://en.wikipedia.org/wiki/Json)): 

    # Ruby
    require 'json'
    require 'rest_client'
 
    # First we create the class that handles the connection
    class RESTfulAdhearsion
  
      DEFAULT_OPTIONS = {
        # Note: :user and :password are non-existent by default
        :host         =&gt; &quot;localhost&quot;,
        :port         =&gt; &quot;5000&quot;,
        :path_nesting =&gt; &quot;/&quot;
      }
  
      def initialize(options={})
        @options = DEFAULT_OPTIONS.merge options
    
        @path_nesting = @options.delete :path_nesting
        @host = @options.delete :host
        @port = @options.delete :port
    
        @url_beginning = &quot;http://#{@host}:#{@port}#{@path_nesting}&quot;
      end
  
      def method_missing(method_name, *args)
        JSON.parse RestClient::Resource.new(@url_beginning + method_name.to_s, @options).post(args.to_json)
      end
  
    end

    #Create our Adhearsion object connected to the RESTful API of Adhearsion
    Adhearsion = RESTfulAdhearsion.new(:host     =&gt; &quot;localhost&quot;,
                                       :port     =&gt; 5000,
                                       :user     =&gt; &quot;jicksta&quot;,
                                       :password =&gt; &quot;roflcopterz&quot;)

    # Then make a call to it to place a phone call
    Adhearsion.originate { :channel  =&gt; &quot;SIP/3000,
                           :context  =&gt; &quot;outbound&quot;,
                           :priority =&gt; &quot;1&quot;,
                           :exten    =&gt; &quot;1000&quot;,
                           :async    =&gt; &quot;true&quot; }</content>
    <content-html>&lt;p&gt;Adhearsion has a great RPC interface out of the box that may be accessed via &lt;a href=&quot;http://en.wikipedia.org/wiki/Representational_State_Transfer&quot;&gt;REST&lt;/a&gt;. You may then access Adhearsion objects and methods from virtually any modern lanugage. In this case we will show Ruby consuming the web services (keep in mind Adhearsion uses &lt;a href=&quot;http://en.wikipedia.org/wiki/Json&quot;&gt;JSON&lt;/a&gt;): &lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;rest_client&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# First we create the class that handles the connection&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;class &lt;/span&gt;&lt;span class=&quot;class&quot;&gt;RESTfulAdhearsion&lt;/span&gt;

  &lt;span class=&quot;constant&quot;&gt;DEFAULT_OPTIONS&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;# Note: :user and :password are non-existent by default&lt;/span&gt;
    &lt;span class=&quot;symbol&quot;&gt;:host&lt;/span&gt;         &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;localhost&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;,&lt;/span&gt;
    &lt;span class=&quot;symbol&quot;&gt;:port&lt;/span&gt;         &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;,&lt;/span&gt;
    &lt;span class=&quot;symbol&quot;&gt;:path_nesting&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;keyword&quot;&gt;def &lt;/span&gt;&lt;span class=&quot;method&quot;&gt;initialize&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;={})&lt;/span&gt;
    &lt;span class=&quot;attribute&quot;&gt;@options&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;DEFAULT_OPTIONS&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;merge&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;options&lt;/span&gt;

    &lt;span class=&quot;attribute&quot;&gt;@path_nesting&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;attribute&quot;&gt;@options&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:path_nesting&lt;/span&gt;
    &lt;span class=&quot;attribute&quot;&gt;@host&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;attribute&quot;&gt;@options&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:host&lt;/span&gt;
    &lt;span class=&quot;attribute&quot;&gt;@port&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;attribute&quot;&gt;@options&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:port&lt;/span&gt;

    &lt;span class=&quot;attribute&quot;&gt;@url_beginning&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;http://&lt;span class=&quot;expr&quot;&gt;#{@host}&lt;/span&gt;:&lt;span class=&quot;expr&quot;&gt;#{@port}#{@path_nesting}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

  &lt;span class=&quot;keyword&quot;&gt;def &lt;/span&gt;&lt;span class=&quot;method&quot;&gt;method_missing&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;method_name&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;parse&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;RestClient&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Resource&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;attribute&quot;&gt;@url_beginning&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;method_name&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;to_s&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;attribute&quot;&gt;@options&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;to_json&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;#Create our Adhearsion object connected to the RESTful API of Adhearsion&lt;/span&gt;
&lt;span class=&quot;constant&quot;&gt;Adhearsion&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;RESTfulAdhearsion&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;symbol&quot;&gt;:host&lt;/span&gt;     &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;localhost&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;,&lt;/span&gt;
                                   &lt;span class=&quot;symbol&quot;&gt;:port&lt;/span&gt;     &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;5000&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt;
                                   &lt;span class=&quot;symbol&quot;&gt;:user&lt;/span&gt;     &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;jicksta&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;,&lt;/span&gt;
                                   &lt;span class=&quot;symbol&quot;&gt;:password&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;roflcopterz&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;)&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Then make a call to it to place a phone call&lt;/span&gt;
&lt;span class=&quot;constant&quot;&gt;Adhearsion&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;originate&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;symbol&quot;&gt;:channel&lt;/span&gt;  &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;SIP/3000,
                       :context  =&amp;gt; &lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;outbound&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;,
                       :priority =&amp;gt; &lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;,
                       :exten    =&amp;gt; &lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;,
                       :async    =&amp;gt; &lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt; }&lt;span class=&quot;normal&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-16T06:16:45Z</created-at>
    <example-section-id type="integer">7</example-section-id>
    <id type="integer">26</id>
    <position type="integer">15</position>
    <title>Consuming RESTful resources</title>
    <updated-at type="datetime">2009-02-19T18:47:36Z</updated-at>
  </example>
  <example>
    <content>While Adhearsion provides an extensive set of methods to ``dialplan.rb`` files, there may be times you want to execute an Asterisk command (known as an &quot;application&quot; in Asterisk parlance) that has not been exposed by Adhearsion.

The [``execute``](http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#execute-instance_method) method accepts as its first argument the name of the Asterisk command followed by an arbitrarily long sequence of arguments.

    # Ruby
    execute &quot;DISA&quot;, 1234, &quot;disa_context&quot;

Voip-Info.org has an extensive list of the available Asterisk commands [here](http://www.voip-info.org/wiki-Asterisk+-+documentation+of+application+commands).

**Note:** Asterisk itself has no dialplan-level concept of arguments. The example above is equivalent to ``DISA(1234|disa_context)`` in ``extensions.conf``. When Asterisk runs the DISA command, it passes the arguments between the parenthesis as a **raw string** and it's up to the application to parse it. For this reason, you may need to pass a String as the second argument to ``execute`` to manually format a finicky command's arguments.</content>
    <content-html>&lt;p&gt;While Adhearsion provides an extensive set of methods to &lt;code&gt;dialplan.rb&lt;/code&gt; files, there may be times you want to execute an Asterisk command (known as an &quot;application&quot; in Asterisk parlance) that has not been exposed by Adhearsion.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;http://api.adhearsion.com/Adhearsion/VoIP/Asterisk/Commands.html#execute-instance_method&quot;&gt;&lt;code&gt;execute&lt;/code&gt;&lt;/a&gt; method accepts as its first argument the name of the Asterisk command followed by an arbitrarily long sequence of arguments.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;execute&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;DISA&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;,&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;1234&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;disa_context&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;Voip-Info.org has an extensive list of the available Asterisk commands &lt;a href=&quot;http://www.voip-info.org/wiki-Asterisk+-+documentation+of+application+commands&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Asterisk itself has no dialplan-level concept of arguments. The example above is equivalent to &lt;code&gt;DISA(1234|disa_context)&lt;/code&gt; in &lt;code&gt;extensions.conf&lt;/code&gt;. When Asterisk runs the DISA command, it passes the arguments between the parenthesis as a &lt;strong&gt;raw string&lt;/strong&gt; and it's up to the application to parse it. For this reason, you may need to pass a String as the second argument to &lt;code&gt;execute&lt;/code&gt; to manually format a finicky command's arguments.&lt;/p&gt;</content-html>
    <created-at type="datetime">2009-02-19T02:59:06Z</created-at>
    <example-section-id type="integer">1</example-section-id>
    <id type="integer">27</id>
    <position type="integer">16</position>
    <title>Executing arbitrary Asterisk commands</title>
    <updated-at type="datetime">2009-02-28T18:20:51Z</updated-at>
  </example>
  <example>
    <content>ActiveRecord is an [object-relational mapper (ORM)](http://en.wikipedia.org/wiki/Object-relational_mapping) for Ruby which makes persistent database data look exactly like Ruby objects. Because ActiveRecord handles all of the SQL for you, it will work on virtually *any* SQL server for which it has adapters.

If you are not using Rails, then you may still want to access a database with your own models, which is possible with Adhearsion. When building a model, you are simply creating a class that represents the table definition as the class (ie - the columns) while each row becomes an instantiated object of that class.

One thing to keep in mind is that ActiveRecord works with [conventions](http://mandhro.com/2006/06/16/designing-databases-with-activerecord-conventions/) so you will want to do some research on the best way to design your database (don't worry, AR may do legacy stuff too).

With this in mind, if you have two tables named 'customers' and 'orders' you may create their models as follows:

    # Ruby
    class Customer &lt; ActiveRecord::Base
    end

    class Order &lt; ActiveRecord::Base
    end

As long as you have followed conventions, that is it really. Then you may reference the table rows as follows:

    # Ruby
    customers = Customer.find(:all)
    customers.each do |customer|
      puts customer.first_name + &quot; &quot; + customer.last_name
    end</content>
    <content-html>&lt;p&gt;ActiveRecord is an &lt;a href=&quot;http://en.wikipedia.org/wiki/Object-relational_mapping&quot;&gt;object-relational mapper (ORM)&lt;/a&gt; for Ruby which makes persistent database data look exactly like Ruby objects. Because ActiveRecord handles all of the SQL for you, it will work on virtually &lt;em&gt;any&lt;/em&gt; SQL server for which it has adapters.&lt;/p&gt;

&lt;p&gt;If you are not using Rails, then you may still want to access a database with your own models, which is possible with Adhearsion. When building a model, you are simply creating a class that represents the table definition as the class (ie - the columns) while each row becomes an instantiated object of that class.&lt;/p&gt;

&lt;p&gt;One thing to keep in mind is that ActiveRecord works with &lt;a href=&quot;http://mandhro.com/2006/06/16/designing-databases-with-activerecord-conventions/&quot;&gt;conventions&lt;/a&gt; so you will want to do some research on the best way to design your database (don't worry, AR may do legacy stuff too).&lt;/p&gt;

&lt;p&gt;With this in mind, if you have two tables named 'customers' and 'orders' you may create their models as follows:&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;class &lt;/span&gt;&lt;span class=&quot;class&quot;&gt;Customer&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Base&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;class &lt;/span&gt;&lt;span class=&quot;class&quot;&gt;Order&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;ActiveRecord&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;constant&quot;&gt;Base&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;As long as you have followed conventions, that is it really. Then you may reference the table rows as follows:&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;customers&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;Customer&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;symbol&quot;&gt;:all&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;ident&quot;&gt;customers&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;customer&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;|&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;puts&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;customer&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;first_name&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt; &lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;customer&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;last_name&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-19T03:57:30Z</created-at>
    <example-section-id type="integer">2</example-section-id>
    <id type="integer">28</id>
    <position type="integer">0</position>
    <title>Writing an ActiveRecord &quot;model&quot;</title>
    <updated-at type="datetime">2009-02-19T17:21:05Z</updated-at>
  </example>
  <example>
    <content>JRuby has its own, separate gem repository and requires gems be installed using its own gem executable. If you have the normal Ruby interpreter installed on your system you would be accustomed to using the 'gem' command to install new gems. For JRuby you may simply use 'jgem'.

Adhearsion has a separate jahn executable with a shebang line of #!/usr/bin/env jruby. If your jruby is available in your path, you can simply execute jahn directly as you would the ahn command.

    jahn start /path/to/my/app</content>
    <content-html>&lt;p&gt;JRuby has its own, separate gem repository and requires gems be installed using its own gem executable. If you have the normal Ruby interpreter installed on your system you would be accustomed to using the 'gem' command to install new gems. For JRuby you may simply use 'jgem'.&lt;/p&gt;

&lt;p&gt;Adhearsion has a separate jahn executable with a shebang line of #!/usr/bin/env jruby. If your jruby is available in your path, you can simply execute jahn directly as you would the ahn command.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;jahn start /path/to/my/app
&lt;/code&gt;&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-02-19T04:07:13Z</created-at>
    <example-section-id type="integer">8</example-section-id>
    <id type="integer">29</id>
    <position type="integer">18</position>
    <title>Starting Adhearsion with JRuby</title>
    <updated-at type="datetime">2009-02-19T04:36:40Z</updated-at>
  </example>
  <example>
    <content>Provides an example Adhearsion component that exposes the Ann Arbor, MI parking lot space availability via an IVR. This example was inspired by the folks @ VoIP Tech Chat and their Perl example.

You may download the component [here](http://jsgoecke.github.com/annarbor_parking/).</content>
    <content-html>&lt;p&gt;Provides an example Adhearsion component that exposes the Ann Arbor, MI parking lot space availability via an IVR. This example was inspired by the folks @ VoIP Tech Chat and their Perl example.&lt;/p&gt;

&lt;p&gt;You may download the component &lt;a href=&quot;http://jsgoecke.github.com/annarbor_parking/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</content-html>
    <created-at type="datetime">2009-02-19T18:24:02Z</created-at>
    <example-section-id type="integer">9</example-section-id>
    <id type="integer">31</id>
    <position type="integer">2</position>
    <title>Web scraping - Ann Arbor Parking</title>
    <updated-at type="datetime">2009-02-20T02:53:26Z</updated-at>
  </example>
  <example>
    <content>The Hammer is used to generate live inbound call load on an Asterisk or any other telephony system. The Hammer also provides a facility to play DTMF tones at the beginning of a call in order to traverse an IVR menu and reach various inbound call routes. The intent is use this facility in both engineering QA as well as a tool for operations in the field to load test each and every Asterisk or voice platform implementation. 

You may download the component [here](http://github.com/jsgoecke/hammer).</content>
    <content-html>&lt;p&gt;The Hammer is used to generate live inbound call load on an Asterisk or any other telephony system. The Hammer also provides a facility to play DTMF tones at the beginning of a call in order to traverse an IVR menu and reach various inbound call routes. The intent is use this facility in both engineering QA as well as a tool for operations in the field to load test each and every Asterisk or voice platform implementation. &lt;/p&gt;

&lt;p&gt;You may download the component &lt;a href=&quot;http://github.com/jsgoecke/hammer&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</content-html>
    <created-at type="datetime">2009-02-19T18:26:50Z</created-at>
    <example-section-id type="integer">9</example-section-id>
    <id type="integer">33</id>
    <position type="integer">1</position>
    <title>An Adhearsion Stress Tester</title>
    <updated-at type="datetime">2009-02-20T02:53:26Z</updated-at>
  </example>
  <example>
    <content>Provides an example Adhearsion component that conducts call surveys. The component also provides a Rails GUI.

You may download the component [here](http://jsgoecke.github.com/surveys/).</content>
    <content-html>&lt;p&gt;Provides an example Adhearsion component that conducts call surveys. The component also provides a Rails GUI.&lt;/p&gt;

&lt;p&gt;You may download the component &lt;a href=&quot;http://jsgoecke.github.com/surveys/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;</content-html>
    <created-at type="datetime">2009-02-19T18:27:30Z</created-at>
    <example-section-id type="integer">9</example-section-id>
    <id type="integer">34</id>
    <position type="integer">3</position>
    <title>Phone Surveys</title>
    <updated-at type="datetime">2009-02-20T02:53:23Z</updated-at>
  </example>
  <example>
    <content>Example consuming the [Yahoo Query Language](http://developer.yahoo.com/yql/). The dialplan below will ask the user for their zipcode, fetch the weather based on zipcode and then play the temperature back to the user.

    # Ruby
    sandbox {

      play 'welcome'

      response = input 5,
                 :play    =&gt; ['please-enter-your', 'zip-code'],
                 :timeout =&gt; 10,
                 :retries =&gt; 3

      yahoo_url = 'http://query.yahooapis.com/v1/public/yql?format=json&amp;amp;q='
      query = &quot;SELECT * FROM weather.forecast WHERE location = &quot; + response

      url = URI.encode(yahoo_url + query)

      json_data = open(url).read
      weather_data = JSON.parse json_data
  
      play 'temperature', weather_data[&quot;query&quot;][&quot;results&quot;][&quot;channel&quot;][&quot;item&quot;][&quot;condition&quot;][&quot;temp&quot;]

    }</content>
    <content-html>&lt;p&gt;Example consuming the &lt;a href=&quot;http://developer.yahoo.com/yql/&quot;&gt;Yahoo Query Language&lt;/a&gt;. The dialplan below will ask the user for their zipcode, fetch the weather based on zipcode and then play the temperature back to the user.&lt;/p&gt;

&lt;pre class=&quot;syntax-ruby&quot;&gt;&lt;span class=&quot;ident&quot;&gt;sandbox&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;welcome&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;

  &lt;span class=&quot;ident&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;symbol&quot;&gt;:play&lt;/span&gt;    &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;['&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;please-enter-your&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;zip-code&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'],&lt;/span&gt;
             &lt;span class=&quot;symbol&quot;&gt;:timeout&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;symbol&quot;&gt;:retries&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;3&lt;/span&gt;

  &lt;span class=&quot;ident&quot;&gt;yahoo_url&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;http://query.yahooapis.com/v1/public/yql?format=json&amp;amp;q=&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;query&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;SELECT * FROM weather.forecast WHERE location = &lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;response&lt;/span&gt;

  &lt;span class=&quot;ident&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;URI&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;encode&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;yahoo_url&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;ident&quot;&gt;json_data&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;read&lt;/span&gt;
  &lt;span class=&quot;ident&quot;&gt;weather_data&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;ident&quot;&gt;parse&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;json_data&lt;/span&gt;

  &lt;span class=&quot;ident&quot;&gt;play&lt;/span&gt; &lt;span class=&quot;punct&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;',&lt;/span&gt; &lt;span class=&quot;ident&quot;&gt;weather_data&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;[&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;][&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;][&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;][&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;][&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;condition&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;][&quot;&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;temp&lt;/span&gt;&lt;span class=&quot;punct&quot;&gt;&quot;]&lt;/span&gt;

&lt;span class=&quot;punct&quot;&gt;}&lt;/span&gt;
&lt;/pre&gt;</content-html>
    <created-at type="datetime">2009-03-05T01:43:04Z</created-at>
    <example-section-id type="integer">7</example-section-id>
    <id type="integer">36</id>
    <position type="integer">19</position>
    <title>Consuming the Yahoo Query Language</title>
    <updated-at type="datetime">2009-03-05T02:07:15Z</updated-at>
  </example>
</examples>
