wechat-sns 0.4 → 1.0

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: e1243379a4457716883ee3744a2c8b617a8d0801
4
- data.tar.gz: 9611bd6bb6e351571c364cf0166acbcce1e1e7e7
3
+ metadata.gz: 76e941a7804cfb04eaee8416ea5bb5261f42ff7b
4
+ data.tar.gz: 3d149eb567fe7c09d9e6f0e81a13c866e2d402f9
5
5
  SHA512:
6
- metadata.gz: 2ac83a6c132dd7b6eb7b05fd10e2819757205564f1591dcf31447649cdaa5e60b4655a206ced0c7906d6430003b3068b208e338364d0e171aba6808773eaf5a6
7
- data.tar.gz: 77faf0979f3346a05a85386ffad25aad19272007305457676524fbd339caee06efe5f9d2000e40c4bfadcda1e0e41c6f8006447bef89a920c7f5de953ac37c06
6
+ metadata.gz: dda253d4e5cec0b1c91c8014787ec6b9a6b7828befef81539ec521a67c6782627b397773ce2596ce546961156f64698721a924b54a2573443345024cbc0bb675
7
+ data.tar.gz: 20609095f4e734507ac2634f6bae26222fe6d6f2927593979611071ab36283b6ef2ba162745666e777bd8990f63ac5e597c68b9fa644024e652cfda7333923e5
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
data/CHANGELOG.md CHANGED
@@ -1,13 +1,16 @@
1
1
  # Wechat SNS Change Log 微信社交库变更日志
2
2
 
3
3
  ## v0.1
4
- 1. Authorize Link class.
4
+ 1. Authorize Link class
5
5
 
6
6
  ## v0.2
7
- 1. Access Token wrapper class.
7
+ 1. Access Token wrapper class
8
8
 
9
9
  ## v0.3
10
- 1. User Profile wrapper class.
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. Improved Access Token wrapper class to paramiterize the Wechat App ID and Wechat App Secret
14
+
15
+ ## v1.0
16
+ 1. Improved the wrapper classes to use Keywords Argument
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wechat-sns (1.0)
5
+ wechat-core (~> 0.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.5)
11
+ httpclient (2.8.0)
12
+ rake (10.5.0)
13
+ rspec (3.4.0)
14
+ rspec-core (~> 3.4.0)
15
+ rspec-expectations (~> 3.4.0)
16
+ rspec-mocks (~> 3.4.0)
17
+ rspec-core (3.4.4)
18
+ rspec-support (~> 3.4.0)
19
+ rspec-expectations (3.4.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.4.0)
22
+ rspec-mocks (3.4.1)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.4.0)
25
+ rspec-support (3.4.1)
26
+ wechat-core (0.3)
27
+ httpclient (~> 2.7)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.11)
34
+ rake (~> 10.0)
35
+ rspec (~> 3.0)
36
+ wechat-sns!
37
+
38
+ BUNDLED WITH
39
+ 1.12.5
data/README.md CHANGED
@@ -5,6 +5,14 @@
5
5
 
6
6
  Wechat SNS library is a low level library for Wechat SNS APIs. 微信社交库是一个调用[微信社交API](http://mp.weixin.qq.com/wiki/9/01f711493b5a02f24b04365ac5d8fd95.html)的低层库。
7
7
 
8
+
9
+
10
+ ## Recent Update
11
+ Check out the [Road Map](ROADMAP.md) to find out what's the next.
12
+ Check out the [Change Log](CHANGELOG.md) to find out what's new.
13
+
14
+
15
+
8
16
  ## Installation
9
17
 
10
18
  Add this line to your application's Gemfile:
@@ -21,6 +29,8 @@ Or install it yourself as:
21
29
 
22
30
  $ gem install wechat-sns
23
31
 
32
+
33
+
24
34
  ## Usage
25
35
 
26
36
  [Generate an Authorize URL and Redirect 第一步:用户同意授权,获取code](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)
@@ -55,7 +65,7 @@ end
55
65
 
56
66
  [Get User Profile per Access Token 第四步:拉取用户信息(需scope为 snsapi_userinfo)](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)
57
67
  ```ruby
58
- response = Wechat::Sns::UserProfile.load access_token, open_id
68
+ response = Wechat::SNS::UserProfile.load access_token, open_id
59
69
  if response.present? && response['errcode'].blank?
60
70
  open_id = response['openid']
61
71
  nick_name = response['nickname']
@@ -69,18 +79,34 @@ if response.present? && response['errcode'].blank?
69
79
  end
70
80
  ```
71
81
 
82
+ [Validate Access Token 附:检验授权凭证(access_token)是否有效](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)
83
+ ```ruby
84
+ response = Wechat::SNS::AccessToken.load access_token, open_id
85
+ if response.present? && 0==response['errcode']
86
+ # valid, do something more with the access_token
87
+ Wechat::SNS::UserProfile.load access_token, open_id
88
+ else
89
+ # invalid, the access_token should be updated
90
+ Wechat::SNS::AccessToken.update Rails.application.secrets.wechat_app_id, refresh_token
91
+ end
92
+ ```
93
+
94
+
95
+
72
96
  ## Development
73
97
 
74
98
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75
99
 
76
100
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
77
101
 
102
+
103
+
78
104
  ## Contributing
79
105
 
80
106
  Bug reports and pull requests are welcome on GitHub at https://github.com/topbitdu/wechat-sns. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
81
107
 
82
108
 
109
+
83
110
  ## License
84
111
 
85
112
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
86
-
data/ROADMAP.md CHANGED
@@ -1,13 +1,16 @@
1
1
  # Wechat SNS Road Map 微信社交库路线图
2
2
 
3
3
  ## v0.1
4
- 1. Authorize Link class.
4
+ 1. Authorize Link class
5
5
 
6
6
  ## v0.2
7
- 1. Access Token wrapper class.
7
+ 1. Access Token wrapper class
8
8
 
9
9
  ## v0.3
10
- 1. User Profile wrapper class.
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. Improved Access Token wrapper class to paramiterize the Wechat App ID and Wechat App Secret
14
+
15
+ ## v1.0
16
+ 1. Improved the wrapper classes to use Keywords Argument
@@ -72,16 +72,17 @@ class Wechat::SNS::AccessToken
72
72
  # errcode: <ERROR_CODE>,
73
73
  # errmsg: <ERROR_MESSAGE>
74
74
  # }
75
- def self.create(app_id, app_secret, code)
75
+ def self.create(app_id, app_secret, code, grant_type: 'authorization_code')
76
76
  message = ::JSONClient.new.get 'https://api.weixin.qq.com/sns/oauth2/access_token',
77
77
  {
78
78
  appid: app_id,
79
79
  secret: app_secret,
80
80
  code: code,
81
- grant_type: 'authorization_code'
81
+ grant_type: grant_type
82
82
  }
83
- body = message.body
84
- body.is_a?(Hash) ? body : JSON.parse(body)
83
+ message.body
84
+ #body = message.body
85
+ #body.is_a?(Hash) ? body : JSON.parse(body)
85
86
  end
86
87
 
87
88
  end
@@ -6,7 +6,7 @@ class Wechat::SNS::AuthorizeLink
6
6
 
7
7
  # 第一步:用户同意授权,获取code
8
8
  # 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
- def self.create(wechat_app_id, redirect_link, response_type = Wechat::SNS::AuthorizeLink::RESPONSE_TYPE_CODE, scope = Wechat::SNS::AuthorizeLink::SCOPE_FULL, state = nil)
9
+ def self.create(wechat_app_id, redirect_link, response_type: Wechat::SNS::AuthorizeLink::RESPONSE_TYPE_CODE, scope: Wechat::SNS::AuthorizeLink::SCOPE_FULL, state: nil)
10
10
  "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
11
  end
12
12
 
@@ -23,15 +23,16 @@ class Wechat::SNS::UserProfile
23
23
  # errcode: <ERROR_CODE>,
24
24
  # errmsg: <ERROR_MESSAGE>
25
25
  # }
26
- def self.load(access_token, open_id, language = Wechat::Core::Common::LANGUAGE_SIMPLIFIED_CHINESE)
26
+ def self.load(access_token, open_id, language: Wechat::Core::Common::LANGUAGE_SIMPLIFIED_CHINESE)
27
27
  message = ::JSONClient.new.get 'https://api.weixin.qq.com/sns/userinfo',
28
28
  {
29
29
  access_token: access_token,
30
30
  openid: open_id,
31
31
  lang: language
32
32
  }
33
- body = message.body
34
- body.is_a?(Hash) ? body : JSON.parse(body)
33
+ message.body
34
+ #body = message.body
35
+ #body.is_a?(Hash) ? body : JSON.parse(body)
35
36
  end
36
37
 
37
38
  end
@@ -1,5 +1,5 @@
1
1
  module Wechat
2
2
  module SNS
3
- VERSION = '0.4'.freeze
3
+ VERSION = '1.0'.freeze
4
4
  end
5
5
  end
data/wechat-sns.gemspec CHANGED
@@ -4,15 +4,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'wechat/sns/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = 'wechat-sns'
8
- spec.version = Wechat::SNS::VERSION
9
- spec.authors = [ 'Topbit Du' ]
10
- spec.email = [ 'topbit.du@gmail.com' ]
11
-
12
- spec.summary = %q{Wechat SNS Library 微信社交库}
13
- spec.description = %q{Wechat SNS Library is a wrapper for calling Wechat SNS APIs. 微信社交库封装了对微信社交API的调用。}
14
- spec.homepage = 'https://github.com/topbitdu/wechat-sns'
15
- spec.license = 'MIT'
7
+ spec.name = 'wechat-sns'
8
+ spec.version = Wechat::SNS::VERSION
9
+ spec.authors = [ 'Topbit Du' ]
10
+ spec.email = [ 'topbit.du@gmail.com' ]
11
+ spec.summary = 'Wechat SNS Library 微信社交库'
12
+ spec.description = 'Wechat SNS Library is a wrapper for calling Wechat SNS APIs. 微信社交库封装了对微信社交API的调用。'
13
+ spec.homepage = 'https://github.com/topbitdu/wechat-sns'
14
+ spec.license = 'MIT'
16
15
 
17
16
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
17
  # delete this section to allow pushing this gem to any host.
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: '0.4'
4
+ version: '1.0'
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-02-19 00:00:00.000000000 Z
11
+ date: 2016-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -79,6 +79,7 @@ files:
79
79
  - CHANGELOG.md
80
80
  - CODE_OF_CONDUCT.md
81
81
  - Gemfile
82
+ - Gemfile.lock
82
83
  - LICENSE.txt
83
84
  - README.md
84
85
  - ROADMAP.md
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
111
112
  version: '0'
112
113
  requirements: []
113
114
  rubyforge_project:
114
- rubygems_version: 2.4.5.1
115
+ rubygems_version: 2.6.4
115
116
  signing_key:
116
117
  specification_version: 4
117
118
  summary: Wechat SNS Library 微信社交库