Module: Pandorabots

Defined in:
lib/pandorabots.rb

Constant Summary collapse

VERSION =
"0.0.1"
PANDORABOTS_URL =
"http://www.pandorabots.com/pandora/talk-xml"

Class Method Summary collapse

Class Method Details

.talk(bot_id, input, cust_id = nil) ⇒ Object

talk to a pandora bot



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pandorabots.rb', line 10

def self.talk(bot_id, input, cust_id=nil)
  uri = URI.parse(PANDORABOTS_URL)
  params = {"botid" => bot_id, "input" => input}
  if cust_id
    params['custid'] = cust_id
  end
  response = Net::HTTP.post_form(uri, params)
  
  if (response && response.code.to_i >= 200 && response.code.to_i < 300)
    hash =  XmlSimple.xml_in(response.body)
    if hash["status"].to_i == 0
      result = {
        :success => true,
        :bot_id => hash["botid"], 
        :cust_id => hash["custid"], 
        :input => hash["input"][0], 
        :output => hash["that"][0]}
      return result
    else
      result = {
         :success => false,
         :bot_id => hash["botid"], 
         :cust_id => hash["custid"], 
         :input => hash["input"][0], 
         :output => hash["message"][0]}   
      return result
    end
  else
    p response.body
    return nil
  end
end