wechat-sns 1.0 → 1.0.1

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: 76e941a7804cfb04eaee8416ea5bb5261f42ff7b
4
- data.tar.gz: 3d149eb567fe7c09d9e6f0e81a13c866e2d402f9
3
+ metadata.gz: 7a92efbc1fdf7b1a981c97cf0d85bfe256b4bf40
4
+ data.tar.gz: 04d5e4501e77a1c55a34d43b7b1e6f243d2cc97b
5
5
  SHA512:
6
- metadata.gz: dda253d4e5cec0b1c91c8014787ec6b9a6b7828befef81539ec521a67c6782627b397773ce2596ce546961156f64698721a924b54a2573443345024cbc0bb675
7
- data.tar.gz: 20609095f4e734507ac2634f6bae26222fe6d6f2927593979611071ab36283b6ef2ba162745666e777bd8990f63ac5e597c68b9fa644024e652cfda7333923e5
6
+ metadata.gz: a1f6c63d59de095cb308292e4a51b44e4fb931f44887c00efe07b1b04ca781be77ccad44ecb0f0384993ca939e1ca43208a21de8e6064a36d926550d0c749fa0
7
+ data.tar.gz: 398b25ff51baa781c278db2b7eda7eb7de8ee0ca6d6b1cf80494549b6241d847d68b5b7bb7385150471b8aac857fe627e152b1317c559e1e63569c7ba09b8bd6
data/CHANGELOG.md CHANGED
@@ -13,4 +13,11 @@
13
13
  1. Improved Access Token wrapper class to paramiterize the Wechat App ID and Wechat App Secret
14
14
 
15
15
  ## v1.0
