weixin_authorize 1.6.0 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/Gemfile +4 -5
  4. data/README.md +19 -8
  5. data/lib/weixin_authorize.rb +31 -13
  6. data/lib/weixin_authorize/api.rb +3 -0
  7. data/lib/weixin_authorize/api/data_cube.rb +8 -0
  8. data/lib/weixin_authorize/api/mass.rb +78 -0
  9. data/lib/weixin_authorize/api/media.rb +50 -4
  10. data/lib/weixin_authorize/api/oauth.rb +38 -0
  11. data/lib/weixin_authorize/api/template.rb +34 -0
  12. data/lib/weixin_authorize/api/user.rb +18 -0
  13. data/lib/weixin_authorize/client.rb +45 -16
  14. data/lib/weixin_authorize/config.rb +12 -3
  15. data/lib/weixin_authorize/handler/result_handler.rb +1 -0
  16. data/lib/weixin_authorize/js_ticket/object_store.rb +21 -0
  17. data/lib/weixin_authorize/js_ticket/redis_store.rb +41 -0
  18. data/lib/weixin_authorize/js_ticket/store.rb +40 -0
  19. data/lib/weixin_authorize/token/object_store.rb +25 -0
  20. data/lib/weixin_authorize/token/redis_store.rb +35 -0
  21. data/lib/weixin_authorize/token/store.rb +72 -0
  22. data/lib/weixin_authorize/version.rb +1 -1
  23. data/spec/1_fetch_access_token_spec.rb +0 -1
  24. data/spec/2_fetch_jsticket_spec.rb +10 -0
  25. data/spec/api/custom_spec.rb +0 -2
  26. data/spec/api/groups_spec.rb +0 -1
  27. data/spec/api/mass_spec.rb +65 -0
  28. data/spec/api/media_spec.rb +1 -3
  29. data/spec/api/menu_spec.rb +0 -2
  30. data/spec/api/qrcode_spec.rb +3 -5
  31. data/spec/api/user_spec.rb +5 -2
  32. data/spec/spec_helper.rb +7 -4
  33. data/weixin_authorize.gemspec +5 -5
  34. metadata +31 -20
  35. data/lib/weixin_authorize/adapter/client_storage.rb +0 -23
  36. data/lib/weixin_authorize/adapter/redis_storage.rb +0 -34
  37. data/lib/weixin_authorize/adapter/storage.rb +0 -73
data/spec/spec_helper.rb CHANGED
@@ -37,12 +37,13 @@ SimpleCov.start
37
37
  ENV['CODECLIMATE_REPO_TOKEN'] = "c91fecbbd9e414e7cc3ad7a7d99207145de0ac65a3368de09e8c19295343d399"
38
38
  CodeClimate::TestReporter.start
39
39
 
40
- ENV["APPID"]="wxe371e0960de5426a"
41
- ENV["APPSECRET"]="572b93d3d20aea242692a804243a141b"
42
- ENV["OPENID"]="oEEoyuEasxionjR5HygmEOQGwRcw"
40
+ # If you want test, change your weixin test profile
41
+ ENV["APPID"]="wx986f04063d341d04"
42
+ ENV["APPSECRET"]="1a941cd88cb4579ba98ec06b6813af03"
43
+ ENV["OPENID"]="o9k6BuB0kydAcPTc7sPxppB1GQqA"
43
44
 
44
45
  # Comment to test for ClientStorage
45
- redis = Redis.new(:host => "127.0.0.1",:port => "6379")
46
+ redis = Redis.new(host: "127.0.0.1", port: "6379", db: 15)
46
47
 
47
48
  namespace = "weixin_test:weixin_authorize"
48
49
 
@@ -54,9 +55,11 @@ redis_with_ns = Redis::Namespace.new("#{namespace}", :redis => redis)
54
55
 
55
56
  WeixinAuthorize.configure do |config|
56
57
  config.redis = redis_with_ns
58
+ config.rest_client_options = {timeout: 10, open_timeout: 10, verify_ssl: true}
57
59
  end
