wechat-core 0.4.1 → 0.4.2

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: 652dce668279af5ec743b29fc94dda40144596ec
4
- data.tar.gz: b06e70285eea750ae85dd147d55d4d94ebc69d98
3
+ metadata.gz: 1fb64c38de72269f3964193557840d1a082e8338
4
+ data.tar.gz: a2f81055f5a1f6958a9b0b3d9ccf560dff71b3b4
5
5
  SHA512:
6
- metadata.gz: 8ab34f8906dc3028c66c342145d6777a7355567935274e4e964f0f878580613feebd631054d9c07aa5b840f0ecf7b162be93108d3cb726e142ef65fdf25bca1e
7
- data.tar.gz: bed85f1de53c1c9112fe0793ef808f9475c8e91b436de09ea312d9253ea46b343f23403d7e5029383cf89d016d11935cdb883afc26da29c76a176c36c8bfc744
6
+ metadata.gz: f38dd883d10e79b7c9f5e5c5f9a3d351b8c89cf933c6184c49e3a4473411d90e4c27b7d3073f923eeeca5b55b1552378fc2f51aa34466bae1339d56166f95cd2
7
+ data.tar.gz: '09791946ee19d6e59acb26c305ca2c9c73652613277dff4ec79d17beb9d2324914922acee6b939069fbdf2a56300797a454854f469e8a9513cbaa32cfd188092'
data/CHANGELOG.md CHANGED
@@ -28,3 +28,10 @@
28
28
  3. Improve the Follower Profile wrapper class for the HTTP request
29
29
  4. Improve the Server Address wrapper class for the HTTP request
30
30
  5. Improve the Tiny Link wrapper class for the HTTP request
31
+
32
+ ## v0.4.2
33
+ 1. Improve the Access Token wrapper class for the HTTP request
34
+ 2. Improve the Follower wrapper class for the HTTP request
35
+ 3. Improve the Follower Profile wrapper class for the HTTP request
36
+ 4. Improve the Server Address wrapper class for the HTTP request
37
+ 5. Improve the Tiny Link wrapper class for the HTTP request
data/Gemfile.lock CHANGED
@@ -8,32 +8,32 @@ PATH
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (5.0.0.1)
11
+ activesupport (5.0.2)
12
12
  concurrent-ruby (~> 1.0, >= 1.0.2)
13
13
  i18n (~> 0.7)
14
14
  minitest (~> 5.1)
15
15
  tzinfo (~> 1.1)
16
- concurrent-ruby (1.0.2)
17
- diff-lcs (1.2.5)
18
- httpclient (2.8.2.4)
19
- i18n (0.7.0)
20
- minitest (5.9.1)
16
+ concurrent-ruby (1.0.5)
17
+ diff-lcs (1.3)
18
+ httpclient (2.8.3)
19
+ i18n (0.8.1)
20
+ minitest (5.10.1)
21
21
  rake (10.5.0)
22
- rspec (3.4.0)
23
- rspec-core (~> 3.4.0)
24
- rspec-expectations (~> 3.4.0)
25
- rspec-mocks (~> 3.4.0)
26
- rspec-core (3.4.4)
27
- rspec-support (~> 3.4.0)
28
- rspec-expectations (3.4.0)
22
+ rspec (3.5.0)
23
+ rspec-core (~> 3.5.0)
24
+ rspec-expectations (~> 3.5.0)
25
+ rspec-mocks (~> 3.5.0)
26
+ rspec-core (3.5.4)
27
+ rspec-support (~> 3.5.0)
28
+ rspec-expectations (3.5.0)
29
29
  diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.4.0)
31
- rspec-mocks (3.4.1)
30
+ rspec-support (~> 3.5.0)
31
+ rspec-mocks (3.5.0)
32
32
  diff-lcs (>= 1.2.0, < 2.0)
