Sha256: 81ef04e84b2d5a4d633000ece403cd847973279fd40a1496a7a51a97d321a7ec

Contents?: true

Size: 687 Bytes

Versions: 8

Compression:

Stored size: 687 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)
    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

8 entries across 8 versions & 1 rubygems

Version Path
wechat-shake_around-0.9 lib/wechat/shake_around/material.rb
wechat-shake_around-0.8 lib/wechat/shake_around/material.rb
wechat-shake_around-0.7 lib/wechat/shake_around/material.rb
wechat-shake_around-0.6 lib/wechat/shake_around/material.rb
wechat-shake_around-0.5 lib/wechat/shake_around/material.rb
wechat-shake_around-0.4 lib/wechat/shake_around/material.rb
wechat-shake_around-0.3 lib/wechat/shake_around/material.rb
wechat-shake_around-0.2 lib/wechat/shake_around/material.rb