Skip to content

Commit

Permalink
Add api shortlink.generate
Browse files Browse the repository at this point in the history
  • Loading branch information
wikimo authored and Eric-Guo committed Mar 21, 2023
1 parent efbe92e commit 8eef832
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.16.3

* Add api shortlink.generate support.

## v0.16.2 (released at 2022-12-09)

* Drop support ruby 2.6 and allow ruby 3.2 will released psych v5.0.0. by @iuhoay #314
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.16.2
0.16.3
6 changes: 6 additions & 0 deletions bin/wechat
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ class App < Thor
puts wechat_api.wxa_generate_urllink(body_hash)
end

desc 'wxa_generate_shortlink [PATH]', '获取小程序 Short Link'
def wxa_generate_shortlink(url, title = '', is_permanent = false)
body_hash = { page_url: url, page_title: title, is_permanent: is_permanent}
puts wechat_api.wxa_generate_shortlink(body_hash)
end

desc 'media_uploadnews [MPNEWS_YAML_PATH]', '上传图文消息素材'
def media_uploadnews(mpnews_yaml_path)
mpnew = Wechat::ApiLoader.load_yaml(File.read(mpnews_yaml_path))
Expand Down
4 changes: 4 additions & 0 deletions lib/wechat/concern/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ def wxa_generate_urllink(body_hash)
post 'generate_urllink', JSON.generate(body_hash), base: Wechat::Api::WXA_BASE
end

def wxa_generate_shortlink(body_hash)
post 'genwxashortlink', JSON.generate(body_hash), base: Wechat::Api::WXA_BASE
end

def menu
get 'menu/get'
end
Expand Down
12 changes: 12 additions & 0 deletions spec/lib/wechat/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,18 @@
end
end

describe '#wxa_generate_shortlink' do
shortlink_result = { errcode: 0, errmsg: 'ok', link: 'shortlink' }

specify 'will post wxa_generate_shortlink with url and access_token' do
body_hash = { page_url: 'pages/home/index' }
wxa_generate_shortlink_req = { page_url: 'pages/home/index' }
expect(subject.client).to receive(:post)
.with('genwxashortlink', JSON.generate(wxa_generate_shortlink_req), params: { access_token: 'access_token' }, base: Wechat::Api::WXA_BASE).and_return(shortlink_result)
expect(subject.wxa_generate_shortlink(body_hash)).to eq shortlink_result
end
end

describe '#menu' do
specify 'will get menu/get with access_token' do
menu_result = 'menu_result'
Expand Down

0 comments on commit 8eef832

Please sign in to comment.