xiaohuangji 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,12 @@
1
+ My 小黃雞
2
+ ==============
3
+
4
+ Based on [SimiSimi](http://www.simsimi.com/talk.htm?lc=zh).
5
+
6
+ ```ruby
7
+ require 'xiaohuangji'
8
+ puts Xiaohuangji.chat('I love you')
9
+ puts Xiaohuangji.chat('I hate you')
10
+ ```
11
+
12
+ Try it ^_^
@@ -0,0 +1,50 @@
1
+ #encoding: utf-8
2
+ #Copyright (c) 2013 zhhailon <zhhailon@gmail.com>
3
+
4
+ require 'open-uri'
5
+ require 'json'
6
+
7
+ module Xiaohuangji
8
+ class SimiSimi
9
+ def initialize
10
+ h = open 'http://www.simsimi.com/talk.htm'
11
+ self.chat_cookie = h.meta['set-cookie'].split('; ', 2)[0]
12
+ self.chat_url = 'http://www.simsimi.com/func/req?lc=ch&msg=%s'
13
+ end
14
+
15
+ def chat(msg='')
16
+ if msg
17
+ h = open(URI.encode(chat_url % msg),
18
+ 'Referer' => 'http://www.simsimi.com/talk.htm',
19
+ 'Cookie' => chat_cookie)
20
+ res = JSON.parse h.read
21
+ begin
22
+ cookie = h.meta['set-cookie'].split('; ', 2)[0]
23
+ self.chat_cookie = cookie
24
+ rescue Exception => e
25
+ $stderr.puts e
26
+ end
27
+ res.has_key?('response') ? res['response'] : 'Hehe'
28
+ else
29
+ 'En?'
30
+ end
31
+ end
32
+
33
+ private
34
+ def chat_cookie
35
+ @chat_cookie
36
+ end
37
+
38
+ def chat_cookie=(cookie={})
39
+ @chat_cookie = cookie
40
+ end
41
+
42
+ def chat_url
43
+ @chat_url
44
+ end
45
+
46
+ def chat_url=(url='')
47
+ @chat_url = url
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,10 @@
1
+ #encoding: utf-8
2
+ #Copyright (c) 2013 zhhailon <zhhailon@gmail.com>
3
+
4
+ require 'xiaohuangji/simisimi'
5
+
6
+ module Xiaohuangji
7
+ def self.chat(msg='')
8
+ SimiSimi.new.chat msg
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'xiaohuangji'
3
+ s.version = '0.0.1'
4
+ s.authors = ['ZHANG Hailong']
5
+ s.date = '2013-01-10'
6
+ s.summary = 'A chatting robot based on SimiSimi.'
7
+ s.description = 'Xiaohuangji is a chatting robot based on SimiSimi.'
8
+ s.email = 'zhhailon@gmail.com'
9
+ s.homepage = 'https://github.com/zhhailon/my-xiaohuangji'
10
+ s.files = [
11
+ 'xiaohuangji.gemspec',
12
+ 'README.md',
13
+ 'lib/xiaohuangji.rb',
14
+ 'lib/xiaohuangji/simisimi.rb'
15
+ ]
16
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xiaohuangji
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - ZHANG Hailong
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Xiaohuangji is a chatting robot based on SimiSimi.
15
+ email: zhhailon@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - xiaohuangji.gemspec
21
+ - README.md
22
+ - lib/xiaohuangji.rb
23
+ - lib/xiaohuangji/simisimi.rb
24
+ homepage: https://github.com/zhhailon/my-xiaohuangji
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.23
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: A chatting robot based on SimiSimi.
48
+ test_files: []