easy_wechat 0.1.3 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5cb4283e2aa2451356d46392ba3260585b49bcb4a57d2e9cbb78964754335e2
4
- data.tar.gz: f684c3d9b9809e1f5d504989e6ccb98110b9dacb05debbfe3d9f9d328d187dea
3
+ metadata.gz: ccc93ec4d83d3f2b3b45a514b9297b76ee395fbe8aebbceef0387cd4a422d491
4
+ data.tar.gz: 9a89ebd838cb835625acb977c1145ef2edfb62250de62adbfa22527e15a5bd97
5
5
  SHA512:
6
- metadata.gz: b95b94c2179eeb420fcc7bcbb4f90851d9b589d47a73da60c31b1dbb6eb5b96dc53b82d8ac205faeba0f716ec1fa8771d0245ce05ef67d62f50e445c7d53ac42
7
- data.tar.gz: b3fb434e830ef7035120a683094fe0ac9a345774db32447e58f2db72ee05a766648f6ed472461864192410e24eb7bb04b79f0bccbe15b71b00f7af12e0e72153
6
+ metadata.gz: 24929f3e1b1ed83e6f57fc167a4c2aa76404b968e6c73f64cf42b99124b35d185ef67d59ba5cee23fcc7a0fe40bc2e1790bfe354c16fb8e06eaee433aa4d7397
7
+ data.tar.gz: aa1b2c8ae2679b0b3d080c8389e71d562275e612f0bebc617b59f323ad051e3e823745db403ab9d15a4175fc6e21a99adfb62f280b4e78864f9cec50da73fea6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy_wechat (0.1.3)
4
+ easy_wechat (0.1.6)
5
5
  activesupport
6
6
  http-form_data
7
7
  httpx
@@ -11,6 +11,7 @@ module EasyWechat
11
11
  ADD_NEWS_URL = "https://api.weixin.qq.com/cgi-bin/material/add_news"
12
12
  GET_USER_SUMMARY_URL = "https://api.weixin.qq.com/datacube/getusersummary"
13
13
  GET_USER_CUMULATE_URL = "https://api.weixin.qq.com/datacube/getusercumulate"
14
+ GET_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket"
14
15
 
15
16
  def initialize
16
17
  end
@@ -53,47 +54,54 @@ module EasyWechat
53
54
  r
54
55
  end
55
56
 
57
+ # 新增永久图文素材
58
+ # https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
59
+ def add_news(articles)
60
+ payload = { articles: articles }
61
+
62
+ resp = HTTPX.post(ADD_NEWS_URL, params: { access_token: access_token }, json: payload)
63
+
64
+ r = ::JSON.parse(resp.body, quirks_mode: true)
65
+ yield r if block_given?
66
+ r
67
+ end
68
+
69
+ def get_ticket(type)
70
+ resp = HTTPX.get(GET_TICKET_URL, params: { access_token: access_token, type: type })
71
+
72
+ r = ::JSON.parse(resp.body, quirks_mode: true)
73
+ yield r if block_given?
74
+ r
75
+ end
76
+
77
+ # 获取永久素材的列表
78
+ # https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
79
+ def batchget_material(type = "image", offset = 0, count = 20)
80
+ # TODO: 检查参数完整性
81
+ # TODO: 检查参数合法性
82
+ payload = { type: type, offset: offset, count: count }
83
+
84
+ resp = HTTPX.post(BATCHGET_MATERIAL_URL, params: { access_token: access_token }, json: payload)
85
+
86
+ r = ::JSON.parse(resp.body, quirks_mode: true)
87
+ yield r if block_given?
88
+ r
89
+ end
90
+
56
91
  # 上传图文消息内的图片获取URL
57
92
  # https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
58
93
  def uploadimg(media)
59
94
  # https://honeyryderchuck.gitlab.io/httpx/wiki/Multipart-Uploads.html#notes
60
- file = if media.is_a?(String) ? HTTP::FormData::File.new(media) : meida
61
- resp = HTTPX.plugin(:multipart).post(UPLOADIMG_URL, params: { access_token: access_token }, form: { media: file })
62
-
63
- r = ::JSON.parse(resp.body, quirks_mode: true)
64
- yield r if block_given?
65
- r
66
- end
67
-
68
- # 获取永久素材的列表
69
- # https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
70
- def batchget_material(type = "image", offset = 0, count = 20)
71
- # TODO: 检查参数完整性
72
- # TODO: 检查参数合法性
73
- payload = { type: type, offset: offset, count: count }
74
-
75
- resp = HTTPX.post(BATCHGET_MATERIAL_URL, params: { access_token: access_token }, json: payload)
76
-
77
- r = ::JSON.parse(resp.body, quirks_mode: true)
78
- yield r if block_given?
79
- r
80
- end
81
-
82
- # 新增永久图文素材
83
- # https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
84
- def add_news(articles)
85
- payload = { articles: articles }
86
-
87
- resp = HTTPX.post(ADD_NEWS_URL, params: { access_token: access_token }, json: payload)
88
-
89
- r = ::JSON.parse(resp.body, quirks_mode: true)
90
- yield r if block_given?
91
- r
92
- end
93
-
94
- def menu_create
95
- raise NotImplementedError
96
- end
95
+ file = media.is_a?(String) ? HTTP::FormData::File.new(media) : meida
96
+ resp = HTTPX.plugin(:multipart).post(UPLOADIMG_URL, params: { access_token: access_token }, form: { media: file })
97
+
98
+ r = ::JSON.parse(resp.body, quirks_mode: true)
99
+ yield r if block_given?
100
+ r
101
+ end
102
+
103
+ def menu_create
104
+ raise NotImplementedError
97
105
  end
98
106
  end
99
107
  end
@@ -1,3 +1,3 @@
1
1
  module EasyWechat
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_wechat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - 42up
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-10 00:00:00.000000000 Z
11
+ date: 2021-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpx