Method: Wechat::Message#news

Defined in:
lib/wechat/message.rb

#news(collection, &_block) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/wechat/message.rb', line 164

def news(collection, &_block)
  if block_given?
    article = NewsArticleBuilder.new
    collection.take(8).each_with_index { |item, index| yield(article, item, index) }
    items = article.items
  else
    items = collection.collect do |item|
      camelize_hash_keys(item.symbolize_keys.slice(:title, :description, :pic_url, :url).compact)
    end
  end

  update(MsgType: 'news', ArticleCount: items.count,
         Articles: items.collect { |item| camelize_hash_keys(item) })
end