58
60
 
59
61
  $client = WeixinAuthorize::Client.new(ENV["APPID"], ENV["APPSECRET"])
62
+
60
63
  RSpec.configure do |config|
61
64
  # The settings below are suggested to provide a good initial experience
62
65
  # with RSpec, but feel free to customize to your heart's content.
@@ -19,16 +19,16 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "rest-client", ">= 1.6.7"
22
- spec.add_dependency "redis", "~> 3.0.7"
22
+ spec.add_dependency "redis", ">= 3.1.0"
23
23
 
24
- spec.add_dependency "carrierwave", "~> 0.10.0"
25
- spec.add_dependency 'mini_magick', '~> 3.7.0'
24
+ spec.add_dependency "carrierwave", ">= 0.10.0"
25
+ spec.add_dependency 'mini_magick', '>= 3.7.0'
26
26
 
27
27
  # A streaming JSON parsing and encoding library for Ruby (C bindings to yajl)
28
28
  # https://github.com/brianmario/yajl-ruby
29
- spec.add_dependency "yajl-ruby", "~> 1.2.0"
29
+ spec.add_dependency "yajl-ruby", ">= 1.2.0"
30
30
 
31
- spec.add_development_dependency "bundler", "~> 1.3"
31
+ spec.add_development_dependency "bundler"
32
32
  spec.add_development_dependency "rake"
33
33
 
34
34
  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.6.0
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - lanrion
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-30 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -28,72 +28,72 @@ dependencies:
28
28
  name: redis
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 3.0.7
33
+ version: 3.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 3.0.7
40
+ version: 3.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: carrierwave
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.10.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.10.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: mini_magick
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.7.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 3.7.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: yajl-ruby
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.2.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.2.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '1.3'
89
+ version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '1.3'
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -124,15 +124,16 @@ files:
124
124
  - README.md
125
125
  - Rakefile
126
126
  - lib/weixin_authorize.rb
127
- - lib/weixin_authorize/adapter/client_storage.rb
128
- - lib/weixin_authorize/adapter/redis_storage.rb
129
- - lib/weixin_authorize/adapter/storage.rb
130
127
  - lib/weixin_authorize/api.rb
131
128
  - lib/weixin_authorize/api/custom.rb
129
+ - lib/weixin_authorize/api/data_cube.rb
132
130
  - lib/weixin_authorize/api/groups.rb
131
+ - lib/weixin_authorize/api/mass.rb
133
132
  - lib/weixin_authorize/api/media.rb
134
133
  - lib/weixin_authorize/api/menu.rb
134
+ - lib/weixin_authorize/api/oauth.rb
135
135
  - lib/weixin_authorize/api/qrcode.rb
136
+ - lib/weixin_authorize/api/template.rb
136
137
  - lib/weixin_authorize/api/user.rb
137
138
  - lib/weixin_authorize/carrierwave/weixin_uploader.rb
138
139
  - lib/weixin_authorize/client.rb
@@ -141,10 +142,18 @@ files:
141
142
  - lib/weixin_authorize/handler/exceptions.rb
142
143
  - lib/weixin_authorize/handler/global_code.rb
143
144
  - lib/weixin_authorize/handler/result_handler.rb
145
+ - lib/weixin_authorize/js_ticket/object_store.rb
146
+ - lib/weixin_authorize/js_ticket/redis_store.rb
147
+ - lib/weixin_authorize/js_ticket/store.rb
148
+ - lib/weixin_authorize/token/object_store.rb
149
+ - lib/weixin_authorize/token/redis_store.rb
150
+ - lib/weixin_authorize/token/store.rb
144
151
  - lib/weixin_authorize/version.rb
145
152
  - spec/1_fetch_access_token_spec.rb
153
+ - spec/2_fetch_jsticket_spec.rb
146
154
  - spec/api/custom_spec.rb
147
155
  - spec/api/groups_spec.rb
