open_qq 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/open_qq/gateway.rb +4 -3
- data/lib/open_qq/request.rb +5 -3
- data/lib/open_qq/signature.rb +4 -0
- data/lib/open_qq/version.rb +1 -1
- data/test/open_qq_test.rb +27 -1
- metadata +2 -2
data/lib/open_qq/gateway.rb
CHANGED
@@ -57,8 +57,8 @@ module OpenQq
|
|
57
57
|
#
|
58
58
|
# @return (see #call)
|
59
59
|
def get(url, params = {}, options = {})
|
60
|
-
parsed_params = Gateway.
|
61
|
-
get_request
|
60
|
+
parsed_params = Gateway.parsed_params( wrap(:get, url, params) )
|
61
|
+
get_request = Net::HTTP::Get.new("#{url}?#{parsed_params}")
|
62
62
|
self.call( get_request, options.merge(:format => params[:format]) )
|
63
63
|
end
|
64
64
|
|
@@ -67,7 +67,8 @@ module OpenQq
|
|
67
67
|
# @return (see #call)
|
68
68
|
def post(url, params = {}, options = {})
|
69
69
|
post_request = Net::HTTP::Post.new(url)
|
70
|
-
post_request.
|
70
|
+
post_request.body = Gateway.parsed_params( wrap(:post, url, params) )
|
71
|
+
post_request.content_type = 'application/x-www-form-urlencoded'
|
71
72
|
self.call( post_request, options.merge(:format => params[:format]) )
|
72
73
|
end
|
73
74
|
|
data/lib/open_qq/request.rb
CHANGED
@@ -17,17 +17,19 @@ module OpenQq
|
|
17
17
|
appkey = options.delete(:appkey)
|
18
18
|
env = options.delete(:env)
|
19
19
|
@url = options.delete(:url)
|
20
|
-
@options = options
|
20
|
+
@options = options || {}
|
21
21
|
super(appid, appkey, env)
|
22
22
|
end
|
23
23
|
|
24
24
|
# @see Gateway#get
|
25
|
-
def get(params = {}, options =
|
25
|
+
def get(params = {}, options = nil)
|
26
|
+
options ||= @options
|
26
27
|
super(@url, params, options)
|
27
28
|
end
|
28
29
|
|
29
30
|
# @see Gateway#get
|
30
|
-
def post(params = {}, options =
|
31
|
+
def post(params = {}, options = nil)
|
32
|
+
options ||= @options
|
31
33
|
super(@url, params, options)
|
32
34
|
end
|
33
35
|
|
data/lib/open_qq/signature.rb
CHANGED
@@ -23,6 +23,10 @@ module OpenQq
|
|
23
23
|
options.inject({}){|h,(k,v)| h[url_escape(k.to_s)] = url_escape(v.to_s);h}
|
24
24
|
end
|
25
25
|
|
26
|
+
def parsed_params(params)
|
27
|
+
each_pair_escape(params).map{|k,v| "#{k}=#{v}"}.join('&')
|
28
|
+
end
|
29
|
+
|
26
30
|
def make_source(http_method, url, options)
|
27
31
|
escape_opt = url_escape( options.sort_by{|k,v| k.to_s}.map{|kv| "#{kv.first}=#{kv.last}" }.join('&') )
|
28
32
|
"#{http_method}&#{url_escape(url)}&#{escape_opt}"
|
data/lib/open_qq/version.rb
CHANGED
data/test/open_qq_test.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'test_helper'
|
2
3
|
|
3
4
|
class OpenQqTest < MiniTest::Unit::TestCase
|
@@ -13,7 +14,11 @@ class OpenQqTest < MiniTest::Unit::TestCase
|
|
13
14
|
|
14
15
|
def teardown
|
15
16
|
# Need setup back for the rest test
|
16
|
-
OpenQq.setup{|c|
|
17
|
+
OpenQq.setup{|c|
|
18
|
+
c.appid = 12345
|
19
|
+
c.appkey ='228bf094169a40a3bd188ba37ebe8723'
|
20
|
+
c.env ='http://119.147.19.43'
|
21
|
+
}
|
17
22
|
end
|
18
23
|
|
19
24
|
def test_OpenQq_is_a_module
|
@@ -102,4 +107,25 @@ class OpenQqTest < MiniTest::Unit::TestCase
|
|
102
107
|
assert OpenQq.verify_callback_sig(:get, '/cgi-bin/temp.py', options), 'Verify sig failure 3'
|
103
108
|
end
|
104
109
|
|
110
|
+
#http://wiki.open.qq.com/wiki/v3/pay/buy_goods
|
111
|
+
def test_buy_goods
|
112
|
+
options = { :appid => 600,
|
113
|
+
:appkey => '12345f9a47df4d1eaeb3bad9a7e54321',
|
114
|
+
:env => 'https://119.147.19.43'
|
115
|
+
}
|
116
|
+
params = { :amt => 4,:appmode => 1,:format => 'json',:goodsmeta => '道具*测试描述信息!!!',
|
117
|
+
:goodsurl => 'http://qzonestyle.gtimg.cn/qzonestyle/act/qzone_app_img/app613_613_75.png',
|
118
|
+
:openid => '0000000000000000000000000E111111',
|
119
|
+
:openkey => '1111806DC5D1C52150CF405E42222222',
|
120
|
+
:payitem => '50005*4*1',
|
121
|
+
:pf => 'qzone',
|
122
|
+
:pfkey => '1B59A5C3D77C7C56D7AFC3E2C823105D',
|
123
|
+
:ts => '1333674935'
|
124
|
+
}
|
125
|
+
sig = 'fVcr1Imq8FjJZgf3h24haUE18rA='
|
126
|
+
OpenQq.call('/v3/pay/buy_goods', options) do |request|
|
127
|
+
assert_equal sig, request.wrap(:get, '/v3/pay/buy_goods', params)[:sig]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
105
131
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_qq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|