Class: Xiaohuangji::SimSimi

Inherits:
Object
  • Object
show all
Defined in:
lib/xiaohuangji/simsimi.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSimSimi

Returns a new instance of SimSimi.



10
11
12
# File 'lib/xiaohuangji/simsimi.rb', line 10

def initialize
  self.chat_url = 'http://www.simsimi.com/requestChat?lc=ch&ft=1.0&req=%s'
end

Instance Attribute Details

#chat_urlObject

Returns the value of attribute chat_url.



9
10
11
# File 'lib/xiaohuangji/simsimi.rb', line 9

def chat_url
  @chat_url
end

Instance Method Details

#chat(msg) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/xiaohuangji/simsimi.rb', line 14

def chat(msg)
  if !msg.nil? && !msg.empty?
    ans = ''
    open(URI.encode(chat_url % msg)) do |f|
      res = JSON.parse f.read
      ans = res['res']
    end
    ans
  else
    '?'
  end
end