=begin THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =end =begin Depending on your ruby install, you might have to run the following commands. gem install rake gem install json_pure =end require 'rubygems' require 'json' require 'net/http' require 'uri' def getJsonResponse(u) u = URI.parse(u) puts u data = Net::HTTP.get(u) puts data return JSON.parse(data) end username = "" apiKey = "" botID = "" type = "Api" method = "" outputType = "Json" baseUrl = "http://api.udefn.com/apigateway.ashx?username=#{username}&apiKey=#{apiKey}&outputType=#{outputType}" while true method = "GetIncomingMessages" url = baseUrl+"&type=#{type}&method=#{method}" result = getJsonResponse(url) if result["Result"] != nil result["Result"].each { |mo| if mo["MO_BotID"] == botID method = "SendOutgoingMessage" moOutgoingID = mo["MO_MOOutgoingID"] body = mo["MO_Body"] url = baseUrl+"&type=#{type}&method=#{method}&mooutgoingid=#{moOutgoingID}&body=#{body}" getJsonResponse(url) end } end sleep(5) end