33
- rspec-support (~> 3.4.0)
34
- rspec-support (3.4.1)
35
- thread_safe (0.3.5)
36
- tzinfo (1.2.2)
33
+ rspec-support (~> 3.5.0)
34
+ rspec-support (3.5.0)
35
+ thread_safe (0.3.6)
36
+ tzinfo (1.2.3)
37
37
  thread_safe (~> 0.1)
38
38
 
39
39
  PLATFORMS
@@ -46,4 +46,4 @@ DEPENDENCIES
46
46
  wechat-core!
47
47
 
48
48
  BUNDLED WITH
49
- 1.12.5
49
+ 1.13.6
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Wechat::Core 微信核心库
2
2
 
3
+ [![Documentation](http://img.shields.io/badge/docs-rdoc.info-blue.svg)](http://www.rubydoc.info/gems/wechat-core/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-core.svg)](https://badge.fury.io/rb/wechat-core)
5
7
  [![Dependency Status](https://gemnasium.com/badges/github.com/topbitdu/wechat-core.svg)](https://gemnasium.com/github.com/topbitdu/wechat-core)
6
8
 
data/ROADMAP.md CHANGED
@@ -29,6 +29,13 @@
29
29
  4. Improve the Server Address wrapper class for the HTTP request
30
30
  5. Improve the Tiny Link wrapper class for the HTTP request
31
31
 
32
+ ## v0.4.2
33
+ 1. Improve the Access Token wrapper class for the HTTP request
34
+ 2. Improve the Follower wrapper class for the HTTP request
35
+ 3. Improve the Follower Profile wrapper class for the HTTP request
36
+ 4. Improve the Server Address wrapper class for the HTTP request
37
+ 5. Improve the Tiny Link wrapper class for the HTTP request
38
+
32
39
  ## v1.0
33
40
  1. Improve the Follower & Follower Profile wrapper class to support the Keyword Arguments
34
41
  2. Removed the depreated classes and methods
@@ -1,9 +1,13 @@
1
1
  require 'jsonclient'
2
2
 
3
+ ##
4
+ # Access Token 是访问令牌的远程调用封装类。
5
+
3
6
  class Wechat::Core::AccessToken
4
7
 
5
8
  extend Wechat::Core::Common
6
9
 
10
+ ##
7
11
  # 获取 Access Token
8
12
  # http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
9
13
  #
@@ -23,6 +27,7 @@ class Wechat::Core::AccessToken
23
27
  message.body
24
28
  end
25
29
 
30
+ ##
26
31
  # 获取 Access Token
27
32
  # http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
28
33
  #
@@ -37,19 +42,12 @@ class Wechat::Core::AccessToken
37
42
  assert_present! :app_id, app_id
38
43
  assert_present! :app_secret, app_secret
39
44
 
40
- #message = ::JSONClient.new.get 'https://api.weixin.qq.com/cgi-bin/token',
41
- # {
42
- # grant_type: 'client_credential',
43
- # appid: app_id, # Rails.application.secrets.wechat_app_id,
44
- # secret: app_secret, # Rails.application.secrets.wechat_app_secret
45
- # }
46
- message = get_json 'https://api.weixin.qq.com/cgi-bin/token', body:
45
+ get_json 'https://api.weixin.qq.com/cgi-bin/token', body:
47
46
  {
48
47
  grant_type: 'client_credential',
49
48
  appid: app_id, # Rails.application.secrets.wechat_app_id,
50
49
  secret: app_secret, # Rails.application.secrets.wechat_app_secret
51
50
  }
52
- message.body
53
51
  end
54
52
 
55
53
  class << self
@@ -142,16 +142,25 @@ module Wechat::Core::Common
142
142
  9001036 => '查询起始值begin不合法'
143
143
  }
144
144
 
145
+ ##
146
+ # 判断给定的参数 value 是否为空,如果为空,则抛出 ArgumentError 异常。参数名为 name 。例如:
147
+ # assert_present! :access_token, access_token
145
148
  def assert_present!(name, value)
146
149
  raise ArgumentError.new("The #{name} argument is required.") if value.blank?
147
150
  end
148
151
 
152
+ ##
153
+ # 向链接 link 发出 GET 请求,参数为 body 指定的 Hash。返回的数据结构必须为 JSON 格式。如:
154
+ # get_json 'https://api.product.com/path/resources.json', body: { page: 2, per_page: 5 }
149
155
  def get_json(link, body: {})
150
156
  assert_present! :link, link
151
157
  message = JSONClient.new.get link, body
152
158
  message.body
153
159
  end
154
160
 
161
+ ##
162
+ # 向链接 link 发出 GET 请求,参数为 body 指定的 Hash。返回的数据结构必须为 JSON 格式。如:
163
+ # post_json 'https://api.product.com/path/resources.json', body: { name: 'Some Name' }
155
164
  def post_json(link, body: {})
156
165
  assert_present! :link, link
157
166
  message = JSONClient.new.post link, body
@@ -1,7 +1,11 @@
1
+ ##
2
+ # Follower 是关注者概要信息的远程调用封装类。
3
+
1
4
  class Wechat::Core::Follower
2
5
 
3
6
  extend Wechat::Core::Common
4
7
 
8
+ ##
5
9
  # 获取关注者列表
6
10
  # http://mp.weixin.qq.com/wiki/0/d0e07720fc711c02a3eab6ec33054804.html
7
11
  #
@@ -19,8 +23,7 @@ class Wechat::Core::Follower
19
23
  options = { access_token: access_token }
20
24
  options[:next_openid] = next_open_id if next_open_id.present?
21
25
 
22
- message = get_json 'https://api.weixin.qq.com/cgi-bin/user/get', body: options
23
- message.body
26
+ get_json 'https://api.weixin.qq.com/cgi-bin/user/get', body: options
24
27
  end
25
28
 
26
29
  end
@@ -1,7 +1,11 @@
1
+ ##
2
+ # Follower Profile 是关注者画像的远程调用封装类。
3
+
1
4
  class Wechat::Core::FollowerProfile
2
5
 
3
6
  extend Wechat::Core::Common
4
7
 
8
+ ##
5
9
  # 批量获取用户基本信息
6
10
  # http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html#.E6.89.B9.E9.87.8F.E8.8E.B7.E5.8F.96.E7.94.A8.E6.88.B7.E5.9F.BA.E6.9C.AC.E4.BF.A1.E6.81.AF
7
11
  # 最多支持一次拉取100条。
@@ -20,7 +24,7 @@ class Wechat::Core::FollowerProfile
20
24
  # country: <COUNTRY_NAME>,
21
25
  # headimgurl: <HEAD_IMAGE_LINK>,
22
26
  # subscribe_time: <SUBSCRIBE_TIME>,
23
- # unionid: <UNION_ID>,
27
+ # unionid: <UNION_ID>,
24
28
  # remark: <REMARK>,
25
29
  # groupid: <GROUP_ID>
26
30
  # }
@@ -32,14 +36,17 @@ class Wechat::Core::FollowerProfile
32
36
  assert_present! :open_ids, open_ids
33
37
 
34
38
  followers = open_ids.map { |open_id| { openid: open_id, lang: language } }
35
- message = post_json "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=#{access_token}", body: { user_list: followers }
36
- message.body
39
+ post_json "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=#{access_token}", body:
40
+ {
41
+ user_list: followers
42
+ }
37
43
 
38
44
  end
39
45
 
46
+ ##
40
47
  # 获取用户基本信息(UnionID机制)
41
48
  # http://mp.weixin.qq.com/wiki/14/bb5031008f1494a59c6f71fa0f319c66.html#.E8.8E.B7.E5.8F.96.E7.94.A8.E6.88.B7.E5.9F.BA.E6.9C.AC.E4.BF.A1.E6.81.AF.EF.BC.88.E5.8C.85.E6.8B.ACUnionID.E6.9C.BA.E5.88.B6.EF.BC.89
42
- # 一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。
49
+ # 一次拉取调用最多拉取10000个关注者的OpenID,可以通过多次拉取的方式来满足需求。
43
50
  #
44
51
  # Return hash format if success:
45
52
  # {
@@ -56,18 +63,17 @@ class Wechat::Core::FollowerProfile
56
63
  # remark: <REMARK>,
57
64
  # groupid: <GROUP_ID>
58
65
  # }
59
- def self.load(access_token, open_id, language: 'zh_CN')
66
+ def self.load(access_token, open_id, language: Wechat::Core::Common::LANGUAGE_SIMPLIFIED_CHINESE)
60
67
 
61
68
  assert_present! :access_token, access_token
62
69
  assert_present! :open_id, open_id
63
70
 
64
- message = get_json 'https://api.weixin.qq.com/cgi-bin/user/info', body:
71
+ get_json 'https://api.weixin.qq.com/cgi-bin/user/info', body:
65
72
  {
66
73
  access_token: access_token,
67
74
  openid: open_id,
68
75
  lang: language
69
76
  }
70
- message.body
71
77
  end
72
78
 
73
79
  end
@@ -1,7 +1,11 @@
1
+ ##
2
+ # Server Address 是服务器地址的远程调用封装类。
3
+
1
4
  class Wechat::Core::ServerAddress
2
5
 
3
6
  extend Wechat::Core::Common
4
7
 
8
+ ##
5
9
  # 获取微信服务器IP地址
6
10
  # http://mp.weixin.qq.com/wiki/0/2ad4b6bfd29f30f71d39616c2a0fcedc.html
7
11
  #
@@ -11,8 +15,8 @@ class Wechat::Core::ServerAddress
11
15
 
12
16
  assert_present! :access_token, access_token
13
17
 
14
- message = get_json 'https://api.weixin.qq.com/cgi-bin/getcallbackip', body: { access_token: access_token }
15
- message.body
18
+ get_json 'https://api.weixin.qq.com/cgi-bin/getcallbackip', body: { access_token: access_token }
19
+
16
20
  end
17
21
 
18
22
  end
@@ -1,7 +1,11 @@
1
+ ##
2
+ # Tiny Link 是短链接的远程调用封装类。
3
+
1
4
  class Wechat::Core::TinyLink
2
5
 
3
6
  extend Wechat::Core::Common
4
7
 
8
+ ##
5
9
  # 长链接转短链接接口
6
10
  # http://mp.weixin.qq.com/wiki/10/165c9b15eddcfbd8699ac12b0bd89ae6.html
7
11
  #
@@ -23,12 +27,11 @@ class Wechat::Core::TinyLink
23
27
  assert_present! :access_token, access_token
24
28
  assert_present! :link, link
25
29
 
26
- message = post_json "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=#{access_token}", body:
30
+ post_json "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=#{access_token}", body:
27
31
  {
28
32
  action: 'long2short',
29
33
  long_url: link
30
34
  }
31
- message.body
32
35
  end
33
36
 
34
37
  end
@@ -1,5 +1,5 @@
1
1
  module Wechat
2
2
  module Core
3
- VERSION = '0.4.1'.freeze
3
+ VERSION = '0.4.2'.freeze
4
4
  end
5
5
  end
data/wechat-core.gemspec CHANGED
@@ -31,6 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency 'rspec', '~> 3.0'
32
32
 
33
33
  spec.add_dependency 'activesupport', '>= 4.2'
34
- spec.add_dependency 'httpclient', '>= 2.8'
34
+ spec.add_dependency 'httpclient', '>= 2.8'
35
35
 
36
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wechat-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
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-12-24 00:00:00.000000000 Z
11
+ date: 2017-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler