xiaohuangji 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
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
- puts Xiaohuangji.chat('I love you')
9
- puts Xiaohuangji.chat('I hate you')
8
+ Xiaohuangji.chat('I love you')
9
+ Xiaohuangji.chat('I hate you')
10
10
  ```
11
11
 
12
12
  Try it ^_^
@@ -7,24 +7,24 @@ require 'json'
7
7
  module Xiaohuangji
8
8
  class SimiSimi
9
9
  def initialize
10
- h = open 'http://www.simsimi.com/talk.htm'
11
- self.chat_cookie = h.meta['set-cookie'].split('; ', 2)[0]
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
- if msg
17
- h = open(URI.encode(chat_url % msg),
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 = h.meta['set-cookie'].split('; ', 2)[0]
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
- res.has_key?('response') ? res['response'] : 'Hehe'
26
+ res = JSON.parse f.read
27
+ res.has_key?('response') ? res['response'] : 'En?'
28
28
  else
29
29
  'En?'
30
30
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'xiaohuangji'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.authors = ['ZHANG Hailong']
5
5
  s.date = '2013-01-10'
6
6
  s.summary = 'A chatting robot based on SimiSimi.'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xiaohuangji
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: