Skip to content

Commit

Permalink
Merge pull request #301 from zlei1/master
Browse files Browse the repository at this point in the history
Update material_add API: 上传永久视频素材时需要description参数
  • Loading branch information
Eric-Guo authored Apr 23, 2021
2 parents 26461af + 5df8c5c commit 5b3ec90
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/wechat/concern/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,11 @@ def material_list(type, offset, count)
post 'material/batchget_material', JSON.generate(type: type, offset: offset, count: count)
end

def material_add(type, file)
post_file 'material/add_material', file, params: { type: type }
def material_add(type, file, opts = {})
params = { type: type }
params.merge!(description: opts.slice(:title, :introduction).to_json) if type == 'video'

post_file 'material/add_material', file, params: params
end

def material_add_news(mpnews_message)
Expand Down
10 changes: 10 additions & 0 deletions spec/lib/wechat/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,16 @@
end
end

describe '#material_add_video' do
specify 'will post material/add_material with access_token, type, description and media payload at file based api endpoint' do
file = 'README.md'
expect(subject.client).to receive(:post_file)
.with('material/add_material', file,
params: { type: 'video', access_token: 'access_token', description: "{\"title\":\"VIDEO_TITLE\",\"introduction\":\"INTRODUCTION\"}" }).and_return(true)
expect(subject.material_add('video', file, {title: 'VIDEO_TITLE', introduction: 'INTRODUCTION'})).to be true
end
end

describe '#material_add_news' do
let(:items) do
[
Expand Down

0 comments on commit 5b3ec90

Please sign in to comment.