Sha256: 0c7cb90d26754bcfcaedb727a04cf33378893f825dfd0c10cf8098595c9817dc
Contents?: true
Size: 815 Bytes
Versions: 3
Compression:
Stored size: 815 Bytes
Contents
require 'httpclient' module Wechat::ShakeAround::Material ## # 上传图片素材 # http://mp.weixin.qq.com/wiki/5/e997428269ff189d8f9a4b9e177be2d9.html # # Return hash format if success: # { # data: { pic_url: <ICON_LINK> }, # errcode: 0, # errmsg: 'success.' # } # # media 图片完整路径。 # type 是icon或者license。 def upload(access_token, media, type) assert_present! :access_token, access_token assert_present! :media, media assert_present! :type, type message = nil File.open(media) do |io| message = ::HTTPClient.new.post "https://api.weixin.qq.com/shakearound/material/add?access_token=#{access_token}&type=#{type}", { media: io } end body = message.try :body body.present? ? JSON.parse(body) : nil end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
wechat-shake_around-1.1 | lib/wechat/shake_around/material.rb |
wechat-shake_around-1.0 | lib/wechat/shake_around/material.rb |
wechat-shake_around-0.9.2 | lib/wechat/shake_around/material.rb |