yx_sdk 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yx_sdk.rb +12 -7
- data/lib/yx_sdk/client.rb +2 -2
- data/lib/yx_sdk/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2650aa7f15f87cd3340404fcde01e6802efbb4d8
|
4
|
+
data.tar.gz: b5653c66c55dbfe8f8c93d9d7410d46ac22ed2ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e13c22362fb1bcec94af0baf5cc0a26399eaf98eb5b44f18f028c74129d1b7fe3fdbcac9510978dd0b0c92103592e4cd7b08d650a9a35c4653c4982e9f58334d
|
7
|
+
data.tar.gz: 45b36f2befe07707e2ac112c3b8f5c8b79733951a16f949897d7e25fcc033333181bad49db8fc0d3973efcfddf8a1f70a23967e0655253b93b5dc16dcf995ef0
|
data/lib/yx_sdk.rb
CHANGED
@@ -3,7 +3,11 @@ require "yx_sdk/version"
|
|
3
3
|
require "yx_sdk/handler/result_handler"
|
4
4
|
require "yx_sdk/api"
|
5
5
|
require "yx_sdk/client"
|
6
|
-
|
6
|
+
if defined? Yajl
|
7
|
+
require 'yajl/json_gem'
|
8
|
+
else
|
9
|
+
require "json"
|
10
|
+
end
|
7
11
|
|
8
12
|
module YxSdk
|
9
13
|
|
@@ -11,24 +15,25 @@ module YxSdk
|
|
11
15
|
|
12
16
|
class << self
|
13
17
|
|
14
|
-
def http_post_without_token(url,
|
18
|
+
def http_post_without_token(url, url_params={}, header = {}, endpoint="plain")
|
15
19
|
post_api_url = endpoint_url(endpoint, url)
|
20
|
+
post_body = ''
|
16
21
|
if endpoint == "plain" || endpoint == CUSTOM_ENDPOINT
|
17
|
-
post_body =
|
22
|
+
url_params.each {|k,v| post_body = post_body + "#{k}=#{v}&"}
|
18
23
|
end
|
19
|
-
|
20
|
-
load_json(resource(post_api_url, header).post(post_body
|
24
|
+
puts "request url is #{post_api_url}, header is #{header}, post_body is #{post_body[0..-1]}"
|
25
|
+
load_json(resource(post_api_url, header).post(post_body[0..-1]))
|
21
26
|
end
|
22
27
|
|
23
28
|
|
24
29
|
def resource(url, header)
|
25
|
-
RestClient::Resource.new(url, header)
|
30
|
+
RestClient::Resource.new(url, :headers => header)
|
26
31
|
end
|
27
32
|
|
28
33
|
# return hash
|
29
34
|
def load_json(string)
|
30
35
|
result_hash = JSON.parse(string.force_encoding("UTF-8").gsub(/[\u0011-\u001F]/, ""))
|
31
|
-
|
36
|
+
puts "response #{result_hash}"
|
32
37
|
code = result_hash.delete("code")
|
33
38
|
info = result_hash.delete("info")
|
34
39
|
ResultHandler.new(code, info)
|
data/lib/yx_sdk/client.rb
CHANGED
@@ -13,9 +13,9 @@ module YxSdk
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# 暴露出:http_get,http_post两个方法,方便第三方开发者扩展未开发的微信API。
|
16
|
-
def http_post(url,
|
16
|
+
def http_post(url, url_params={}, endpoint="plain")
|
17
17
|
# url_params = url_params.merge(access_token_param)
|
18
|
-
YxSdk.http_post_without_token(url,
|
18
|
+
YxSdk.http_post_without_token(url, url_params, get_header, endpoint)
|
19
19
|
end
|
20
20
|
|
21
21
|
def get_header
|
data/lib/yx_sdk/version.rb
CHANGED