wei-backend 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/Gemfile +1 -4
- data/Gemfile.lock +25 -48
- data/README.md +2 -4
- data/lib/wei-backend/base.rb +17 -1
- data/lib/wei-backend/wei-templates/music.haml +12 -0
- data/scripts/publish.sh +18 -0
- data/wei-backend.gemspec +3 -3
- metadata +8 -31
- data/examples/locations/Gemfile +0 -16
- data/examples/locations/Gemfile.lock +0 -93
- data/examples/locations/app.rb +0 -17
- data/examples/locations/config.ru +0 -12
- data/examples/waiting_bus/Gemfile +0 -22
- data/examples/waiting_bus/Gemfile.lock +0 -93
- data/examples/waiting_bus/Rakefile +0 -23
- data/examples/waiting_bus/ai_bang_client.rb +0 -17
- data/examples/waiting_bus/app.rb +0 -25
- data/examples/waiting_bus/bus_helper.rb +0 -19
- data/examples/waiting_bus/config.ru +0 -12
- data/examples/waiting_bus/config/development.yml +0 -7
- data/examples/waiting_bus/config/production.yml +0 -7
- data/examples/waiting_bus/config/test.yml +0 -7
- data/examples/waiting_bus/spec/ai_bang_client_spec.rb +0 -22
- data/examples/waiting_bus/spec/bus_helper_spec.rb +0 -19
- data/examples/waiting_bus/spec/fixtures/bus_lines_response.json +0 -44
- data/lib/wei-backend/version.rb +0 -3
- data/spec/spec_helper.rb +0 -48
- data/spec/wei_backend_spec.rb +0 -84
- data/spec/wei_backend_utils_spec.rb +0 -7
- data/spec/weixin_message_handler_spec.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NmIyMTA4ZWNhZjkzM2RiMTMxYTJiZmQ5MmQ2OTRhMGUwNzI4OThiNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZGYwZGEzNzdhMWZjMTBlNTEzMTZjODE2MWI4Njg3Y2NkM2JmYjRmMg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
N2I3N2QzMDlhMDM2ZTIyNjg3MjFlZTQzOGUzNDg3YzFhM2ZkMDM5MmU5YmY0
|
10
|
+
ODFkYzFkZjJjYmE5NDY3Yjg5YWU4ODg1MTNmOGQ4ZGEyYTU3YmUxNGIxMTM3
|
11
|
+
Mjg0ZjA3NWQyN2ViMTJiY2MzZDY3MTJiYTYwNTM2MjcxNzhiNDY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NWJlMzdhZmU0N2E2NTMzNTY5OGM5M2IwNDBkMmU5MGE0MWZkNWNlYzkwZDI0
|
14
|
+
ZWFlYmNhZTNmNzdlMDFkMzVkNTBjYzNkNGQ2MzI0NzQ3NGYxZDY5MjM5YWVm
|
15
|
+
YzNmNjMwOGU5NTI2OTljMDMwZjgzNTJlYzY2YTYwODYzZDQ4YmI=
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,90 +1,67 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
celluloid (0.15.2)
|
5
|
+
timers (~> 1.1.0)
|
6
|
+
celluloid-io (0.15.0)
|
7
|
+
celluloid (>= 0.15.0)
|
8
|
+
nio4r (>= 0.5.0)
|
9
9
|
diff-lcs (1.2.5)
|
10
|
-
eventmachine (1.0.3)
|
11
10
|
ffi (1.9.3)
|
12
|
-
haml (4.0.
|
11
|
+
haml (4.0.5)
|
13
12
|
tilt
|
14
|
-
hash_validator (0.2.7)
|
15
|
-
httparty (0.12.0)
|
16
|
-
json (~> 1.8)
|
17
|
-
multi_xml (>= 0.5.2)
|
18
|
-
i18n (0.6.5)
|
19
13
|
json (1.8.1)
|
20
|
-
listen (
|
14
|
+
listen (2.7.1)
|
15
|
+
celluloid (>= 0.15.2)
|
16
|
+
celluloid-io (>= 0.15.0)
|
21
17
|
rb-fsevent (>= 0.9.3)
|
22
18
|
rb-inotify (>= 0.9)
|
23
|
-
rb-kqueue (>= 0.2)
|
24
19
|
mini_portile (0.5.2)
|
25
|
-
|
26
|
-
|
27
|
-
net-ssh (>= 2.6.5)
|
28
|
-
net-ssh (2.7.0)
|
29
|
-
nokogiri (1.6.0)
|
20
|
+
nio4r (1.0.0)
|
21
|
+
nokogiri (1.6.1)
|
30
22
|
mini_portile (~> 0.5.0)
|
31
23
|
rack (1.5.2)
|
32
|
-
rack-protection (1.5.
|
24
|
+
rack-protection (1.5.2)
|
33
25
|
rack
|
34
26
|
rack-test (0.6.2)
|
35
27
|
rack (>= 1.0)
|
36
|
-
rake (10.1.
|
37
|
-
rb-fsevent (0.9.
|
38
|
-
rb-inotify (0.9.
|
28
|
+
rake (10.1.1)
|
29
|
+
rb-fsevent (0.9.4)
|
30
|
+
rb-inotify (0.9.3)
|
39
31
|
ffi (>= 0.5.0)
|
40
|
-
|
41
|
-
|
42
|
-
rerun (0.8.2)
|
43
|
-
listen (~> 1.0.3)
|
32
|
+
rerun (0.9.0)
|
33
|
+
listen (~> 2.7)
|
44
34
|
rspec (2.14.1)
|
45
35
|
rspec-core (~> 2.14.0)
|
46
36
|
rspec-expectations (~> 2.14.0)
|
47
37
|
rspec-mocks (~> 2.14.0)
|
48
|
-
rspec-core (2.14.
|
49
|
-
rspec-expectations (2.14.
|
38
|
+
rspec-core (2.14.8)
|
39
|
+
rspec-expectations (2.14.5)
|
50
40
|
diff-lcs (>= 1.1.3, < 2.0)
|
51
|
-
rspec-html-matchers (0.
|
52
|
-
nokogiri (
|
53
|
-
rspec (>= 2.
|
54
|
-
rspec-mocks (2.14.
|
41
|
+
rspec-html-matchers (0.5.0)
|
42
|
+
nokogiri (~> 1)
|
43
|
+
rspec (~> 2, >= 2.11.0)
|
44
|
+
rspec-mocks (2.14.6)
|
55
45
|
shotgun (0.9)
|
56
46
|
rack (>= 1.0)
|
57
47
|
sinatra (1.4.4)
|
58
48
|
rack (~> 1.4)
|
59
49
|
rack-protection (~> 1.4)
|
60
50
|
tilt (~> 1.3, >= 1.3.4)
|
61
|
-
sshkit (1.2.0)
|
62
|
-
net-scp (>= 1.1.2)
|
63
|
-
net-ssh
|
64
|
-
term-ansicolor
|
65
|
-
term-ansicolor (1.2.2)
|
66
|
-
tins (~> 0.8)
|
67
|
-
thin (1.6.1)
|
68
|
-
daemons (>= 1.0.9)
|
69
|
-
eventmachine (>= 1.0.0)
|
70
|
-
rack (>= 1.0.0)
|
71
51
|
tilt (1.4.1)
|
72
|
-
|
52
|
+
timers (1.1.0)
|
73
53
|
|
74
54
|
PLATFORMS
|
75
55
|
ruby
|
76
56
|
|
77
57
|
DEPENDENCIES
|
78
|
-
capistrano
|
79
58
|
haml
|
80
|
-
hash_validator
|
81
|
-
httparty
|
82
59
|
json
|
83
60
|
nokogiri
|
84
61
|
rack-test
|
62
|
+
rake
|
85
63
|
rerun
|
86
64
|
rspec
|
87
65
|
rspec-html-matchers
|
88
66
|
shotgun
|
89
67
|
sinatra
|
90
|
-
thin
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ export TIMESTAMP=1388674716
|
|
40
40
|
export NONCE=1388564676
|
41
41
|
export TOKEN=mytoken
|
42
42
|
export SIGNATURE=$(ruby -e 'require "digest/sha1"; puts Digest::SHA1.hexdigest [ENV["TIMESTAMP"], ENV["NONCE"], ENV["TOKEN"]].sort!.join')
|
43
|
-
curl -H 'Content-type:text/xml' -d@- localhost:4567/weixin?signature=$SIGNATURE×tamp=$TIMESTAMP&nonce=$NONCE << EOF
|
43
|
+
curl -H 'Content-type:text/xml' -d@- "localhost:4567/weixin?signature=$SIGNATURE×tamp=$TIMESTAMP&nonce=$NONCE" << EOF
|
44
44
|
<xml>
|
45
45
|
<ToUserName><![CDATA[toUser]]></ToUserName>
|
46
46
|
<FromUserName><![CDATA[fromUser]]></FromUserName>
|
@@ -50,7 +50,6 @@ curl -H 'Content-type:text/xml' -d@- localhost:4567/weixin?signature=$SIGNATURE&
|
|
50
50
|
<MsgId>1234567890123456</MsgId>
|
51
51
|
</xml>
|
52
52
|
EOF
|
53
|
-
|
54
53
|
```
|
55
54
|
|
56
55
|
将会得到一段xml返回值,表示一切OK:
|
@@ -61,9 +60,8 @@ EOF
|
|
61
60
|
<FromUserName><![CDATA[toUser]]></FromUserName>
|
62
61
|
<CreateTime><![CDATA[1386522760]]></CreateTime>
|
63
62
|
<MsgType><![CDATA[text]]></MsgType>
|
64
|
-
<Content><![CDATA[你发送了如下内容: This is a text message]]></Content>
|
63
|
+
<Content><![CDATA[你发送了如下内容: This is a text message!!]]></Content>
|
65
64
|
</xml>
|
66
|
-
|
67
65
|
```
|
68
66
|
|
69
67
|
## 与微信接口兼容情况:
|
data/lib/wei-backend/base.rb
CHANGED
@@ -14,13 +14,29 @@ module WeiBackend
|
|
14
14
|
|
15
15
|
def create_model data
|
16
16
|
case data
|
17
|
-
when
|
17
|
+
when Array
|
18
18
|
image_text_message(data)
|
19
|
+
when Hash
|
20
|
+
if !data[:url].nil?
|
21
|
+
image_text_message(data)
|
22
|
+
elsif !data[:music_url].nil?
|
23
|
+
music_message(data)
|
24
|
+
end
|
19
25
|
else
|
20
26
|
text_message(data)
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
30
|
+
def music_message(model)
|
31
|
+
{
|
32
|
+
:format => 'music',
|
33
|
+
:model => {
|
34
|
+
:music => model
|
35
|
+
}.merge(account_info)
|
36
|
+
}
|
37
|
+
|
38
|
+
end
|
39
|
+
|
24
40
|
def text_message(data)
|
25
41
|
{
|
26
42
|
:format => 'text',
|
@@ -0,0 +1,12 @@
|
|
1
|
+
%xml
|
2
|
+
%ToUserName= cdata userAccount
|
3
|
+
%FromUserName= cdata myAccount
|
4
|
+
%CreateTime= cdata Time.now.to_i
|
5
|
+
%MsgType= cdata 'music'
|
6
|
+
%Music
|
7
|
+
%Title= cdata music[:title]
|
8
|
+
%Description= cdata music[:description]
|
9
|
+
%MusicUrl= cdata music[:music_url]
|
10
|
+
%HQMusicUrl= cdata music[:hq_music_url]
|
11
|
+
%FuncFlag
|
12
|
+
='0'
|
data/scripts/publish.sh
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
git tag
|
3
|
+
REPO_VERSION=`git tag | tail -1`
|
4
|
+
echo "Development version: $REPO_VERSION"
|
5
|
+
SEARCH_RESULTS=`gem search --remote wei-backend`
|
6
|
+
echo $SEARCH_RESULTS
|
7
|
+
CURRENT_VERSION=`echo $SEARCH_RESULTS | tail -1 | sed -n 's/wei-backend (\(.*\).*)/\1/p'`
|
8
|
+
echo "Production version: $CURRENT_VERSION"
|
9
|
+
if [ "$REPO_VERSION" != "$CURRENT_VERSION" ]; then
|
10
|
+
echo "---" > ~/.gem/credentials
|
11
|
+
echo ":rubygems_api_key: $API_KEY" >> ~/.gem/credentials
|
12
|
+
gem build wei-backend.gemspec
|
13
|
+
chmod 0600 ~/.gem/credentials
|
14
|
+
echo "pushing: wei-backend-$REPO_VERSION.gem"
|
15
|
+
gem push wei-backend-$REPO_VERSION.gem
|
16
|
+
else
|
17
|
+
echo "Do not need publish new version"
|
18
|
+
fi
|
data/wei-backend.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
2
|
-
require 'wei-backend/version'
|
3
2
|
|
4
|
-
Gem::Specification.new 'wei-backend'
|
3
|
+
Gem::Specification.new 'wei-backend' do |s|
|
5
4
|
s.description = 'wei-backend is a DSL for quickly creating weixin open platform backend system.'
|
6
5
|
s.summary = 'Best DSL for weixin development'
|
7
6
|
s.authors = ['Wang Chao']
|
8
7
|
s.email = 'cwang8023@gmail.com'
|
9
8
|
s.homepage = 'https://github.com/charleyw/weixin-sinatra'
|
10
9
|
s.license = 'MIT'
|
11
|
-
s.files = `git ls-files`.split("\n") - %w[.gitignore .travis.yml .ruby-version .ruby-gemset]
|
10
|
+
s.files = `git ls-files`.split("\n") - %w[.gitignore .travis.yml .ruby-version .ruby-gemset] - Dir['examples/**/*','spec/**/*']
|
12
11
|
s.test_files = s.files.select { |p| p =~ /^spec\/.*_spec.rb/ }
|
12
|
+
s.version = `git tag | tail -1`
|
13
13
|
|
14
14
|
s.add_dependency 'sinatra', '~> 1.4.4'
|
15
15
|
s.add_dependency 'nokogiri', '~> 1.6.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wei-backend
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wang Chao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -77,34 +77,14 @@ files:
|
|
77
77
|
- Gemfile.lock
|
78
78
|
- README.md
|
79
79
|
- Rakefile
|
80
|
-
- examples/locations/Gemfile
|
81
|
-
- examples/locations/Gemfile.lock
|
82
|
-
- examples/locations/app.rb
|
83
|
-
- examples/locations/config.ru
|
84
|
-
- examples/waiting_bus/Gemfile
|
85
|
-
- examples/waiting_bus/Gemfile.lock
|
86
|
-
- examples/waiting_bus/Rakefile
|
87
|
-
- examples/waiting_bus/ai_bang_client.rb
|
88
|
-
- examples/waiting_bus/app.rb
|
89
|
-
- examples/waiting_bus/bus_helper.rb
|
90
|
-
- examples/waiting_bus/config.ru
|
91
|
-
- examples/waiting_bus/config/development.yml
|
92
|
-
- examples/waiting_bus/config/production.yml
|
93
|
-
- examples/waiting_bus/config/test.yml
|
94
|
-
- examples/waiting_bus/spec/ai_bang_client_spec.rb
|
95
|
-
- examples/waiting_bus/spec/bus_helper_spec.rb
|
96
|
-
- examples/waiting_bus/spec/fixtures/bus_lines_response.json
|
97
80
|
- lib/wei-backend.rb
|
98
81
|
- lib/wei-backend/base.rb
|
99
82
|
- lib/wei-backend/main.rb
|
100
83
|
- lib/wei-backend/utils.rb
|
101
|
-
- lib/wei-backend/version.rb
|
102
84
|
- lib/wei-backend/wei-templates/image_text.haml
|
85
|
+
- lib/wei-backend/wei-templates/music.haml
|
103
86
|
- lib/wei-backend/wei-templates/text.haml
|
104
|
-
-
|
105
|
-
- spec/wei_backend_spec.rb
|
106
|
-
- spec/wei_backend_utils_spec.rb
|
107
|
-
- spec/weixin_message_handler_spec.rb
|
87
|
+
- scripts/publish.sh
|
108
88
|
- wei-backend.gemspec
|
109
89
|
homepage: https://github.com/charleyw/weixin-sinatra
|
110
90
|
licenses:
|
@@ -116,21 +96,18 @@ require_paths:
|
|
116
96
|
- lib
|
117
97
|
required_ruby_version: !ruby/object:Gem::Requirement
|
118
98
|
requirements:
|
119
|
-
- - '>='
|
99
|
+
- - ! '>='
|
120
100
|
- !ruby/object:Gem::Version
|
121
101
|
version: '0'
|
122
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
103
|
requirements:
|
124
|
-
- - '>='
|
104
|
+
- - ! '>='
|
125
105
|
- !ruby/object:Gem::Version
|
126
106
|
version: '0'
|
127
107
|
requirements: []
|
128
108
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.2.2
|
130
110
|
signing_key:
|
131
111
|
specification_version: 4
|
132
112
|
summary: Best DSL for weixin development
|
133
|
-
test_files:
|
134
|
-
- spec/wei_backend_spec.rb
|
135
|
-
- spec/wei_backend_utils_spec.rb
|
136
|
-
- spec/weixin_message_handler_spec.rb
|
113
|
+
test_files: []
|
data/examples/locations/Gemfile
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
capistrano (3.0.1)
|
5
|
-
i18n
|
6
|
-
rake (>= 10.0.0)
|
7
|
-
sshkit (>= 0.0.23)
|
8
|
-
daemons (1.1.9)
|
9
|
-
diff-lcs (1.2.5)
|
10
|
-
eventmachine (1.0.3)
|
11
|
-
ffi (1.9.3)
|
12
|
-
haml (4.0.4)
|
13
|
-
tilt
|
14
|
-
hash_validator (0.2.7)
|
15
|
-
httparty (0.12.0)
|
16
|
-
json (~> 1.8)
|
17
|
-
multi_xml (>= 0.5.2)
|
18
|
-
i18n (0.6.9)
|
19
|
-
json (1.8.1)
|
20
|
-
listen (1.0.3)
|
21
|
-
rb-fsevent (>= 0.9.3)
|
22
|
-
rb-inotify (>= 0.9)
|
23
|
-
rb-kqueue (>= 0.2)
|
24
|
-
mini_portile (0.5.2)
|
25
|
-
multi_xml (0.5.5)
|
26
|
-
net-scp (1.1.2)
|
27
|
-
net-ssh (>= 2.6.5)
|
28
|
-
net-ssh (2.7.0)
|
29
|
-
nokogiri (1.6.0)
|
30
|
-
mini_portile (~> 0.5.0)
|
31
|
-
rack (1.5.2)
|
32
|
-
rack-protection (1.5.1)
|
33
|
-
rack
|
34
|
-
rack-test (0.6.2)
|
35
|
-
rack (>= 1.0)
|
36
|
-
rake (10.1.0)
|
37
|
-
rb-fsevent (0.9.3)
|
38
|
-
rb-inotify (0.9.2)
|
39
|
-
ffi (>= 0.5.0)
|
40
|
-
rb-kqueue (0.2.0)
|
41
|
-
ffi (>= 0.5.0)
|
42
|
-
rerun (0.8.2)
|
43
|
-
listen (~> 1.0.3)
|
44
|
-
rspec (2.14.1)
|
45
|
-
rspec-core (~> 2.14.0)
|
46
|
-
rspec-expectations (~> 2.14.0)
|
47
|
-
rspec-mocks (~> 2.14.0)
|
48
|
-
rspec-core (2.14.7)
|
49
|
-
rspec-expectations (2.14.4)
|
50
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
51
|
-
rspec-html-matchers (0.4.3)
|
52
|
-
nokogiri (>= 1.4.4)
|
53
|
-
rspec (>= 2.0.0)
|
54
|
-
rspec-mocks (2.14.4)
|
55
|
-
shotgun (0.9)
|
56
|
-
rack (>= 1.0)
|
57
|
-
sinatra (1.4.4)
|
58
|
-
rack (~> 1.4)
|
59
|
-
rack-protection (~> 1.4)
|
60
|
-
tilt (~> 1.3, >= 1.3.4)
|
61
|
-
sshkit (1.2.0)
|
62
|
-
net-scp (>= 1.1.2)
|
63
|
-
net-ssh
|
64
|
-
term-ansicolor
|
65
|
-
term-ansicolor (1.2.2)
|
66
|
-
tins (~> 0.8)
|
67
|
-
thin (1.6.1)
|
68
|
-
daemons (>= 1.0.9)
|
69
|
-
eventmachine (>= 1.0.0)
|
70
|
-
rack (>= 1.0.0)
|
71
|
-
tilt (1.4.1)
|
72
|
-
tins (0.13.1)
|
73
|
-
wei-backend (0.0.2)
|
74
|
-
sinatra (~> 1.4.4)
|
75
|
-
|
76
|
-
PLATFORMS
|
77
|
-
ruby
|
78
|
-
|
79
|
-
DEPENDENCIES
|
80
|
-
capistrano
|
81
|
-
haml
|
82
|
-
hash_validator
|
83
|
-
httparty
|
84
|
-
json
|
85
|
-
nokogiri
|
86
|
-
rack-test
|
87
|
-
rerun
|
88
|
-
rspec
|
89
|
-
rspec-html-matchers
|
90
|
-
shotgun
|
91
|
-
sinatra
|
92
|
-
thin
|
93
|
-
wei-backend
|
data/examples/locations/app.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'sinatra'
|
2
|
-
require 'wei-backend'
|
3
|
-
|
4
|
-
on_location do
|
5
|
-
"You location:\n\t lat: #{params[:Latitude]} \n\t long: #{params[:Longitude]}"
|
6
|
-
end
|
7
|
-
|
8
|
-
on_subscribe do
|
9
|
-
"Please share your location information"
|
10
|
-
end
|
11
|
-
|
12
|
-
on_text do
|
13
|
-
|
14
|
-
#"hello world #{params[:Latitude]}"
|
15
|
-
[{:title=>"", :description=>"", :picturl=>"", :url=>""},{:title=>"", :description=>"", :picturl=>"", :url=>""}]
|
16
|
-
end
|
17
|
-
|
@@ -1,22 +0,0 @@
|
|
1
|
-
source 'http://rubygems.org'
|
2
|
-
|
3
|
-
gem 'json'
|
4
|
-
gem 'haml'
|
5
|
-
gem 'sinatra'
|
6
|
-
gem 'nokogiri'
|
7
|
-
gem 'capistrano'
|
8
|
-
gem 'httparty'
|
9
|
-
gem 'thin'
|
10
|
-
gem 'hash_validator'
|
11
|
-
gem 'wei-backend'
|
12
|
-
|
13
|
-
group :test do
|
14
|
-
gem 'rspec'
|
15
|
-
gem 'rspec-html-matchers'
|
16
|
-
gem 'rack-test'
|
17
|
-
end
|
18
|
-
|
19
|
-
group :development do
|
20
|
-
gem 'rerun'
|
21
|
-
gem 'shotgun'
|
22
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
capistrano (3.0.1)
|
5
|
-
i18n
|
6
|
-
rake (>= 10.0.0)
|
7
|
-
sshkit (>= 0.0.23)
|
8
|
-
daemons (1.1.9)
|
9
|
-
diff-lcs (1.2.5)
|
10
|
-
eventmachine (1.0.3)
|
11
|
-
ffi (1.9.3)
|
12
|
-
haml (4.0.4)
|
13
|
-
tilt
|
14
|
-
hash_validator (0.2.7)
|
15
|
-
httparty (0.12.0)
|
16
|
-
json (~> 1.8)
|
17
|
-
multi_xml (>= 0.5.2)
|
18
|
-
i18n (0.6.9)
|
19
|
-
json (1.8.1)
|
20
|
-
listen (1.0.3)
|
21
|
-
rb-fsevent (>= 0.9.3)
|
22
|
-
rb-inotify (>= 0.9)
|
23
|
-
rb-kqueue (>= 0.2)
|
24
|
-
mini_portile (0.5.2)
|
25
|
-
multi_xml (0.5.5)
|
26
|
-
net-scp (1.1.2)
|
27
|
-
net-ssh (>= 2.6.5)
|
28
|
-
net-ssh (2.7.0)
|
29
|
-
nokogiri (1.6.0)
|
30
|
-
mini_portile (~> 0.5.0)
|
31
|
-
rack (1.5.2)
|
32
|
-
rack-protection (1.5.1)
|
33
|
-
rack
|
34
|
-
rack-test (0.6.2)
|
35
|
-
rack (>= 1.0)
|
36
|
-
rake (10.1.0)
|
37
|
-
rb-fsevent (0.9.3)
|
38
|
-
rb-inotify (0.9.2)
|
39
|
-
ffi (>= 0.5.0)
|
40
|
-
rb-kqueue (0.2.0)
|
41
|
-
ffi (>= 0.5.0)
|
42
|
-
rerun (0.8.2)
|
43
|
-
listen (~> 1.0.3)
|
44
|
-
rspec (2.14.1)
|
45
|
-
rspec-core (~> 2.14.0)
|
46
|
-
rspec-expectations (~> 2.14.0)
|
47
|
-
rspec-mocks (~> 2.14.0)
|
48
|
-
rspec-core (2.14.7)
|
49
|
-
rspec-expectations (2.14.4)
|
50
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
51
|
-
rspec-html-matchers (0.4.3)
|
52
|
-
nokogiri (>= 1.4.4)
|
53
|
-
rspec (>= 2.0.0)
|
54
|
-
rspec-mocks (2.14.4)
|
55
|
-
shotgun (0.9)
|
56
|
-
rack (>= 1.0)
|
57
|
-
sinatra (1.4.4)
|
58
|
-
rack (~> 1.4)
|
59
|
-
rack-protection (~> 1.4)
|
60
|
-
tilt (~> 1.3, >= 1.3.4)
|
61
|
-
sshkit (1.2.0)
|
62
|
-
net-scp (>= 1.1.2)
|
63
|
-
net-ssh
|
64
|
-
term-ansicolor
|
65
|
-
term-ansicolor (1.2.2)
|
66
|
-
tins (~> 0.8)
|
67
|
-
thin (1.6.1)
|
68
|
-
daemons (>= 1.0.9)
|
69
|
-
eventmachine (>= 1.0.0)
|
70
|
-
rack (>= 1.0.0)
|
71
|
-
tilt (1.4.1)
|
72
|
-
tins (0.13.1)
|
73
|
-
wei-backend (0.0.2)
|
74
|
-
sinatra (~> 1.4.4)
|
75
|
-
|
76
|
-
PLATFORMS
|
77
|
-
ruby
|
78
|
-
|
79
|
-
DEPENDENCIES
|
80
|
-
capistrano
|
81
|
-
haml
|
82
|
-
hash_validator
|
83
|
-
httparty
|
84
|
-
json
|
85
|
-
nokogiri
|
86
|
-
rack-test
|
87
|
-
rerun
|
88
|
-
rspec
|
89
|
-
rspec-html-matchers
|
90
|
-
shotgun
|
91
|
-
sinatra
|
92
|
-
thin
|
93
|
-
wei-backend
|
@@ -1,23 +0,0 @@
|
|
1
|
-
namespace :dev do
|
2
|
-
desc 'start application in local env'
|
3
|
-
task :start do
|
4
|
-
sh 'bundle exec shotgun config.ru'
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
namespace :prod do
|
9
|
-
desc 'start production'
|
10
|
-
task :start do
|
11
|
-
sh 'bundle exec thin -d -p 80 start'
|
12
|
-
end
|
13
|
-
|
14
|
-
desc 'stop production'
|
15
|
-
task :stop do
|
16
|
-
sh 'bundle exec thin stop'
|
17
|
-
end
|
18
|
-
|
19
|
-
desc 'restart production'
|
20
|
-
task :restart do
|
21
|
-
sh 'bundle exec thin restart'
|
22
|
-
end
|
23
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
class AiBangClient
|
5
|
-
def initialize(api_base_url, api_key)
|
6
|
-
%w(lines transfer stats).each do |category|
|
7
|
-
instance_variable_set("@#{category}_api_url", api_base_url + "/#{category}?app_key=#{api_key}&alt=json")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
def bus_lines(city, query)
|
11
|
-
encoded_city = URI.encode city
|
12
|
-
encoded_query = URI.encode query
|
13
|
-
api_url = "#{@lines_api_url}&city=#{encoded_city}&q=#{encoded_query}"
|
14
|
-
result = HTTParty.get(api_url).parsed_response["lines"]
|
15
|
-
result.has_key?('line') ? result['line'] : []
|
16
|
-
end
|
17
|
-
end
|
data/examples/waiting_bus/app.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
require './ai_bang_client'
|
4
|
-
require './bus_helper'
|
5
|
-
require_relative '../../lib/wei-backend'
|
6
|
-
|
7
|
-
CONFIG = YAML.load_file("./config/#{ENV['RACK_ENV']}.yml")
|
8
|
-
|
9
|
-
on_text do
|
10
|
-
aibang_client = AiBangClient.new CONFIG[:ai_bang_api], CONFIG[:ai_bang_api_key]
|
11
|
-
bus_helper = BusHelper.new aibang_client
|
12
|
-
bus_helper.bus_lines_running_time(params[:Content])
|
13
|
-
end
|
14
|
-
|
15
|
-
on_event do
|
16
|
-
if params[:Content].eql? 'subscribe'
|
17
|
-
CONFIG[:subscribe_message]
|
18
|
-
else
|
19
|
-
CONFIG[:unsubscribe_message]
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
on_voice do
|
24
|
-
puts 'on voice message'
|
25
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class BusHelper
|
2
|
-
def initialize(ai_bang_client)
|
3
|
-
@ai_bang_client = ai_bang_client
|
4
|
-
end
|
5
|
-
|
6
|
-
def bus_lines_running_time(query)
|
7
|
-
lines = query.scan(/\w*\d+/)
|
8
|
-
bus_num = lines[0].strip if lines.length > 0
|
9
|
-
city = query.sub(/#{bus_num}.*/, '').strip
|
10
|
-
city = "西安" if city.empty?
|
11
|
-
bus_lines_results = @ai_bang_client.bus_lines(city, bus_num)
|
12
|
-
result = "";
|
13
|
-
bus_lines_results.each do |line|
|
14
|
-
running_time = line["info"].scan(/\d{1,2}[::]\d{1,2}-{1,2}\d{1,2}[::]\d{1,2}/)[0]
|
15
|
-
result += line["name"] + " " + running_time + "\n\n" if !running_time.nil?
|
16
|
-
end
|
17
|
-
result
|
18
|
-
end
|
19
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require_relative '../ai_bang_client'
|
3
|
-
|
4
|
-
class MockResponse
|
5
|
-
def parsed_response
|
6
|
-
JSON.parse IO.read('spec/fixtures/bus_lines_response.json')
|
7
|
-
end
|
8
|
-
end
|
9
|
-
module HTTParty
|
10
|
-
def self.get(*args, &block)
|
11
|
-
MockResponse.new
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'aibang api client' do
|
16
|
-
|
17
|
-
it 'should bus lines as json object when search for line 6' do
|
18
|
-
aibang_client = AiBangClient.new 'http://localhost/bus', 'api_key'
|
19
|
-
aibang_client.bus_lines("city", "query").to_s.should include "6\\u8DEF(\\u6021\\u56ED\\u8DEF\\u5317\\u53E3-\\u706B\\u8F66\\u7AD9\\u897F)"
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require_relative '../ai_bang_client'
|
3
|
-
require_relative '../bus_helper'
|
4
|
-
|
5
|
-
describe "bus helper" do
|
6
|
-
|
7
|
-
it "should return bus running time when user search for line 6 running time and city is xi'an" do
|
8
|
-
aibang_client = double(AiBangClient, :bus_lines => (JSON.parse IO.read('spec/fixtures/bus_lines_response.json'))["lines"]["line"])
|
9
|
-
bus_helper = BusHelper.new aibang_client
|
10
|
-
bus_helper.bus_lines_running_time("西安6路").should include "6\u8def(\u706b\u8f66\u7ad9\u897f-\u6021\u56ed\u8def\u5317\u53e3) 6:00-20:30"
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should return bus running time when user search for line k700 running time and city is xi'an" do
|
14
|
-
aibang_client = double(AiBangClient, :bus_lines => (JSON.parse IO.read('spec/fixtures/bus_lines_response.json'))["lines"]["line"])
|
15
|
-
bus_helper = BusHelper.new aibang_client
|
16
|
-
bus_helper.bus_lines_running_time("西安k700路").should include "6\u8def(\u706b\u8f66\u7ad9\u897f-\u6021\u56ed\u8def\u5317\u53e3) 6:00-20:30"
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"result_num": "6",
|
3
|
-
"web_url": "http:\/\/bus.aibang.com",
|
4
|
-
"wap_url": "http:\/\/wap.aibang.com",
|
5
|
-
"lines": {
|
6
|
-
"line": [{
|
7
|
-
"name": "6\u8def(\u6021\u56ed\u8def\u5317\u53e3-\u706b\u8f66\u7ad9\u897f)",
|
8
|
-
"info": "\u5e02\u533a\u7ebf\u8def; \u706b\u8f66\u7ad9\u897f-\u6021\u56ed\u8def\u5317\u53e3 6:00-20:30,\u6021\u56ed\u8def\u5317\u53e3\u2014\u706b\u8f66\u7ad9\u897f 6:00-20:30; 1\u5143\u4e00\u7968\u5236 \u666e\u901a\u53610.5\u5143 \u5b66\u751f\u53610.3\u5143\u3002",
|
9
|
-
"stats": "\u6021\u56ed\u8def\u5317\u53e3;\u60a6\u56ed\u8def\u5317\u53e3;\u9526\u4e1a\u4e8c\u8def;\u4e2d\u5174\u901a\u8baf;\u5357\u4e09\u73af;\u9526\u4e1a\u8def;\u7701\u6e38\u6cf3\u4e2d\u5fc3;\u897f\u4e07\u8def\u53e3;\u6728\u5854\u5be8;\u5e02\u5efa\u56db\u516c\u53f8;\u7535\u5b50\u4e8c\u8def\u897f\u53e3;\u7535\u5b50\u5546\u57ce;\u6c99\u4e95\u6751;\u897f\u659c\u4e03\u8def;\u516c\u4ea4\u4e94\u516c\u53f8;\u897f\u659c\u516d\u8def;\u592a\u767d\u8def\u7acb\u4ea4;\u8fb9\u5bb6\u6751;\u9ec4\u96c1\u6751;\u5f20\u5bb6\u6751;\u542b\u5149\u95e8;\u5c0f\u5357\u95e8(\u4e34\u65f6\u53d6\u6d88);\u6731\u96c0\u95e8(\u4e34\u65f6\u53d6\u6d88);\u5357\u95e8(\u4e34\u65f6\u53d6\u6d88);\u949f\u697c;\u5317\u5927\u8857;\u5317\u95e8;\u897f\u95f8\u53e3\u5357\u53e3;\u706b\u8f66\u7ad9\u897f",
|
10
|
-
"stat_xys": "",
|
11
|
-
"xys": ""
|
12
|
-
}, {
|
13
|
-
"name": "6\u8def(\u706b\u8f66\u7ad9\u897f-\u6021\u56ed\u8def\u5317\u53e3)",
|
14
|
-
"info": "\u5e02\u533a\u7ebf\u8def; \u706b\u8f66\u7ad9\u897f-\u6021\u56ed\u8def\u5317\u53e3 6:00-20:30,\u6021\u56ed\u8def\u5317\u53e3\u2014\u706b\u8f66\u7ad9\u897f 6:00-20:30; 1\u5143\u4e00\u7968\u5236 \u666e\u901a\u53610.5\u5143 \u5b66\u751f\u53610.3\u5143\u3002",
|
15
|
-
"stats": "\u706b\u8f66\u7ad9\u897f;\u897f\u95f8\u53e3\u5357\u53e3;\u5317\u95e8;\u5317\u5927\u8857;\u949f\u697c;\u5357\u95e8(\u4e34\u65f6\u53d6\u6d88);\u6731\u96c0\u95e8(\u4e34\u65f6\u53d6\u6d88);\u5c0f\u5357\u95e8(\u4e34\u65f6\u53d6\u6d88);\u542b\u5149\u95e8;\u5f20\u5bb6\u6751;\u9ec4\u96c1\u6751;\u8fb9\u5bb6\u6751;\u592a\u767d\u8def\u7acb\u4ea4;\u897f\u659c\u516d\u8def;\u516c\u4ea4\u4e94\u516c\u53f8;\u897f\u659c\u4e03\u8def;\u6c99\u4e95\u6751;\u7535\u5b50\u5546\u57ce;\u7535\u5b50\u4e8c\u8def\u897f\u53e3;\u5e02\u5efa\u56db\u516c\u53f8;\u6728\u5854\u5be8;\u897f\u4e07\u8def\u53e3;\u7701\u6e38\u6cf3\u4e2d\u5fc3;\u9526\u4e1a\u8def;\u5357\u4e09\u73af;\u4e2d\u5174\u901a\u8baf;\u9526\u4e1a\u4e8c\u8def;\u60a6\u56ed\u8def\u5317\u53e3;\u6021\u56ed\u8def\u5317\u53e3",
|
16
|
-
"stat_xys": "",
|
17
|
-
"xys": ""
|
18
|
-
}, {
|
19
|
-
"name": "\u6e386(\u5510\u82d1-\u706b\u8f66\u7ad9)",
|
20
|
-
"info": "\u65c5\u6e38\u7ebf\u8def; \u706b\u8f66\u7ad9\u4e1c\u5e7f\u573a--\u5510\u82d1 6:40--19:30; \u8d77\u6b655\u89d2\uff0c5\u89d2\u8fdb\u4f4d\uff0c\u5168\u7a0b3.5\u5143\u3002",
|
21
|
-
"stats": "\u5510\u82d1;\u6797\u5e26\u8def\u91c7\u6458\u56ed;\u66f2\u6c5f\u751f\u6001\u82b1\u56ed;\u9ec4\u6e20\u5934\u6751;\u77f3\u7f8a\u519c\u5e84;\u5b5f\u6751;\u7406\u5de5\u5927\u66f2\u6c5f\u6821\u533a;\u9752\u9f99\u5bfa;\u94c1\u7089\u5e99;\u65b0\u7586\u4e09\u6240;\u89c2\u97f3\u5e99;\u5317\u6c60\u5934;\u897f\u5f71\u8def;\u5e02\u59d4\u515a\u6821;\u5927\u96c1\u5854;\u7fe0\u534e\u8def;\u5c0f\u5be8;\u5927\u5174\u5584\u5bfa(\u53d6\u6d88);\u957f\u5b89\u7acb\u4ea4(\u897f\u5b89\u97f3\u4e50\u5b66\u9662);\u7701\u4f53\u80b2\u573a(\u9655\u897f\u7701\u56fe\u4e66\u9986;\u8349\u573a\u5761;\u5357\u7a0d\u95e8;\u5357\u95e8;\u6587\u660c\u95e8;\u548c\u5e73\u95e8(\u53d6\u6d88);\u534e\u590f\u94f6\u884c;\u5927\u5dee\u5e02;\u6c11\u4e50\u56ed;\u4e94\u8def\u53e3;\u706b\u8f66\u7ad9",
|
22
|
-
"stat_xys": "",
|
23
|
-
"xys": ""
|
24
|
-
}, {
|
25
|
-
"name": "\u6e386(\u706b\u8f66\u7ad9-\u5510\u82d1)",
|
26
|
-
"info": "\u65c5\u6e38\u7ebf\u8def; \u706b\u8f66\u7ad9\u4e1c\u5e7f\u573a--\u5510\u82d1 6:40--19:30; \u8d77\u6b655\u89d2\uff0c5\u89d2\u8fdb\u4f4d\uff0c\u5168\u7a0b3.5\u5143\u3002",
|
27
|
-
"stats": "\u706b\u8f66\u7ad9;\u4e94\u8def\u53e3;\u6c11\u4e50\u56ed;\u5927\u5dee\u5e02;\u534e\u590f\u94f6\u884c;\u548c\u5e73\u95e8;\u6587\u660c\u95e8;\u5357\u95e8;\u5357\u7a0d\u95e8;\u8349\u573a\u5761;\u7701\u4f53\u80b2\u573a(\u9655\u897f\u7701\u56fe\u4e66\u9986;\u957f\u5b89\u7acb\u4ea4(\u897f\u5b89\u97f3\u4e50\u5b66\u9662);\u5927\u5174\u5584\u5bfa(\u53d6\u6d88);\u5c0f\u5be8;\u7fe0\u534e\u8def;\u5927\u96c1\u5854;\u5927\u96c1\u5854\u5357\u5e7f\u573a;\u96c1\u5f15\u8def;\u5e02\u59d4\u515a\u6821;\u897f\u5f71\u8def;\u5317\u6c60\u5934;\u89c2\u97f3\u5e99;\u65b0\u7586\u4e09\u6240;\u94c1\u7089\u5e99;\u9752\u9f99\u5bfa;\u7406\u5de5\u5927\u66f2\u6c5f\u6821\u533a;\u5b5f\u6751;\u77f3\u7f8a\u519c\u5e84;\u9ec4\u6e20\u5934\u6751;\u66f2\u6c5f\u751f\u6001\u82b1\u56ed;\u6797\u5e26\u8def\u91c7\u6458\u56ed;\u5510\u82d1",
|
28
|
-
"stat_xys": "",
|
29
|
-
"xys": ""
|
30
|
-
}, {
|
31
|
-
"name": "\u673a\u573a\u5927\u5df46\u53f7\u7ebf(\u54b8\u9633\u673a\u573a-\u5f69\u8679\u5bbe\u9986)",
|
32
|
-
"info": "\u673a\u573a:09:00-21:00;\u5f69\u8679\u5bbe\u9986:07:00-19:00;\u8d39\u7528:15\u5143+1\u5143\uff08\u71c3\u6cb9\u9644\u52a0\u8d39\uff09\/\u4eba;",
|
33
|
-
"stats": "\u54b8\u9633\u673a\u573a;\u54b8\u9633\u706b\u8f66\u7ad9;\u6e2d\u57ce\u4e2d\u5b66;\u54b8\u9633\u5e02\u653f\u5e9c;\u6c11\u751f\u5546\u53a6;\u5f69\u8679\u5bbe\u9986",
|
34
|
-
"stat_xys": "",
|
35
|
-
"xys": ""
|
36
|
-
}, {
|
37
|
-
"name": "\u673a\u573a\u5927\u5df46\u53f7\u7ebf(\u5f69\u8679\u5bbe\u9986-\u54b8\u9633\u673a\u573a)",
|
38
|
-
"info": "\u673a\u573a:09:00-21:00;\u5f69\u8679\u5bbe\u9986:07:00-19:00;\u8d39\u7528:15\u5143+1\u5143\uff08\u71c3\u6cb9\u9644\u52a0\u8d39\uff09\/\u4eba;",
|
39
|
-
"stats": "\u5f69\u8679\u5bbe\u9986;\u6c11\u751f\u5546\u53a6;\u54b8\u9633\u5e02\u653f\u5e9c;\u6e2d\u57ce\u4e2d\u5b66;\u54b8\u9633\u706b\u8f66\u7ad9;\u54b8\u9633\u673a\u573a",
|
40
|
-
"stat_xys": "",
|
41
|
-
"xys": ""
|
42
|
-
}]
|
43
|
-
}
|
44
|
-
}
|
data/lib/wei-backend/version.rb
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
ENV['RACK_ENV'] = 'test'
|
2
|
-
|
3
|
-
require 'rack/test'
|
4
|
-
require 'rack'
|
5
|
-
require 'rack-protection'
|
6
|
-
require 'rspec'
|
7
|
-
require 'rspec-html-matchers'
|
8
|
-
require './lib/wei-backend'
|
9
|
-
|
10
|
-
TEXT_MESSAGE_REQUEST='<xml><ToUserName><![CDATA[toUser]]></ToUserName><FromUserName>'+
|
11
|
-
'<![CDATA[fromUser]]></FromUserName><CreateTime>1348831860</CreateTime><MsgType><![CDATA[text]]></MsgType>'+
|
12
|
-
'<Content><![CDATA[this is a test]]></Content><MsgId>1234567890123456</MsgId></xml>'
|
13
|
-
|
14
|
-
EVENT_MESSAGE_REQUEST='<xml><ToUserName><![CDATA[toUser]]></ToUserName>'+
|
15
|
-
'<FromUserName><![CDATA[fromUser]]></FromUserName><CreateTime>123456789</CreateTime>'+
|
16
|
-
'<MsgType><![CDATA[event]]></MsgType><Event><![CDATA[subscribe]]></Event></xml>'
|
17
|
-
|
18
|
-
LOCATION_EVENT_REQUEST='<xml>
|
19
|
-
<ToUserName><![CDATA[toUser]]></ToUserName>
|
20
|
-
<FromUserName><![CDATA[fromUser]]></FromUserName>
|
21
|
-
<CreateTime>123456789</CreateTime>
|
22
|
-
<MsgType><![CDATA[event]]></MsgType>
|
23
|
-
<Event><![CDATA[LOCATION]]></Event>
|
24
|
-
<Latitude>23.137466</Latitude>
|
25
|
-
<Longitude>113.352425</Longitude>
|
26
|
-
<Precision>119.385040</Precision>
|
27
|
-
</xml>'
|
28
|
-
|
29
|
-
SUBSCRIBE_EVENT_REQUEST='<xml>
|
30
|
-
<ToUserName><![CDATA[toUser]]></ToUserName>
|
31
|
-
<FromUserName><![CDATA[fromUser]]></FromUserName>
|
32
|
-
<CreateTime>123456789</CreateTime>
|
33
|
-
<MsgType><![CDATA[event]]></MsgType>
|
34
|
-
<Event><![CDATA[subscribe]]></Event>
|
35
|
-
</xml>'
|
36
|
-
|
37
|
-
PARSED_PARAMS={
|
38
|
-
:ToUserName => 'toUser',
|
39
|
-
:FromUserName => 'fromUser',
|
40
|
-
:CreateTime => '1348831860',
|
41
|
-
:MsgType => 'text',
|
42
|
-
:Content => 'this is a test',
|
43
|
-
:MsgId => '1234567890123456'
|
44
|
-
}
|
45
|
-
|
46
|
-
def app
|
47
|
-
Sinatra::Application
|
48
|
-
end
|
data/spec/wei_backend_spec.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
describe 'app' do
|
3
|
-
include Rack::Test::Methods
|
4
|
-
|
5
|
-
it 'should echo string when request with echostr parameter' do
|
6
|
-
get '/weixin?echostr=test'
|
7
|
-
last_response.body.should include 'test'
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'should return user defined text message when receive a text request message' do
|
11
|
-
WeiBackend::MessageDispatcher.on_text do
|
12
|
-
'hello world'
|
13
|
-
end
|
14
|
-
|
15
|
-
post '/weixin', TEXT_MESSAGE_REQUEST, 'CONTENT_TYPE' => 'text/xml'
|
16
|
-
last_response.body.should include '<ToUserName><![CDATA[fromUser]]></ToUserName>'
|
17
|
-
last_response.body.should include '<Content><![CDATA[hello world]]></Content>'
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'should return user defined news message when receive a text request message' do
|
21
|
-
WeiBackend::MessageDispatcher.on_text do
|
22
|
-
{:title => 'title', :description => 'desc', :picture_url => 'pic url', :url => 'url'}
|
23
|
-
end
|
24
|
-
|
25
|
-
post '/weixin', TEXT_MESSAGE_REQUEST, 'CONTENT_TYPE' => 'text/xml'
|
26
|
-
last_response.body.should include '<ToUserName><![CDATA[fromUser]]></ToUserName>'
|
27
|
-
last_response.body.should include '<Title><![CDATA[title]]></Title>'
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'should return news message when receive a text request message and user defined a multi-news' do
|
31
|
-
WeiBackend::MessageDispatcher.on_text do
|
32
|
-
[{
|
33
|
-
:title => 'title',
|
34
|
-
:description => 'desc',
|
35
|
-
:picture_url => 'pic url',
|
36
|
-
:url => 'url'
|
37
|
-
},
|
38
|
-
{
|
39
|
-
:title => 'title1',
|
40
|
-
:description => 'desc1',
|
41
|
-
:picture_url => 'pic url1',
|
42
|
-
:url => 'url1'
|
43
|
-
}]
|
44
|
-
end
|
45
|
-
|
46
|
-
post '/weixin', TEXT_MESSAGE_REQUEST, 'CONTENT_TYPE' => 'text/xml'
|
47
|
-
last_response.body.should include '<ToUserName><![CDATA[fromUser]]></ToUserName>'
|
48
|
-
last_response.body.should include '<Title><![CDATA[title]]></Title>'
|
49
|
-
last_response.body.should include '<Title><![CDATA[title1]]></Title>'
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'should echo location message when receive a location event message' do
|
53
|
-
WeiBackend::MessageDispatcher.on_location do
|
54
|
-
"location event: #{params[:Latitude]}"
|
55
|
-
end
|
56
|
-
|
57
|
-
post '/weixin', LOCATION_EVENT_REQUEST, 'CONTENT_TYPE' => 'text/xml'
|
58
|
-
last_response.body.should include '<ToUserName><![CDATA[fromUser]]></ToUserName>'
|
59
|
-
last_response.body.should include '<Content><![CDATA[location event: 23.137466]]></Content>'
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should echo location message when receive a location event message' do
|
63
|
-
WeiBackend::MessageDispatcher.on_subscribe do
|
64
|
-
'Thank you for subscribe!'
|
65
|
-
end
|
66
|
-
|
67
|
-
post '/weixin', SUBSCRIBE_EVENT_REQUEST, 'CONTENT_TYPE' => 'text/xml'
|
68
|
-
last_response.body.should include '<ToUserName><![CDATA[fromUser]]></ToUserName>'
|
69
|
-
last_response.body.should include '<Content><![CDATA[Thank you for subscribe!]]></Content>'
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'should do something when user have set token' do
|
73
|
-
WeiBackend::MessageDispatcher.on_subscribe do
|
74
|
-
'Thank you for subscribe!'
|
75
|
-
end
|
76
|
-
|
77
|
-
WeiBackend::MessageDispatcher.token 'combustest'
|
78
|
-
|
79
|
-
post '/weixin?signature=0d144fa22f4119dbb2f6fe9710f3b732fb45092b×tamp=1388674716&nonce=1388564676', SUBSCRIBE_EVENT_REQUEST, 'CONTENT_TYPE' => 'text/xml'
|
80
|
-
last_response.body.should include '<ToUserName><![CDATA[fromUser]]></ToUserName>'
|
81
|
-
last_response.body.should include '<Content><![CDATA[Thank you for subscribe!]]></Content>'
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require_relative 'spec_helper'
|
2
|
-
require_relative '../lib/wei-backend/base'
|
3
|
-
|
4
|
-
describe 'weixin message handler' do
|
5
|
-
it 'should call text message handler when invoke handle with text message' do
|
6
|
-
WeiBackend::MessageDispatcher.any_instance.should_receive(:handle_text_message) { 'results' }
|
7
|
-
dispatcher = WeiBackend::MessageDispatcher.new
|
8
|
-
dispatcher.on('text', PARSED_PARAMS).should == {:format => 'text', :model => {:content => 'results', :myAccount=>"toUser", :userAccount=>"fromUser"}}
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should return text format result when model is a string' do
|
12
|
-
dispatcher = WeiBackend::MessageDispatcher.new
|
13
|
-
dispatcher.params=PARSED_PARAMS
|
14
|
-
dispatcher.create_model('text results').should == {:format => 'text', :model => {:content => 'text results', :myAccount=>"toUser", :userAccount=>"fromUser"}}
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should return image text format result when model is a hash' do
|
18
|
-
dispatcher = WeiBackend::MessageDispatcher.new
|
19
|
-
dispatcher.params=PARSED_PARAMS
|
20
|
-
dispatcher.create_model({:url => "http://adc/"}).should == {:format=>"image_text", :model=>{:article_count=>1, :articles=>[{:url=>"http://adc/"}], :myAccount=>"toUser", :userAccount=>"fromUser"}}
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|