16
- 1. Improved the wrapper classes to use Keywords Argument
16
+ 1. Improved the wrapper classes to use Keyword Arguments
17
+ 2. Improved the Ruby Gem Specification to depend on [wechat-core](https://github.com/topbitdu/wechat-core) v0.3
18
+
19
+ ## v1.0.1
20
+ 1. Improved the Ruby Gem Specification to depend on [wechat-core](https://github.com/topbitdu/wechat-core) v0.4
21
+ 2. Improve the Access Token wrapper class for the argument validation & HTTP request
22
+ 3. Improve the Authorize Link class for the argument validation
23
+ 4. Improve the User Profile wrapper class for the argument validation & HTTP request
data/Gemfile.lock CHANGED
@@ -2,7 +2,7 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  wechat-sns (1.0)
5
- wechat-core (~> 0.2)
5
+ wechat-core (~> 0.3)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,13 +1,17 @@
1
1
  # Wechat SNS 微信社交库
2
2
 
3
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/wechat-sns/frames)
3
4
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
5
+
4
6
  [![Gem Version](https://badge.fury.io/rb/wechat-sns.svg)](https://badge.fury.io/rb/wechat-sns)
7
+ [![Dependency Status](https://gemnasium.com/badges/github.com/topbitdu/wechat-sns.svg)](https://gemnasium.com/github.com/topbitdu/wechat-sns)
5
8
 
6
9
  Wechat SNS library is a low level library for Wechat SNS APIs. 微信社交库是一个调用[微信社交API](http://mp.weixin.qq.com/wiki/9/01f711493b5a02f24b04365ac5d8fd95.html)的低层库。
7
10
 
8
11
 
9
12
 
10
13
  ## Recent Update
14
+
11
15
  Check out the [Road Map](ROADMAP.md) to find out what's the next.
12
16
  Check out the [Change Log](CHANGELOG.md) to find out what's new.
13
17
 
data/ROADMAP.md CHANGED
@@ -10,7 +10,14 @@
10
10
  1. User Profile wrapper class
11
11
 
12
12
  ## v0.4
13
- 1. Improved Access Token wrapper class to paramiterize the Wechat App ID and Wechat App Secret
13
+ 1. Improve Access Token wrapper class to paramiterize the Wechat App ID and Wechat App Secret
14
14
 
15
15
  ## v1.0
16
- 1. Improved the wrapper classes to use Keywords Argument
16
+ 1. Improve the wrapper classes to support Keyword Arguments
17
+ 2. Improve the Ruby Gem Specification to depend on [wechat-core](https://github.com/topbitdu/wechat-core) v0.3
18
+
19
+ ## v1.0.1
20
+ 1. Improve the Ruby Gem Specification to depend on [wechat-core](https://github.com/topbitdu/wechat-core) v0.4
21
+ 2. Improve the Access Token wrapper class for the argument validation & HTTP request
22
+ 3. Improve the Authorize Link class for the argument validation
23
+ 4. Improve the User Profile wrapper class for the argument validation & HTTP request
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ markdown: kramdown
@@ -2,7 +2,7 @@ require 'jsonclient'
2
2
 
3
3
  class Wechat::SNS::AccessToken
4
4
 
5
- include ::Wechat::Core::Common
5
+ extend Wechat::Core::Common
6
6
 
7
7
  # 附:检验授权凭证(access_token)是否有效
8
8
  # http://mp.weixin.qq.com/wiki/9/01f711493b5a02f24b04365ac5d8fd95.html#.E9.99.84.EF.BC.9A.E6.A3.80.E9.AA.8C.E6.8E.88.E6.9D.83.E5.87.AD.E8.AF.81.EF.BC.88access_token.EF.BC.89.E6.98.AF.E5.90.A6.E6.9C.89.E6.95.88
@@ -19,7 +19,12 @@ class Wechat::SNS::AccessToken
19
19
  # errmsg: 'invalid openid'
20
20
  # }
21
21
  def self.load(access_token, opend_id)
22
- message = ::JSONClient.new.get 'https://api.weixin.qq.com/sns/auth',
22
+
23
+ assert_present! :access_token, access_token
24
+ assert_present! :opend_id, opend_id
25
+ #raise ArgumentError.new('The access_token argument is required.') if access_token.blank?
26
+
27
+ message = get_json 'https://api.weixin.qq.com/sns/auth', body:
23
28
  {
24
29
  access_token: access_token,
25
30
  openid: opend_id
@@ -45,6 +50,11 @@ class Wechat::SNS::AccessToken
45
50
  # errmsg: <ERROR_MESSAGE>
46
51
  # }
47
52
  def self.update(app_id, refresh_token)
53
+
54
+ assert_present! :app_id, app_id
55
+ assert_present! :refresh_token, refresh_token
56
+ # raise ArgumentError.new('The app_id argument is required.') if app_id.blank?
57
+
48
58
  message = ::JSONClient.new.get 'https://api.weixin.qq.com/sns/oauth2/refresh_token',
49
59
  {
50
60
  appid: app_id,
@@ -73,6 +83,9 @@ class Wechat::SNS::AccessToken
73
83
  # errmsg: <ERROR_MESSAGE>
74
84
  # }
75
85
  def self.create(app_id, app_secret, code, grant_type: 'authorization_code')
86
+
87
+ raise ArgumentError.new('The app_id argument is required.') if app_id.blank?
88
+
76
89
  message = ::JSONClient.new.get 'https://api.weixin.qq.com/sns/oauth2/access_token',
77
90
  {
78
91
  appid: app_id,
@@ -1,5 +1,7 @@
1
1
  class Wechat::SNS::AuthorizeLink
2
2
 
3
+ extend Wechat::Core::Common
4
+
3
5
  RESPONSE_TYPE_CODE = 'code'.freeze
4
6
  SCOPE_BASE = 'snsapi_base'.freeze
5
7
  SCOPE_FULL = 'snsapi_userinfo'.freeze
@@ -7,6 +9,11 @@ class Wechat::SNS::AuthorizeLink
7
9
  # 第一步:用户同意授权,获取code
8
10
  # http://mp.weixin.qq.com/wiki/9/01f711493b5a02f24b04365ac5d8fd95.html#.E7.AC.AC.E4.B8.80.E6.AD.A5.EF.BC.9A.E7.94.A8.E6.88.B7.E5.90.8C.E6.84.8F.E6.8E.88.E6.9D.83.EF.BC.8C.E8.8E.B7.E5.8F.96code
9
11
  def self.create(wechat_app_id, redirect_link, response_type: Wechat::SNS::AuthorizeLink::RESPONSE_TYPE_CODE, scope: Wechat::SNS::AuthorizeLink::SCOPE_FULL, state: nil)
12
+
13
+ assert_present! :wechat_app_id, wechat_app_id
14
+ assert_present! :redirect_link, redirect_link
15
+ assert_present! :response_type, response_type
16
+
10
17
  "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{wechat_app_id}&redirect_uri=#{CGI::escape redirect_link}&response_type=#{response_type}&scope=#{scope}&state=#{state}#wechat_redirect"
11
18
  end
12
19
 
@@ -2,6 +2,8 @@ require 'jsonclient'
2
2
 
3
3
  class Wechat::SNS::UserProfile
4
4
 
5
+ extend Wechat::Core::Common
6
+
5
7
  # 第四步:拉取用户信息(需scope为 snsapi_userinfo)
6
8
  # http://mp.weixin.qq.com/wiki/9/01f711493b5a02f24b04365ac5d8fd95.html#.E7.AC.AC.E5.9B.9B.E6.AD.A5.EF.BC.9A.E6.8B.89.E5.8F.96.E7.94.A8.E6.88.B7.E4.BF.A1.E6.81.AF.28.E9.9C.80scope.E4.B8.BA_snsapi_userinfo.29
7
9
  #
@@ -24,7 +26,12 @@ class Wechat::SNS::UserProfile
24
26
  # errmsg: <ERROR_MESSAGE>
25
27
  # }
26
28
  def self.load(access_token, open_id, language: Wechat::Core::Common::LANGUAGE_SIMPLIFIED_CHINESE)
27
- message = ::JSONClient.new.get 'https://api.weixin.qq.com/sns/userinfo',
29
+
30
+ assert_present! :access_token, access_token
31
+ assert_present! :open_id, open_id
32
+ #raise ArgumentError.new('The access_token argument is required.') if access_token.blank?
33
+
34
+ message = get_json 'https://api.weixin.qq.com/sns/userinfo', body:
28
35
  {
29
36
  access_token: access_token,
30
37
  openid: open_id,
@@ -1,5 +1,5 @@
1
1
  module Wechat
2
2
  module SNS
3
- VERSION = '1.0'.freeze
3
+ VERSION = '1.0.1'.freeze
4
4
  end
5
5
  end
data/wechat-sns.gemspec CHANGED
@@ -30,6 +30,6 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency 'rake', '~> 10.0'
31
31
  spec.add_development_dependency 'rspec', '~> 3.0'
32
32
 
33
- spec.add_dependency 'wechat-core', '~> 0.2'
33
+ spec.add_dependency 'wechat-core', '~> 0.4'
34
34
 
35
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wechat-sns
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-05 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.2'
61
+ version: '0.4'
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
- version: '0.2'
68
+ version: '0.4'
69
69
  description: Wechat SNS Library is a wrapper for calling Wechat SNS APIs. 微信社交库封装了对微信社交API的调用。
70
70
  email:
71
71
  - topbit.du@gmail.com
@@ -84,6 +84,7 @@ files:
84
84
  - README.md
85
85
  - ROADMAP.md
86
86
  - Rakefile
87
+ - _config.yml
87
88
  - bin/console
88
89
  - bin/setup
89
90
  - lib/wechat/sns.rb