xiaohuangji 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -2
- data/lib/xiaohuangji/simisimi.rb +8 -8
- data/xiaohuangji.gemspec +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -5,8 +5,8 @@ Based on [SimiSimi](http://www.simsimi.com/talk.htm?lc=zh).
|
|
5
5
|
|
6
6
|
```ruby
|
7
7
|
require 'xiaohuangji'
|
8
|
-
|
9
|
-
|
8
|
+
Xiaohuangji.chat('I love you')
|
9
|
+
Xiaohuangji.chat('I hate you')
|
10
10
|
```
|
11
11
|
|
12
12
|
Try it ^_^
|
data/lib/xiaohuangji/simisimi.rb
CHANGED
@@ -7,24 +7,24 @@ require 'json'
|
|
7
7
|
module Xiaohuangji
|
8
8
|
class SimiSimi
|
9
9
|
def initialize
|
10
|
-
|
11
|
-
self.chat_cookie =
|
10
|
+
f = open 'http://www.simsimi.com/talk.htm'
|
11
|
+
self.chat_cookie = f.meta['set-cookie'].split('; ', 2)[0]
|
12
12
|
self.chat_url = 'http://www.simsimi.com/func/req?lc=ch&msg=%s'
|
13
13
|
end
|
14
14
|
|
15
|
-
def chat(msg
|
16
|
-
|
17
|
-
|
15
|
+
def chat(msg)
|
16
|
+
unless msg.nil?
|
17
|
+
f = open(URI.encode(chat_url % msg),
|
18
18
|
'Referer' => 'http://www.simsimi.com/talk.htm',
|
19
19
|
'Cookie' => chat_cookie)
|
20
|
-
res = JSON.parse h.read
|
21
20
|
begin
|
22
|
-
cookie =
|
21
|
+
cookie = f.meta['set-cookie'].split('; ', 2)[0]
|
23
22
|
self.chat_cookie = cookie
|
24
23
|
rescue Exception => e
|
25
24
|
$stderr.puts e
|
26
25
|
end
|
27
|
-
|
26
|
+
res = JSON.parse f.read
|
27
|
+
res.has_key?('response') ? res['response'] : 'En?'
|
28
28
|
else
|
29
29
|
'En?'
|
30
30
|
end
|
data/xiaohuangji.gemspec
CHANGED