weixin_authorize 1.5.7 → 1.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d129bc3d015de739c581be31a890d2d69a660c3c
4
- data.tar.gz: 0733221f98d69e18fcc590b722b5ca65b6e160a1
3
+ metadata.gz: af6979103c92161f0e5e190e4e2e3050abf5aa4a
4
+ data.tar.gz: ad4f77bbc0a0745f87762c500a14f23e2fc10778
5
5
  SHA512:
6
- metadata.gz: ce78111847c32d86347750e4801ab110129c96759ef5e96ec6d8554abda6da4a0ed4859573379f7c061f2eab9f93230f0c0f5930215474b3a1c7ded42dd01e49
7
- data.tar.gz: 9ce24065e53e9fdc5be18244541d018f333377f5bece38d8639ffe79f617a775cc6afdfc6975482fa3383c1e1e942cd7856275dd51fa37b6aaebe37cff498dcc
6
+ metadata.gz: b98d1b3412cadc32b2c62790f0c97a265ebf93120baf611fa40e261f2f477f531c328dc575fe44cda8cecbfeb1197c15d53e608df76c12bf2e8912f7b870749f
7
+ data.tar.gz: 79ef616a6877b6790aca143d08bf571919e47be2d41581f7aa2535690f2e588d15d07bdd32d2493d3e0dc9d68888be756781c05dc34a4df0aeea503215eb9a31
data/.coveralls.yml ADDED
@@ -0,0 +1,2 @@
1
+ service_name: travis-pro
2
+ repo_token: aAaaYkiZrS6MHUIbKFdM1b5EnevvVZ4MQ
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ bundler_args: --without development
3
+ rvm:
4
+ - 2.0.0
5
+ script:
6
+ - bundle exec rspec spec
7
+ services:
8
+ - redis
9
+ addons:
10
+ code_climate:
11
+ repo_token: c91fecbbd9e414e7cc3ad7a7d99207145de0ac65a3368de09e8c19295343d399
data/Gemfile CHANGED
@@ -1,4 +1,19 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem "rspec", "~> 3.0.0.beta1"
4
+ gem "redis-namespace", "~> 1.4.1"
5
+ gem "rake", "~> 0.9.6"
6
+ gem 'simplecov', '~> 0.7.1', :require => false
7
+ gem "codeclimate-test-reporter", require: nil
8
+ gem 'coveralls', require: false
9
+
10
+ group :development do
11
+ # For debugger
12
+ gem "pry-rails", "~> 0.3.2"
13
+
14
+ gem "pry-debugger", "~> 0.2.2"
15
+ end
16
+
3
17
  # Specify your gem's dependencies in weixin_authorize.gemspec
4
18
  gemspec