156
+ - spec/api/mass_spec.rb
148
157
  - spec/api/media_spec.rb
149
158
  - spec/api/medias/favicon.ico
150
159
  - spec/api/medias/ruby-logo.jpg
@@ -173,14 +182,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
182
  version: '0'
174
183
  requirements: []
175
184
  rubyforge_project:
176
- rubygems_version: 2.2.2
185
+ rubygems_version: 2.4.5
177
186
  signing_key:
178
187
  specification_version: 4
179
188
  summary: weixin api authorize access_token
180
189
  test_files:
181
190
  - spec/1_fetch_access_token_spec.rb
191
+ - spec/2_fetch_jsticket_spec.rb
182
192
  - spec/api/custom_spec.rb
183
193
  - spec/api/groups_spec.rb
194
+ - spec/api/mass_spec.rb
184
195
  - spec/api/media_spec.rb
185
196
  - spec/api/medias/favicon.ico
186
197
  - spec/api/medias/ruby-logo.jpg
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
- module WeixinAuthorize
3
- class ClientStorage < Storage
4
-
5
- def valid?
6
- super
7
- end
8
-
9
- def token_expired?
10
- # 如果当前token过期时间小于现在的时间,则重新获取一次
11
- client.expired_at <= Time.now.to_i
12
- end
13
-
14
- def refresh_token
15
- super
16
- end
17
-
18
- def access_token
19
- super
20
- client.access_token
21
- end
22
- end
23
- end
@@ -1,34 +0,0 @@
1
- # encoding: utf-8
2
- module WeixinAuthorize
3
-
4
- class RedisStorage < Storage
5
-
6
- def valid?
7
- weixin_redis.del(client.redis_key)
8
- super
9
- end
10
-
11
- def token_expired?
12
- weixin_redis.hvals(client.redis_key).empty?
13
- end
14
-
15
- def refresh_token
16
- super
17
- weixin_redis.hmset(client.redis_key, "access_token", client.access_token,
18
- "expired_at", client.expired_at)
19
- weixin_redis.expireat(client.redis_key, client.expired_at.to_i-10) # 提前10秒超时
20
- end
21
-
22
- def access_token
23
- super
24
- client.access_token = weixin_redis.hget(client.redis_key, "access_token")
25
- client.expired_at = weixin_redis.hget(client.redis_key, "expired_at")
26
- client.access_token
27
- end
28
-
29
- def weixin_redis
30
- WeixinAuthorize.weixin_redis
31
- end
32
-
33
- end
34
- end
@@ -1,73 +0,0 @@
1
- # encoding: utf-8
2
- module WeixinAuthorize
3
-
4
- class Storage
5
-
6
- attr_accessor :client
7
-
8
- def initialize(client)
9
- @client = client
10
- end
11
-
12
- def self.init_with(client)
13
- if WeixinAuthorize.weixin_redis.nil?
14
- ClientStorage.new(client)
15
- else
16
- RedisStorage.new(client)
17
- end
18
- end
19
-
20
- def valid?
21
- authenticate["valid"]
22
- end
23
-
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}
32
- end
33
-
34
- def refresh_token
35
- handle_valid_exception
36
- set_access_token_for_client
37
- end
38
-
39
- def access_token
40
- refresh_token if token_expired?
41
- end
42
-
43
- def token_expired?
44
- raise NotImplementedError, "Subclasses must implement a token_expired? method"
45
- end
46
-
47
- def set_access_token_for_client(access_token_infos=nil)
48
- token_infos = access_token_infos || http_get_access_token.result
49
- client.access_token = token_infos["access_token"]
50
- client.expired_at = Time.now.to_i + token_infos["expires_in"].to_i
51
- end
52
-
53
- def http_get_access_token
54
- WeixinAuthorize.http_get_without_token("/token", authenticate_headers)
55
- end
56
-
57
- def authenticate_headers
58
- {grant_type: GRANT_TYPE, appid: client.app_id, secret: client.app_secret}
59
- end
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
-
71
- end
72
-
73
- end