19
+
data/README.md CHANGED
@@ -1,11 +1,18 @@
1
1
  # WeixinAuthorize
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/weixin_authorize.png)](http://badge.fury.io/rb/weixin_authorize)
4
+ [![Build Status](https://secure.travis-ci.org/lanrion/weixin_authorize.png?branch=master)](http://travis-ci.org/lanrion/weixin_authorize)
5
+ [![Code Climate](https://codeclimate.com/github/lanrion/weixin_authorize.png)](https://codeclimate.com/github/lanrion/weixin_authorize)
6
+ [![Coverage Status](https://codeclimate.com/github/lanrion/weixin_authorize/coverage.png)](https://codeclimate.com/github/lanrion/weixin_authorize)
4
7
 
5
8
  Support using [Redis](http://redis.io) to store `access_token`
6
9
 
10
+ [查看Wiki](https://github.com/lanrion/weixin_authorize/wiki)
11
+
7
12
  [Getting-Started](https://github.com/lanrion/weixin_authorize/wiki/Getting-Started)
8
13
 
14
+ 注意:查看Wiki或者源代码时,请切换对应的版本来查看。Master处于不断更新完善分支。
15
+
9
16
  ## How to test
10
17
 
11
18
  Go to https://github.com/lanrion/weixin_authorize/issues/2, apply a weixin sandbox test account and follow this account, then add them to your `~/.bash_profile`
@@ -11,7 +11,7 @@ module WeixinAuthorize
11
11
  client.expired_at <= Time.now.to_i
12
12
  end
13
13
 
14
- def authenticate
14
+ def refresh_token
15
15
  super
16
16
  end
17
17
 
@@ -12,10 +12,10 @@ module WeixinAuthorize
12
12
  weixin_redis.hvals(client.redis_key).empty?
13
13
  end
14
14
 
15
- def authenticate
15
+ def refresh_token
16
16
  super
17
- weixin_redis.hmset(client.redis_key, :access_token, client.access_token,
18
- :expired_at, client.expired_at)
17
+ weixin_redis.hmset(client.redis_key, "access_token", client.access_token,
18
+ "expired_at", client.expired_at)
19
19
  weixin_redis.expireat(client.redis_key, client.expired_at.to_i-10) # 提前10秒超时
20
20
  end
21
21
 
@@ -18,29 +18,34 @@ module WeixinAuthorize
18
18
  end
19
19
 
20
20
  def valid?
21
- valid_result = http_get_access_token
22
- if valid_result.keys.include?("access_token")
23
- set_access_token_for_client(valid_result)
24
- return true
25
- end
26
- false
21
+ authenticate["valid"]
27
22
  end
28
23
 
29
- def token_expired?
30
- raise NotImplementedError, "Subclasses must implement a token_expired? method"
24
+ def authenticate
25
+ auth_result = http_get_access_token
26
+ auth = false
27
+ if auth_result.is_ok?
28
+ set_access_token_for_client(auth_result.result)
29
+ auth = true
30
+ end
31
+ {"valid" => auth, "handler" => auth_result}
31
32
  end
32
33
 
33
- def authenticate
34
- raise "APPID or APPSECRET is invalid" if !valid?
34
+ def refresh_token
35
+ handle_valid_exception
35
36
  set_access_token_for_client
36
37
  end
37
38
 
38
39
  def access_token
39
- authenticate if token_expired?
40
+ refresh_token if token_expired?
41
+ end
42
+
43
+ def token_expired?
44
+ raise NotImplementedError, "Subclasses must implement a token_expired? method"
40
45
  end
41
46
 
42
47
  def set_access_token_for_client(access_token_infos=nil)
43
- token_infos = access_token_infos || http_get_access_token
48
+ token_infos = access_token_infos || http_get_access_token.result
44
49
  client.access_token = token_infos["access_token"]
45
50
  client.expired_at = Time.now.to_i + token_infos["expires_in"].to_i
46
51
  end
@@ -50,9 +55,19 @@ module WeixinAuthorize
50
55
  end
51
56
 
52
57
  def authenticate_headers
53
- {grant_type: "client_credential", appid: client.app_id, secret: client.app_secret}
58
+ {grant_type: GRANT_TYPE, appid: client.app_id, secret: client.app_secret}
54
59
  end
55
60
 
61
+ private
62
+
63
+ def handle_valid_exception
64
+ auth_result = authenticate
65
+ if !auth_result["valid"]
66
+ result_handler = auth_result["handler"]
67
+ raise ValidAccessTokenException, result_handler.full_error_message
68
+ end
69
+ end
70
+
56
71
  end
57
72
 
58
73
  end
@@ -45,7 +45,7 @@ module WeixinAuthorize
45
45
  end
46
46
 
47
47
  def http_post(url, payload={}, headers={}, endpoint="plain")
48
- headers = {:params => access_token_param.merge(headers)}
48
+ headers = access_token_param.merge(headers)
49
49
  WeixinAuthorize.http_post_without_token(url, payload, headers, endpoint)
50
50
  end
51
51
 
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+ module WeixinAuthorize
3
+
4
+ class ValidAccessTokenException < RuntimeError
5
+ end
6
+
7
+ end
@@ -0,0 +1,89 @@
1
+ # encoding: utf-8
2
+ module WeixinAuthorize
3
+
4
+ GLOBAL_CODES = {
5
+ -1 => "系统繁忙",
6
+ 0 => "请求成功",
7
+ 40001 => "获取access_token时AppSecret错误,或者access_token无效",
8
+ 40002 => "不合法的凭证类型",
9
+ 40003 => "不合法的OpenID",
10
+ 40004 => "不合法的媒体文件类型",
11
+ 40005 => "不合法的文件类型",
12
+ 40006 => "不合法的文件大小",
13
+ 40007 => "不合法的媒体文件id",
14
+ 40008 => "不合法的消息类型",
15
+ 40009 => "不合法的图片文件大小",
16
+ 40010 => "不合法的语音文件大小",
17
+ 40011 => "不合法的视频文件大小",
18
+ 40012 => "不合法的缩略图文件大小",
19
+ 40013 => "不合法的APPID",
20
+ 40014 => "不合法的access_token",
21
+ 40015 => "不合法的菜单类型",
22
+ 40016 => "不合法的按钮个数",
23
+ 40017 => "不合法的按钮个数",
24
+ 40018 => "不合法的按钮名字长度",
25
+ 40019 => "不合法的按钮KEY长度",
26
+ 40020 => "不合法的按钮URL长度",
27
+ 40021 => "不合法的菜单版本号",
28
+ 40022 => "不合法的子菜单级数",
29
+ 40023 => "不合法的子菜单按钮个数",
30
+ 40024 => "不合法的子菜单按钮类型",
31
+ 40025 => "不合法的子菜单按钮名字长度",
32
+ 40026 => "不合法的子菜单按钮KEY长度",
33
+ 40027 => "不合法的子菜单按钮URL长度",
34
+ 40028 => "不合法的自定义菜单使用用户",
35
+ 40029 => "不合法的oauth_code",
36
+ 40030 => "不合法的refresh_token",
37
+ 40031 => "不合法的openid列表",
38
+ 40032 => "不合法的openid列表长度",
39
+ 40033 => "不合法的请求字符,不能包含xxxx格式的字符",
40
+ 40035 => "不合法的参数",
41
+ 40038 => "不合法的请求格式",
42
+ 40039 => "不合法的URL长度",
43
+ 40050 => "不合法的分组id",
44
+ 40051 => "分组名字不合法",
45
+ 41001 => "缺少access_token参数",
46
+ 41002 => "缺少appid参数",
47
+ 41003 => "缺少refresh_token参数",
48
+ 41004 => "缺少secret参数",
49
+ 41005 => "缺少多媒体文件数据",
50
+ 41006 => "缺少media_id参数",
51
+ 41007 => "缺少子菜单数据",
52
+ 41008 => "缺少oauth code",
53
+ 41009 => "缺少openid",
54
+ 42001 => "access_token超时",
55
+ 42002 => "refresh_token超时",
56
+ 42003 => "oauth_code超时",
57
+ 43001 => "需要GET请求",
58
+ 43002 => "需要POST请求",
59
+ 43003 => "需要HTTPS请求",
60
+ 43004 => "需要接收者关注",
61
+ 43005 => "需要好友关系",
62
+ 44001 => "多媒体文件为空",
63
+ 44002 => "POST的数据包为空",
64
+ 44003 => "图文消息内容为空",
65
+ 44004 => "文本消息内容为空",
66
+ 45001 => "多媒体文件大小超过限制",
67
+ 45002 => "消息内容超过限制",
68
+ 45003 => "标题字段超过限制",
69
+ 45004 => "描述字段超过限制",
70
+ 45005 => "链接字段超过限制",
71
+ 45006 => "图片链接字段超过限制",
72
+ 45007 => "语音播放时间超过限制",
73
+ 45008 => "图文消息超过限制",
74
+ 45009 => "接口调用超过限制",
75
+ 45010 => "创建菜单个数超过限制",
76
+ 45015 => "回复时间超过限制",
77
+ 45016 => "系统分组,不允许修改",
78
+ 45017 => "分组名字过长",
79
+ 45018 => "分组数量超过上限",
80
+ 46001 => "不存在媒体数据",
81
+ 46002 => "不存在的菜单版本",
82
+ 46003 => "不存在的菜单数据",
83
+ 46004 => "不存在的用户",
84
+ 47001 => "解析JSON/XML内容错误",
85
+ 48001 => "api功能未授权",
86
+ 50001 => "用户未授权该api"
87
+ }unless defined?(GLOBAL_CODES)
88
+
89
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ module WeixinAuthorize
3
+
4
+ class ResultHandler
5
+
6
+ attr_accessor :code, :cn_msg, :en_msg, :result
7
+
8
+ def initialize(code, en_msg, result={})
9
+ @code = code || OK_CODE
10
+ @en_msg = en_msg || OK_MSG
11
+ @cn_msg = GLOBAL_CODES[@code.to_i]
12
+ @result = package_result(result)
13
+ end
14
+
15
+ # This method is to valid the current request if is true or is false
16
+ def is_ok?
17
+ code == OK_CODE
18
+ end
19
+ alias_method :ok?, :is_ok?
20
+
21
+ # e.g.:
22
+ # 45009: api freq out of limit(接口调用超过限制)
23
+ def full_message
24
+ "#{code}: #{en_msg}(#{cn_msg})."
25
+ end
26
+ alias_method :full_messages, :full_message
27
+
28
+ def full_error_message
29
+ full_message if !is_ok?
30
+ end
31
+ alias_method :full_error_messages, :full_error_message
32
+ alias_method :errors, :full_error_message
33
+
34
+ private
35
+
36
+ # if define Rails constant
37
+ # result = WeixinAuthorize::ResultHandler.new("0", "success", {:ok => "true"})
38
+ # result.result["ok"] #=> true
39
+ # result.result[:ok] #=> true
40
+ # result.result['ok'] #=> true
41
+ def package_result(result)
42
+ if defined?(Rails)
43
+ ActiveSupport::HashWithIndifferentAccess.new(result)
44
+ else
45
+ result
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+ end
@@ -0,0 +1,3 @@
1
+ require "weixin_authorize/handler/global_code"
2
+ require "weixin_authorize/handler/result_handler"
3
+ require "weixin_authorize/handler/exceptions"
@@ -1,3 +1,3 @@
1
1
  module WeixinAuthorize
2
- VERSION = "1.5.7"
2
+ VERSION = "1.5.8"
3
3
  end
@@ -1,12 +1,21 @@
1
1
  require "rest-client"
2
2
  require "multi_json"
3
3
  require "weixin_authorize/config"
4
- require "weixin_authorize/adapter"
4
+ require "weixin_authorize/handler"
5
5
  require "weixin_authorize/api"
6
6
  require "weixin_authorize/client"
7
7
 
8
8
  module WeixinAuthorize
9
9
 
10
+ # Storage
11
+ autoload(:Storage, "weixin_authorize/adapter/storage")
12
+ autoload(:ClientStorage, "weixin_authorize/adapter/client_storage")
13
+ autoload(:RedisStorage, "weixin_authorize/adapter/redis_storage")
14
+
15
+ OK_MSG = "ok".freeze
16
+ OK_CODE = 0.freeze
17
+ GRANT_TYPE = "client_credential".freeze
18
+
10
19
  class << self
11
20
 
12
21
  def http_get_without_token(url, headers={}, endpoint="plain")
@@ -16,13 +25,16 @@ module WeixinAuthorize
16
25
 
17
26
  def http_post_without_token(url, payload={}, headers={}, endpoint="plain")
18
27
  post_api_url = endpoint_url(endpoint, url)
19
- payload = MultiJson.dump(payload) if endpoint == "plain" # to json
20
- load_json(RestClient.post(post_api_url, payload, headers))
28
+ payload = MultiJson.dump(payload) if endpoint == "plain" # to json if invoke "plain"
29
+ load_json(RestClient.post(post_api_url, payload, :params => headers))
21
30
  end
22
31
 
23
32
  # return hash
24
33
  def load_json(string)
25
- JSON.parse(string)
34
+ result_hash = JSON.parse(string)
35
+ code = result_hash.delete("errcode")
36
+ en_msg = result_hash.delete("errmsg")
37
+ ResultHandler.new(code, en_msg, result_hash)
26
38
  end
27
39
 
28
40
  def endpoint_url(endpoint, url)
@@ -15,7 +15,7 @@ describe WeixinAuthorize::Api::Custom do
15
15
 
16
16
  it "#send_text_custom" do
17
17
  response = $client.send_text_custom(ENV["OPENID"], text_message)
18
- expect(response["errcode"]).to eq(0)
18
+ expect(response.code).to eq(WeixinAuthorize::OK_CODE)
19
19
  end
20
20
 
21
21
  it "#send_news_custom" do
@@ -32,14 +32,14 @@ describe WeixinAuthorize::Api::Custom do
32
32
  "picurl"=> "http://www.baidu.com/img/bdlogo.gif"
33
33
  }]
34
34
  response = $client.send_news_custom(ENV["OPENID"], articles)
35
- expect(response["errcode"]).to eq(0)
35
+ expect(response.code).to eq(WeixinAuthorize::OK_CODE)
36
36
  end
37
37
 
38
38
  it "#send_image_custom" do
39
39
  image = $client.upload_media(image_file, "image")
40
- media_id = image["media_id"]
40
+ media_id = image.result["media_id"]
41
41
  response = $client.send_image_custom(ENV["OPENID"], media_id)
42
- expect(response["errcode"]).to eq(0)
42
+ expect(response.code).to eq(WeixinAuthorize::OK_CODE)
43
43
  end
44
44
 
45
45
  it "#send_video_custom" do
@@ -11,44 +11,44 @@ describe WeixinAuthorize::Api::Groups do
11
11
 
12
12
  it "create a group" do
13
13
  response = $client.create_group(group_name)
14
- if !response["errcode"].nil?
15
- expect(response.keys).to eq(["errcode", "errmsg"])
16
- puts "SB WEIXIN says: system error"
17
- else
14
+ if response.code == WeixinAuthorize::OK_CODE
18
15
  expect(response["group"]["name"]).to eq(group_name)
16
+ else
17
+ expect(response.code).to eq(-1)
18
+ puts "SB WEIXIN says: system error"
19
19
  end
20
20
  end
21
21
 
22
22
  it "get groups" do
23
23
  groups = $client.groups
24
- expect(groups["groups"][-1]["name"]).to eq(group_name)
24
+ expect(groups.result["groups"][-1]["name"]).to eq(group_name)
25
25
  end
26
26
 
27
27
  it "#get_group_for ENV['OPENID']" do
28
28
  group = $client.get_group_for(ENV["OPENID"])
29
- expect(group.keys).to eq(["groupid"])
29
+ expect(group.result.keys).to eq(["groupid"])
30
30
  end
31
31
 
32
32
  it "#update_group_name" do
33
33
  response = $client.create_group(group_name)
34
- if !response["errcode"].nil?
35
- expect(response.keys).to eq(["errcode", "errmsg"])
34
+ if response.code != WeixinAuthorize::OK_CODE
35
+ expect(response.code).to eq(-1)
36
36
  puts "SB WEIXIN says: system error"
37
37
  else
38
- expect(response["group"]["name"]).to eq(group_name)
39
- response = $client.update_group_name(response["group"]["id"], group_name_2)
40
- expect(response["errcode"]).to eq(0)
38
+ expect(response.result["group"]["name"]).to eq(group_name)
39
+ response = $client.update_group_name(response.result["group"]["id"], group_name_2)
40
+ expect(response.code).to eq(WeixinAuthorize::OK_CODE)
41
41
  groups = $client.groups
42
- expect(groups["groups"][-1]["name"]).to eq(group_name_2)
42
+ expect(groups.result["groups"][-1]["name"]).to eq(group_name_2)
43
43
  end
44
44
  end
45
45
 
46
46
  it "#update_group_for_openid" do
47
47
  groups = $client.groups
48
- last_group_id = groups["groups"][-1]["id"]
48
+ last_group_id = groups.result["groups"][-1]["id"]
49
49
  $client.update_group_for_openid(ENV["OPENID"], last_group_id)
50
50
  group = $client.get_group_for(ENV["OPENID"])
51
- expect(group["groupid"]).to eq(last_group_id)
51
+ expect(group.result["groupid"]).to eq(last_group_id)
52
52
  $client.update_group_for_openid(ENV["OPENID"], 0)
53
53
  end
54
54
 
@@ -12,12 +12,13 @@ describe WeixinAuthorize::Api::Media do
12
12
 
13
13
  it "can upload a image" do
14
14
  response = $client.upload_media(image_file, "image")
15
- expect(response.keys).to eq(["type", "media_id", "created_at"])
15
+ expect(response.code).to eq(WeixinAuthorize::OK_CODE)
16
+ expect(response.result.keys).to eq(["type", "media_id", "created_at"])
16
17
  end
17
18
 
18
19
  it "#download_media_url return a String url" do
19
20
  image = $client.upload_media(image_file, "image")
20
- media_id = image["media_id"]
21
+ media_id = image.result["media_id"]
21
22
  response = $client.download_media_url(media_id)
22
23
  expect(response.class).to eq(String)
23
24
  end
@@ -6,16 +6,23 @@ describe WeixinAuthorize::Api::Menu do
6
6
  it "can create a menu" do
7
7
  menu = '{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]}'
8
8
  response = $client.create_menu(MultiJson.load(menu)) # or Json string
9
- expect(response["errcode"]).to eq(0)
9
+ expect(response.code).to eq(WeixinAuthorize::OK_CODE)
10
+ end
11
+
12
+ it "can't create a menu if invalid button size" do
13
+ menu = '{"button":[]}'
14
+ response = $client.create_menu(menu)
15
+ expect(response.code).not_to eq(WeixinAuthorize::OK_CODE)
10
16
  end
11
17
 
12
18
  it "can get a weixin Menu info" do
13
19
  menu_info = $client.menu
14
- expect(menu_info.keys[0]).to eq("menu")
20
+ expect(menu_info.result.keys[0]).to eq("menu")
21
+ expect(menu_info.code).to eq(WeixinAuthorize::OK_CODE)
15
22
  end
16
23
 
17
24
  it "can delete weixin Menu" do
18
25
  response = $client.delete_menu
19
- expect(response["errcode"]).to eq(0)
26
+ expect(response.code).to eq(WeixinAuthorize::OK_CODE)
20
27
  end
21
28
  end
@@ -4,13 +4,15 @@ describe WeixinAuthorize::Api::Qrcode do
4
4
 
5
5
  it "#create_qr_scene" do
6
6
  response = $client.create_qr_scene("123")
7
- expect(response.keys).to eq(["ticket", "expire_seconds"])
8
- expect(response["expire_seconds"]).to eq(1800)
7
+ expect(response.code).to eq(WeixinAuthorize::OK_CODE)
8
+ expect(response.result.keys).to eq(["ticket", "expire_seconds"])
9
+ expect(response.result["expire_seconds"]).to eq(1800)
9
10
  end
10
11
 
11
12
  it "#create_qr_limit_scene" do
12
13
  response = $client.create_qr_limit_scene("1234")
13
- expect(response.keys).to eq(["ticket"])
14
+ expect(response.code).to eq(WeixinAuthorize::OK_CODE)
15
+ expect(response.result.keys).to eq(["ticket"])
14
16
  end
15
17
 
16
18
  end
@@ -3,18 +3,21 @@ require "spec_helper"
3
3
  describe WeixinAuthorize::Api::User do
4
4
  it "can get a weixin User info" do
5
5
  user_info = $client.user(ENV["OPENID"])
6
- expect(user_info["openid"]).to eq(ENV["OPENID"])
6
+ expect(user_info.code).to eq(WeixinAuthorize::OK_CODE)
7
+ expect(user_info.result["openid"]).to eq(ENV["OPENID"])
7
8
  end
8
9
 
9
10
  it "can get followers infos" do
10
11
  valid_info = $client.is_valid?
11
12
  expect(valid_info).to eq(true)
12
13
  followers = $client.followers
13
- expect(followers.keys).to eq(["total", "count", "data", "next_openid"])
14
+ expect(followers.code).to eq(WeixinAuthorize::OK_CODE)
15
+ expect(followers.result.keys).to eq(["total", "count", "data", "next_openid"])
14
16
 
15
17
  valid_info = $client.is_valid?
16
18
  expect(valid_info).to eq(true)
17
19
  followers = $client.followers
18
- expect(followers.keys).to eq(["total", "count", "data", "next_openid"])
20
+ expect(followers.code).to eq(WeixinAuthorize::OK_CODE)
21
+ expect(followers.result.keys).to eq(["total", "count", "data", "next_openid"])
19
22
  end
20
23
  end
data/spec/spec_helper.rb CHANGED
@@ -19,6 +19,27 @@ require "multi_json"
19
19
  require "redis"
20
20
  require "redis-namespace"
21
21
 
22
+ require 'coveralls'
23
+ require 'simplecov'
24
+ require "codeclimate-test-reporter"
25
+
26
+ Coveralls.wear!
27
+
28
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
29
+ SimpleCov::Formatter::HTMLFormatter,
30
+ Coveralls::SimpleCov::Formatter
31
+ ]
32
+
33
+ SimpleCov.start
34
+
35
+ ENV['CODECLIMATE_REPO_TOKEN'] = "c91fecbbd9e414e7cc3ad7a7d99207145de0ac65a3368de09e8c19295343d399"
36
+ CodeClimate::TestReporter.start
37
+
38
+ ENV["APPID"]="wx986f04063d341d04"
39
+ ENV["APPSECRET"]="1a941cd88cb4579ba98ec06b6813af03"
40
+ ENV["OPENID"]="o9k6BuB0kydAcPTc7sPxppB1GQqA"
41
+
42
+ # Comment to test for ClientStorage
22
43
  redis = Redis.new(:host => "127.0.0.1",:port => "6379")
23
44
 
24
45
  namespace = "weixin_test:weixin_authorize"
@@ -24,8 +24,5 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.3"
26
26
  spec.add_development_dependency "rake"
27
- spec.add_development_dependency "redis-namespace", "~> 1.4.1"
28
-
29
- spec.add_development_dependency "rspec", "~> 3.0.0.beta1"
30
27
 
31
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weixin_authorize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.7
4
+ version: 1.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - lanrion
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-01 00:00:00.000000000 Z
11
+ date: 2014-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -80,34 +80,6 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: redis-namespace
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ~>
88
- - !ruby/object:Gem::Version
89
- version: 1.4.1
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ~>
95
- - !ruby/object:Gem::Version
96
- version: 1.4.1
97
- - !ruby/object:Gem::Dependency
98
- name: rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ~>
102
- - !ruby/object:Gem::Version
103
- version: 3.0.0.beta1
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ~>
109
- - !ruby/object:Gem::Version
110
- version: 3.0.0.beta1
111
83
  description: weixin api authorize access_token
112
84
  email:
113
85
  - huaitao-deng@foxmail.com
@@ -115,14 +87,15 @@ executables: []
115
87
  extensions: []
116
88
  extra_rdoc_files: []
117
89
  files:
90
+ - .coveralls.yml
118
91
  - .gitignore
119
92
  - .rspec
93
+ - .travis.yml
120
94
  - Gemfile
121
95
  - LICENSE.txt
122
96
  - README.md
123
97
  - Rakefile
124
98
  - lib/weixin_authorize.rb
125
- - lib/weixin_authorize/adapter.rb
126
99
  - lib/weixin_authorize/adapter/client_storage.rb
127
100
  - lib/weixin_authorize/adapter/redis_storage.rb
128
101
  - lib/weixin_authorize/adapter/storage.rb
@@ -135,6 +108,10 @@ files:
135
108
  - lib/weixin_authorize/api/user.rb
136
109
  - lib/weixin_authorize/client.rb
137
110
  - lib/weixin_authorize/config.rb
111
+ - lib/weixin_authorize/handler.rb
112
+ - lib/weixin_authorize/handler/exceptions.rb
113
+ - lib/weixin_authorize/handler/global_code.rb
114
+ - lib/weixin_authorize/handler/result_handler.rb
138
115
  - lib/weixin_authorize/version.rb
139
116
  - spec/1_fetch_access_token_spec.rb
140
117
  - spec/api/custom_spec.rb
@@ -1,3 +0,0 @@
1
- require "weixin_authorize/adapter/storage"
2
- require "weixin_authorize/adapter/client_storage"
3
- require "weixin_authorize/adapter/redis_storage"